feat: implement standard pagination for org member list (#19802)
* feat: implement standard pagination for org member list * fix type error * i18n for pagination * add paginationMode * apply the change to PlatformManagedUsersTable * replace useInfiniteQuery with useQuery * fix type error * fix type error * fix type error * fix type error * update comment * remove optimistic update * minor changes * update usage on nuqs --------- Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
1 parent
861e3aa24f
commit
7eee2728a2
24 files changed
+403
-388
No files matched your search
@@ -15,22 +15,9 @@ export function DeleteBulkUsers({ users, onRemove }: Props) {
|
||||
const selectedRows = users; // Get selected rows from table
|
||||
const utils = trpc.useUtils();
|
||||
const deleteMutation = trpc.viewer.organizations.bulkDeleteUsers.useMutation({
|
||||
onSuccess: (_, { userIds }) => {
|
||||
onSuccess: () => {
|
||||
showToast("Deleted Users", "success");
|
||||
utils.viewer.organizations.listMembers.setInfiniteData(
|
||||
{ limit: 10, searchTerm: "", expand: ["attributes"] },
|
||||
// @ts-expect-error - infinite data types are not correct
|
||||
(oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return {
|
||||
...oldData,
|
||||
pages: oldData.pages.map((page) => ({
|
||||
...page,
|
||||
rows: page.rows.filter((user) => !userIds.includes(user.id)),
|
||||
})),
|
||||
};
|
||||
}
|
||||
);
|
||||
utils.viewer.organizations.listMembers.invalidate();
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message, "error");
|
||||
|
||||
@@ -4,7 +4,6 @@ import type { Dispatch, SetStateAction } from "react";
|
||||
|
||||
import { DataTableSelectionBar, type ColumnFilter } from "@calcom/features/data-table";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import type { Attribute as _Attribute, AttributeOption } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import {
|
||||
@@ -241,78 +240,6 @@ function MassAssignAttributesBulkActionComponent({ table, filters }: Props) {
|
||||
const utils = trpc.useUtils();
|
||||
const bulkAssignAttributes = trpc.viewer.attributes.bulkAssignAttributes.useMutation({
|
||||
onSuccess: (success) => {
|
||||
// Optimistically update the infinite query data
|
||||
const selectedRows = table.getSelectedRowModel().flatRows;
|
||||
|
||||
utils.viewer.organizations.listMembers.setInfiniteData(
|
||||
{
|
||||
limit: 10,
|
||||
searchTerm: "",
|
||||
expand: ["attributes"],
|
||||
filters,
|
||||
},
|
||||
// @ts-expect-error i really dont know how to type this
|
||||
(oldData) => {
|
||||
if (!oldData) {
|
||||
return {
|
||||
pages: [],
|
||||
pageParams: [],
|
||||
};
|
||||
}
|
||||
|
||||
const newPages = oldData?.pages.map((page) => ({
|
||||
...page,
|
||||
rows: page.rows.map((row) => {
|
||||
if (selectedRows.some((selectedRow) => selectedRow.original.id === row.id)) {
|
||||
// Update the attributes for the selected users
|
||||
|
||||
const attributeOptionValues = foundAttributeInCache?.options.filter((option) =>
|
||||
selectedAttributeOptions.includes(option.id)
|
||||
);
|
||||
|
||||
const newAttributes =
|
||||
row.attributes?.filter((attr) => attr.attributeId !== selectedAttribute) || [];
|
||||
|
||||
if (attributeOptionValues && attributeOptionValues.length > 0) {
|
||||
const newAttributeValues = attributeOptionValues?.map((value) => ({
|
||||
id: value.id,
|
||||
attributeId: value.attributeId,
|
||||
value: value.value,
|
||||
slug: value.slug,
|
||||
contains: value.contains,
|
||||
isGroup: value.isGroup,
|
||||
weight: 100,
|
||||
}));
|
||||
newAttributes.push(...newAttributeValues);
|
||||
} else {
|
||||
// Text or number input we don't have an option to fall back on
|
||||
newAttributes.push({
|
||||
id: "-1",
|
||||
attributeId: foundAttributeInCache?.id ?? "-1",
|
||||
value: selectedAttributeOptions[0],
|
||||
slug: slugify(selectedAttributeOptions[0]),
|
||||
contains: [],
|
||||
isGroup: false,
|
||||
weight: 100,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...row,
|
||||
attributes: newAttributes,
|
||||
};
|
||||
}
|
||||
return row;
|
||||
}),
|
||||
}));
|
||||
|
||||
return {
|
||||
...oldData,
|
||||
pages: newPages,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
setSelectedAttribute(undefined);
|
||||
setSelectedAttributeOptions([]);
|
||||
utils.viewer.organizations.listMembers.invalidate();
|
||||
|
||||
@@ -19,20 +19,9 @@ export function DeleteMemberModal({
|
||||
const utils = trpc.useUtils();
|
||||
const removeMemberMutation = trpc.viewer.teams.removeMember.useMutation({
|
||||
onSuccess() {
|
||||
// @ts-expect-error rows can't be of type never[] but oldData can be due to the filter
|
||||
utils.viewer.organizations.listMembers.setInfiniteData({ limit: 10, searchTerm: "" }, (oldData) => {
|
||||
if (!oldData) return oldData;
|
||||
return {
|
||||
...oldData,
|
||||
pages: oldData.pages.map((page) => ({
|
||||
...page,
|
||||
rows: page.rows.filter((member) => member.id !== state.deleteMember.user?.id),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
// Existing invalidations
|
||||
Promise.all([utils.viewer.teams.get.invalidate(), utils.viewer.eventTypes.invalidate()]);
|
||||
utils.viewer.organizations.listMembers.invalidate();
|
||||
utils.viewer.teams.get.invalidate();
|
||||
utils.viewer.eventTypes.invalidate();
|
||||
|
||||
showToast(t("success"), "success");
|
||||
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
import { keepPreviousData } from "@tanstack/react-query";
|
||||
import { getCoreRowModel, getSortedRowModel, useReactTable, type ColumnDef } from "@tanstack/react-table";
|
||||
import { useMemo, useReducer, useRef, useState } from "react";
|
||||
import { useMemo, useReducer, useState } from "react";
|
||||
|
||||
import {
|
||||
DataTableWrapper,
|
||||
DataTableProvider,
|
||||
DataTable,
|
||||
DataTableToolbar,
|
||||
DataTableFilters,
|
||||
DataTableSelectionBar,
|
||||
DataTablePagination,
|
||||
DataTableFilters,
|
||||
useColumnFilters,
|
||||
useFetchMoreOnBottomReached,
|
||||
useDataTable,
|
||||
} from "@calcom/features/data-table";
|
||||
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -55,7 +54,7 @@ type PlatformManagedUsersTableProps = {
|
||||
|
||||
export function PlatformManagedUsersTable(props: PlatformManagedUsersTableProps) {
|
||||
return (
|
||||
<DataTableProvider>
|
||||
<DataTableProvider defaultPageSize={25}>
|
||||
<UserListTableContent {...props} />
|
||||
</DataTableProvider>
|
||||
);
|
||||
@@ -64,36 +63,34 @@ export function PlatformManagedUsersTable(props: PlatformManagedUsersTableProps)
|
||||
function UserListTableContent({ oAuthClientId }: PlatformManagedUsersTableProps) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const tableContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState("");
|
||||
const [rowSelection, setRowSelection] = useState({});
|
||||
|
||||
const columnFilters = useColumnFilters();
|
||||
|
||||
const { data, isPending, hasNextPage, fetchNextPage, isFetching } =
|
||||
trpc.viewer.organizations.listMembers.useInfiniteQuery(
|
||||
{
|
||||
limit: 30,
|
||||
searchTerm: debouncedSearchTerm,
|
||||
filters: columnFilters,
|
||||
oAuthClientId,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
placeholderData: keepPreviousData,
|
||||
enabled: !!oAuthClientId,
|
||||
}
|
||||
);
|
||||
const { pageIndex, pageSize } = useDataTable();
|
||||
const limit = pageSize;
|
||||
const offset = pageIndex * pageSize;
|
||||
|
||||
const totalDBRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
|
||||
const { data, isPending } = trpc.viewer.organizations.listMembers.useQuery(
|
||||
{
|
||||
limit,
|
||||
offset,
|
||||
searchTerm: debouncedSearchTerm,
|
||||
filters: columnFilters,
|
||||
oAuthClientId,
|
||||
},
|
||||
{
|
||||
placeholderData: keepPreviousData,
|
||||
enabled: !!oAuthClientId,
|
||||
}
|
||||
);
|
||||
|
||||
const totalRowCount = data?.meta?.totalRowCount ?? 0;
|
||||
|
||||
//we must flatten the array of arrays from the useInfiniteQuery hook
|
||||
const flatData = useMemo(
|
||||
() => data?.pages?.flatMap((page) => page.rows) ?? [],
|
||||
[data]
|
||||
) as PlatformManagedUserTableUser[];
|
||||
const flatData = useMemo(() => data?.rows ?? [], [data]) as PlatformManagedUserTableUser[];
|
||||
|
||||
const columns = useMemo(() => {
|
||||
const cols: ColumnDef<PlatformManagedUserTableUser>[] = [
|
||||
@@ -293,46 +290,31 @@ function UserListTableContent({ oAuthClientId }: PlatformManagedUsersTableProps)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchMoreOnBottomReached = useFetchMoreOnBottomReached({
|
||||
tableContainerRef,
|
||||
hasNextPage,
|
||||
fetchNextPage,
|
||||
isFetching,
|
||||
});
|
||||
|
||||
const numberOfSelectedRows = useMemo(() => table.getSelectedRowModel().rows.length, [table]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DataTable
|
||||
<DataTableWrapper
|
||||
testId="managed-user-list-data-table"
|
||||
table={table}
|
||||
tableContainerRef={tableContainerRef}
|
||||
isPending={isPending}
|
||||
enableColumnResizing={true}
|
||||
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
||||
<DataTableToolbar.Root>
|
||||
<div className="flex w-full flex-col gap-2 sm:flex-row">
|
||||
<div className="w-full sm:w-auto sm:min-w-[200px] sm:flex-1">
|
||||
<DataTableToolbar.SearchBar
|
||||
table={table}
|
||||
onSearch={(value) => setDebouncedSearchTerm(value)}
|
||||
className="sm:max-w-64 max-w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
{/* We have to omit member because we don't want the filter to show but we can't disable filtering as we need that for the search bar */}
|
||||
<DataTableFilters.AddFilterButton table={table} />
|
||||
<DataTableFilters.ColumnVisibilityButton table={table} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2 justify-self-start">
|
||||
<DataTableFilters.ActiveFilters table={table} />
|
||||
</div>
|
||||
</DataTableToolbar.Root>
|
||||
|
||||
<div style={{ gridArea: "footer", marginTop: "1rem" }}>
|
||||
<DataTablePagination table={table} totalDbDataCount={totalDBRowCount} />
|
||||
totalRowCount={data?.meta?.totalRowCount}
|
||||
paginationMode="standard"
|
||||
ToolbarLeft={
|
||||
<DataTableToolbar.SearchBar
|
||||
table={table}
|
||||
onSearch={(value) => setDebouncedSearchTerm(value)}
|
||||
className="sm:max-w-64 max-w-full"
|
||||
/>
|
||||
}
|
||||
ToolbarRight={
|
||||
<>
|
||||
<DataTableFilters.AddFilterButton table={table} />
|
||||
<DataTableFilters.ColumnVisibilityButton table={table} />
|
||||
</>
|
||||
}>
|
||||
<div className="flex gap-2 justify-self-start">
|
||||
<DataTableFilters.ActiveFilters table={table} />
|
||||
</div>
|
||||
|
||||
{numberOfSelectedRows > 0 && (
|
||||
@@ -346,7 +328,7 @@ function UserListTableContent({ oAuthClientId }: PlatformManagedUsersTableProps)
|
||||
/>
|
||||
</DataTableSelectionBar.Root>
|
||||
)}
|
||||
</DataTable>
|
||||
</DataTableWrapper>
|
||||
{state.deleteMember.showModal && <DeleteMemberModal state={state} dispatch={dispatch} />}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
multiSelectFilter,
|
||||
ColumnFilterType,
|
||||
convertFacetedValuesToMap,
|
||||
useDataTable,
|
||||
} from "@calcom/features/data-table";
|
||||
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
@@ -103,7 +104,7 @@ function reducer(state: UserTableState, action: UserTableAction): UserTableState
|
||||
|
||||
export function UserListTable() {
|
||||
return (
|
||||
<DataTableProvider>
|
||||
<DataTableProvider defaultPageSize={25}>
|
||||
<UserListTableContent />
|
||||
</DataTableProvider>
|
||||
);
|
||||
@@ -117,10 +118,21 @@ function UserListTableContent() {
|
||||
|
||||
const { data: session } = useSession();
|
||||
const { isPlatformUser } = useGetUserAttributes();
|
||||
const { data: org } = trpc.viewer.organizations.listCurrent.useQuery();
|
||||
const { data: attributes, isSuccess: isSuccessAttributes } = trpc.viewer.attributes.list.useQuery();
|
||||
const { data: teams } = trpc.viewer.organizations.getTeams.useQuery();
|
||||
const { data: facetedTeamValues } = trpc.viewer.organizations.getFacetedValues.useQuery();
|
||||
const { data: org } = trpc.viewer.organizations.listCurrent.useQuery(undefined, {
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
const { data: attributes, isSuccess: isSuccessAttributes } = trpc.viewer.attributes.list.useQuery(
|
||||
undefined,
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
}
|
||||
);
|
||||
const { data: teams } = trpc.viewer.organizations.getTeams.useQuery(undefined, {
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
const { data: facetedTeamValues } = trpc.viewer.organizations.getFacetedValues.useQuery(undefined, {
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState("");
|
||||
@@ -129,39 +141,27 @@ function UserListTableContent() {
|
||||
|
||||
const columnFilters = useColumnFilters();
|
||||
|
||||
const { data, isPending, hasNextPage, fetchNextPage, isFetching } =
|
||||
trpc.viewer.organizations.listMembers.useInfiniteQuery(
|
||||
{
|
||||
limit: 30,
|
||||
searchTerm: debouncedSearchTerm,
|
||||
expand: ["attributes"],
|
||||
filters: columnFilters,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
placeholderData: keepPreviousData,
|
||||
}
|
||||
);
|
||||
const { limit, offset } = useDataTable();
|
||||
|
||||
const exportQuery = trpc.viewer.organizations.listMembers.useInfiniteQuery(
|
||||
const { data, isPending } = trpc.viewer.organizations.listMembers.useQuery(
|
||||
{
|
||||
limit: 100, // Max limit
|
||||
limit,
|
||||
offset,
|
||||
searchTerm: debouncedSearchTerm,
|
||||
expand: ["attributes"],
|
||||
filters: columnFilters,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
enabled: false,
|
||||
placeholderData: keepPreviousData,
|
||||
}
|
||||
);
|
||||
|
||||
// TODO (SEAN): Make Column filters a trpc query param so we can fetch serverside even if the data is not loaded
|
||||
const totalDBRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
|
||||
const totalRowCount = data?.meta?.totalRowCount ?? 0;
|
||||
const adminOrOwner = org?.user.role === "ADMIN" || org?.user.role === "OWNER";
|
||||
|
||||
//we must flatten the array of arrays from the useInfiniteQuery hook
|
||||
const flatData = useMemo(() => data?.pages?.flatMap((page) => page.rows) ?? [], [data]) as UserTableUser[];
|
||||
const flatData = useMemo<UserTableUser[]>(() => data?.rows ?? [], [data]);
|
||||
|
||||
const memorisedColumns = useMemo(() => {
|
||||
const permissions = {
|
||||
@@ -174,8 +174,8 @@ function UserListTableContent() {
|
||||
if (!attributes?.length) {
|
||||
return [];
|
||||
}
|
||||
return (
|
||||
(attributes?.map((attribute) => {
|
||||
const attributeColumns: ColumnDef<UserTableUser>[] =
|
||||
attributes?.map((attribute) => {
|
||||
// TODO: We need to normalize AttributeOption table first
|
||||
// so that we can have `number_value` column for numeric operations.
|
||||
// Currently, `value` column is used for both text and number attributes.
|
||||
@@ -184,7 +184,7 @@ function UserListTableContent() {
|
||||
const isNumber = false;
|
||||
const isText = attribute.type === "TEXT";
|
||||
const isSingleSelect = attribute.type === "SINGLE_SELECT";
|
||||
const isMultiSelect = attribute.type === "MULTI_SELECT";
|
||||
// const isMultiSelect = attribute.type === "MULTI_SELECT";
|
||||
const filterType = isNumber
|
||||
? ColumnFilterType.NUMBER
|
||||
: isText
|
||||
@@ -200,15 +200,15 @@ function UserListTableContent() {
|
||||
filter: { type: filterType },
|
||||
},
|
||||
size: 120,
|
||||
accessorFn: (data) => data.attributes.find((attr) => attr.attributeId === attribute.id)?.value,
|
||||
accessorFn: (data) => data.attributes?.find((attr) => attr.attributeId === attribute.id)?.value,
|
||||
cell: ({ row }) => {
|
||||
const attributeValues = row.original.attributes.filter(
|
||||
const attributeValues = row.original.attributes?.filter(
|
||||
(attr) => attr.attributeId === attribute.id
|
||||
);
|
||||
if (attributeValues.length === 0) return null;
|
||||
if (attributeValues?.length === 0) return null;
|
||||
return (
|
||||
<div className={classNames(isNumber ? "flex w-full justify-center" : "flex flex-wrap")}>
|
||||
{attributeValues.map((attributeValue) => {
|
||||
{attributeValues?.map((attributeValue) => {
|
||||
const isAGroupOption = attributeValue.contains?.length > 0;
|
||||
const suffix = attribute.isWeightsEnabled
|
||||
? `${attributeValue.weight || 100}%`
|
||||
@@ -238,27 +238,22 @@ function UserListTableContent() {
|
||||
);
|
||||
},
|
||||
filterFn: (row, id, filterValue) => {
|
||||
const attributeValues = row.original.attributes.filter((attr) => attr.attributeId === id);
|
||||
const attributeValues = row.original.attributes?.filter((attr) => attr.attributeId === id);
|
||||
|
||||
if (isTextFilterValue(filterValue)) {
|
||||
return attributeValues.some((attr) => textFilter(attr.value, filterValue));
|
||||
return attributeValues?.some((attr) => textFilter(attr.value, filterValue)) ?? false;
|
||||
} else if (isSingleSelectFilterValue(filterValue)) {
|
||||
return singleSelectFilter(
|
||||
attributeValues.map((attr) => attr.value),
|
||||
filterValue
|
||||
);
|
||||
return singleSelectFilter(attributeValues?.map((attr) => attr.value) ?? [], filterValue);
|
||||
} else if (isMultiSelectFilterValue(filterValue)) {
|
||||
return multiSelectFilter(
|
||||
attributeValues.map((attr) => attr.value),
|
||||
filterValue
|
||||
);
|
||||
return multiSelectFilter(attributeValues?.map((attr) => attr.value) ?? [], filterValue);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
}) as ColumnDef<UserTableUser>[]) ?? []
|
||||
);
|
||||
}) ?? [];
|
||||
return attributeColumns;
|
||||
};
|
||||
|
||||
const cols: ColumnDef<UserTableUser>[] = [
|
||||
// Disabling select for this PR: Will work on actions etc in a follow up
|
||||
{
|
||||
@@ -430,14 +425,16 @@ function UserListTableContent() {
|
||||
];
|
||||
|
||||
return cols;
|
||||
}, [session?.user.id, adminOrOwner, dispatch, domain, totalDBRowCount, attributes]);
|
||||
}, [session?.user.id, adminOrOwner, dispatch, domain, attributes, org?.canAdminImpersonate]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: flatData,
|
||||
columns: memorisedColumns,
|
||||
enableRowSelection: true,
|
||||
debugTable: true,
|
||||
manualPagination: true,
|
||||
state: {
|
||||
rowSelection,
|
||||
},
|
||||
initialState: {
|
||||
columnVisibility: initalColumnVisibility,
|
||||
columnPinning: {
|
||||
@@ -448,9 +445,6 @@ function UserListTableContent() {
|
||||
defaultColumn: {
|
||||
size: 150,
|
||||
},
|
||||
state: {
|
||||
rowSelection,
|
||||
},
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
onRowSelectionChange: setRowSelection,
|
||||
@@ -489,6 +483,8 @@ function UserListTableContent() {
|
||||
},
|
||||
});
|
||||
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
const numberOfSelectedRows = table.getSelectedRowModel().rows.length;
|
||||
|
||||
const handleDownload = async () => {
|
||||
@@ -502,30 +498,35 @@ function UserListTableContent() {
|
||||
throw new Error("Header is missing.");
|
||||
}
|
||||
|
||||
const result = await exportQuery.refetch();
|
||||
if (!result.data) {
|
||||
throw new Error("There are no members found.");
|
||||
}
|
||||
const allMembers = result.data.pages.flatMap((page) => page.rows ?? []) ?? [];
|
||||
let lastPage = result.data.pages[result.data.pages.length - 1];
|
||||
// Fetch all pages
|
||||
let allRows: UserTableUser[] = [];
|
||||
let offset: number | undefined = 0;
|
||||
const limit = 100;
|
||||
|
||||
while (lastPage.nextCursor) {
|
||||
const nextPage = await exportQuery.fetchNextPage();
|
||||
if (!nextPage.data) {
|
||||
break;
|
||||
while (offset !== undefined) {
|
||||
const result = await utils.viewer.organizations.listMembers.fetch({
|
||||
limit,
|
||||
offset,
|
||||
searchTerm: debouncedSearchTerm,
|
||||
expand: ["attributes"],
|
||||
filters: columnFilters,
|
||||
});
|
||||
|
||||
if (!result.rows?.length) {
|
||||
offset = undefined;
|
||||
continue;
|
||||
}
|
||||
const latestPageItems = nextPage.data.pages[nextPage.data.pages.length - 1].rows ?? [];
|
||||
allMembers.push(...latestPageItems);
|
||||
lastPage = nextPage.data.pages[nextPage.data.pages.length - 1];
|
||||
|
||||
allRows = [...allRows, ...result.rows];
|
||||
offset = offset + limit;
|
||||
}
|
||||
|
||||
if (!allRows.length) {
|
||||
throw new Error("There are no members found.");
|
||||
}
|
||||
|
||||
const ATTRIBUTE_IDS = attributes?.map((attr) => attr.id) ?? [];
|
||||
const csvRaw = generateCsvRawForMembersTable(
|
||||
headers,
|
||||
allMembers as UserTableUser[],
|
||||
ATTRIBUTE_IDS,
|
||||
domain
|
||||
);
|
||||
const csvRaw = generateCsvRawForMembersTable(headers, allRows, ATTRIBUTE_IDS, domain);
|
||||
if (!csvRaw) {
|
||||
throw new Error("Generating CSV file failed.");
|
||||
}
|
||||
@@ -550,10 +551,8 @@ function UserListTableContent() {
|
||||
testId="user-list-data-table"
|
||||
table={table}
|
||||
isPending={isPending}
|
||||
hasNextPage={hasNextPage}
|
||||
fetchNextPage={fetchNextPage}
|
||||
isFetching={isFetching}
|
||||
totalDBRowCount={totalDBRowCount}
|
||||
totalRowCount={data?.meta?.totalRowCount}
|
||||
paginationMode="standard"
|
||||
ToolbarLeft={
|
||||
<>
|
||||
<DataTableToolbar.SearchBar table={table} onSearch={(value) => setDebouncedSearchTerm(value)} />
|
||||
|
||||
@@ -1,30 +1,6 @@
|
||||
import type { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { RouterOutputs } from "@calcom/trpc";
|
||||
|
||||
export interface UserTableUser {
|
||||
id: number;
|
||||
username: string | null;
|
||||
email: string;
|
||||
timeZone: string;
|
||||
role: MembershipRole;
|
||||
avatarUrl: string | null;
|
||||
accepted: boolean;
|
||||
disableImpersonation: boolean;
|
||||
completedOnboarding: boolean;
|
||||
lastActiveAt: string;
|
||||
teams: {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string | null;
|
||||
}[];
|
||||
attributes: {
|
||||
id: string;
|
||||
attributeId: string;
|
||||
value: string;
|
||||
slug: string;
|
||||
weight?: number | null;
|
||||
contains: string[];
|
||||
}[];
|
||||
}
|
||||
export type UserTableUser = RouterOutputs["viewer"]["organizations"]["listMembers"]["rows"][number];
|
||||
|
||||
export type PlatformManagedUserTableUser = Omit<
|
||||
UserTableUser,
|
||||
|
||||
Reference in new issue
Block a user