({ initialSettings }: Props)
| 42 | }; |
| 43 | |
| 44 | export function DataTable({ initialSettings }: Props) { |
| 45 | const trpc = useTRPC(); |
| 46 | const queryClient = useQueryClient(); |
| 47 | const { data: user } = useUserQuery(); |
| 48 | const { filter, hasFilters } = useDocumentFilterParams(); |
| 49 | const { setRowSelection, rowSelection } = useDocumentsStore(); |
| 50 | const { setParams, params } = useDocumentParams(); |
| 51 | const [, copy] = useCopyToClipboard(); |
| 52 | const parentRef = useRef<HTMLDivElement>(null); |
| 53 | |
| 54 | // Hide header on scroll |
| 55 | useScrollHeader(parentRef); |
| 56 | |
| 57 | // Use unified table settings hook for column state management |
| 58 | const { |
| 59 | columnVisibility, |
| 60 | setColumnVisibility, |
| 61 | columnSizing, |
| 62 | setColumnSizing, |
| 63 | columnOrder, |
| 64 | setColumnOrder, |
| 65 | } = useTableSettings({ |
| 66 | tableId: "vault", |
| 67 | initialSettings, |
| 68 | }); |
| 69 | |
| 70 | // Use the reusable table scroll hook |
| 71 | const tableScroll = useTableScroll({ |
| 72 | useColumnWidths: true, |
| 73 | startFromColumn: 2, // Skip sticky columns: select, title |
| 74 | }); |
| 75 | |
| 76 | const { |
| 77 | data, |
| 78 | fetchNextPage, |
| 79 | hasNextPage, |
| 80 | refetch, |
| 81 | isFetching, |
| 82 | isFetchingNextPage, |
| 83 | } = useSuspenseInfiniteQuery( |
| 84 | trpc.documents.get.infiniteQueryOptions( |
| 85 | { |
| 86 | pageSize: 20, |
| 87 | ...filter, |
| 88 | }, |
| 89 | { |
| 90 | getNextPageParam: ({ meta }) => meta?.cursor, |
| 91 | }, |
| 92 | ), |
| 93 | ); |
| 94 | |
| 95 | const baseDocuments = useMemo(() => { |
| 96 | return data?.pages.flatMap((page) => page.data) ?? []; |
| 97 | }, [data]); |
| 98 | |
| 99 | const debouncedEventHandler = useDebounceCallback(() => { |
| 100 | refetch(); |
| 101 |
nothing calls this directly
no test coverage detected