Skip to content

Commit 204e411

Browse files
fix: make actions column sticky in members list (#17554)
* fix: make actions column sticky in members list * clean up import * change type definition * remove old export * include tanstack.d.ts * fix declaration file * move type def to packages/types/tanstack-table.d.ts --------- Co-authored-by: Keith Williams <[email protected]>
1 parent 1ec1554 commit 204e411

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

packages/features/users/components/UserTable/UserListTable.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ import {
99
useReactTable,
1010
type ColumnDef,
1111
} from "@tanstack/react-table";
12-
import type { ColumnMeta } from "@tanstack/react-table";
1312
import { useSession } from "next-auth/react";
1413
import { useQueryState, parseAsBoolean } from "nuqs";
1514
import { useMemo, useReducer, useRef, useState } from "react";
1615

1716
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
1817
import { WEBAPP_URL } from "@calcom/lib/constants";
19-
import {
20-
downloadAsCsv,
21-
generateCsvRaw,
22-
generateHeaderFromReactTable,
23-
sanitizeValue,
24-
} from "@calcom/lib/csvUtils";
18+
import { downloadAsCsv, generateCsvRaw, generateHeaderFromReactTable } from "@calcom/lib/csvUtils";
2519
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
2620
import { useLocale } from "@calcom/lib/hooks/useLocale";
2721
import { trpc } from "@calcom/trpc";
@@ -36,8 +30,8 @@ import {
3630
DataTableSelectionBar,
3731
DataTablePagination,
3832
showToast,
33+
useFetchMoreOnBottomReached,
3934
} from "@calcom/ui";
40-
import { useFetchMoreOnBottomReached } from "@calcom/ui/data-table";
4135
import { useGetUserAttributes } from "@calcom/web/components/settings/platform/hooks/useGetUserAttributes";
4236

4337
import { DeleteBulkUsers } from "./BulkActions/DeleteBulkUsers";
@@ -53,11 +47,6 @@ import { InviteMemberModal } from "./InviteMemberModal";
5347
import { TableActions } from "./UserTableActions";
5448
import type { UserTableState, UserTableAction, UserTableUser } from "./types";
5549

56-
type CustomColumnMeta<TData, TValue> = ColumnMeta<TData, TValue> & {
57-
sticky?: boolean;
58-
stickLeft?: number;
59-
};
60-
6150
const initialState: UserTableState = {
6251
changeMemberRole: {
6352
showModal: false,
@@ -217,9 +206,10 @@ export function UserListTable() {
217206
enableHiding: false,
218207
enableSorting: false,
219208
meta: {
220-
sticky: true,
221-
stickLeft: 0,
222-
} as CustomColumnMeta<UserTableUser, unknown>,
209+
sticky: {
210+
position: "left",
211+
},
212+
},
223213
header: ({ table }) => (
224214
<Checkbox
225215
checked={table.getIsAllPageRowsSelected()}
@@ -245,9 +235,8 @@ export function UserListTable() {
245235
return `Members`;
246236
},
247237
meta: {
248-
sticky: true,
249-
stickyLeft: 24,
250-
} as CustomColumnMeta<UserTableUser, unknown>,
238+
sticky: { position: "left", gap: 24 },
239+
},
251240
cell: ({ row }) => {
252241
const { username, email, avatarUrl } = row.original;
253242
return (
@@ -349,6 +338,9 @@ export function UserListTable() {
349338
{
350339
id: "actions",
351340
enableHiding: false,
341+
meta: {
342+
sticky: { position: "right" },
343+
},
352344
cell: ({ row }) => {
353345
const user = row.original;
354346
const permissionsRaw = permissions;

packages/types/tanstack-table.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import "@tanstack/react-table";
22

33
declare module "@tanstack/table-core" {
44
interface ColumnMeta<TData extends RowData, TValue> {
5-
hasPermissions?: (data?: TData) => boolean; // We can conditionally render a column based on this callback -> User doesnt have admin for example.
5+
sticky?: {
6+
position: "left" | "right";
7+
gap?: number;
8+
};
69
}
710
}

packages/ui/components/data-table/DataTable.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ export function DataTable<TData, TValue>({
6565
{table.getHeaderGroups().map((headerGroup) => (
6666
<TableRow key={headerGroup.id}>
6767
{headerGroup.headers.map((header) => {
68-
const meta = header.column.columnDef.meta as { sticky?: boolean; stickyLeft?: number };
68+
const meta = header.column.columnDef.meta;
6969
return (
7070
<TableHead
7171
key={header.id}
7272
style={{
73-
left: meta?.stickyLeft ? `${meta.stickyLeft}px` : undefined,
73+
...(meta?.sticky?.position === "left" && { left: `${meta.sticky.gap || 0}px` }),
74+
...(meta?.sticky?.position === "right" && { right: `${meta.sticky.gap || 0}px` }),
7475
}}
7576
className={classNames(
7677
header.column.getCanSort() ? "cursor-pointer select-none" : "",
77-
meta?.sticky && "bg-subtle sticky left-0 top-0 z-20"
78+
meta?.sticky && "bg-subtle sticky top-0 z-20"
7879
)}>
7980
<div className="flex items-center" onClick={header.column.getToggleSortingHandler()}>
8081
{header.isPlaceholder
@@ -119,16 +120,17 @@ export function DataTable<TData, TValue>({
119120
)}>
120121
{row.getVisibleCells().map((cell) => {
121122
const column = table.getColumn(cell.column.id);
122-
const meta = column?.columnDef.meta as { sticky?: boolean; stickyLeft?: number };
123+
const meta = column?.columnDef.meta;
123124
return (
124125
<TableCell
125126
key={cell.id}
126127
style={{
127-
left: meta?.stickyLeft ? `${meta.stickyLeft}px` : undefined,
128+
...(meta?.sticky?.position === "left" && { left: `${meta.sticky.gap || 0}px` }),
129+
...(meta?.sticky?.position === "right" && { right: `${meta.sticky.gap || 0}px` }),
128130
}}
129131
className={classNames(
130132
variant === "compact" && "p-1.5",
131-
meta?.sticky && "group-hover:bg-muted bg-default sticky left-0"
133+
meta?.sticky && "group-hover:bg-muted bg-default sticky"
132134
)}>
133135
{flexRender(cell.column.columnDef.cell, cell.getContext())}
134136
</TableCell>

packages/ui/components/data-table/tanstack.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)