import { ScrollArea } from '@affine/admin/components/ui/scroll-area'; import { Table, TableBody, TableCell, TableRow, } from '@affine/admin/components/ui/table'; import type { ColumnDef, PaginationState } from '@tanstack/react-table'; import { flexRender, getCoreRowModel, useReactTable, } from '@tanstack/react-table'; import { type Dispatch, type SetStateAction, useEffect, useState } from 'react'; import { DataTablePagination } from './data-table-pagination'; import { DataTableToolbar } from './data-table-toolbar'; import { useUserCount } from './use-user-management'; interface DataTableProps { columns: ColumnDef[]; data: TData[]; pagination: PaginationState; onPaginationChange: Dispatch< SetStateAction<{ pageIndex: number; pageSize: number; }> >; } export function DataTable({ columns, data, pagination, onPaginationChange, }: DataTableProps) { const usersCount = useUserCount(); const [tableData, setTableData] = useState(data); const table = useReactTable({ data: tableData, columns, getCoreRowModel: getCoreRowModel(), manualPagination: true, rowCount: usersCount, enableFilters: true, onPaginationChange: onPaginationChange, state: { pagination, }, }); useEffect(() => { setTableData(data); }, [data]); return (
{table.getRowModel().rows?.length ? ( table.getRowModel().rows.map(row => ( {row.getVisibleCells().map(cell => ( {flexRender( cell.column.columnDef.cell, cell.getContext() )} ))} )) ) : ( No results. )}
); }