@trackunit/react-table 0.0.207 → 0.0.210-alpha-1820203754.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -345,8 +345,8 @@ const Table = (_a) => {
345
345
  rowHeight,
346
346
  });
347
347
  const hasResults = props.getRowModel().rows.length > 0;
348
- return (jsxRuntime.jsxs(reactComponents.Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex", children: props.headerRightActions })] })), jsxRuntime.jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxRuntime.jsxs(reactTableBaseComponents.TableRoot, { style: {
349
- height: getTotalSize() > 0 ? getTotalSize() : "100%",
348
+ return (jsxRuntime.jsxs(reactComponents.Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex", children: props.headerRightActions })] })), jsxRuntime.jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxRuntime.jsxs(reactTableBaseComponents.TableRoot, { style: {
349
+ height: hasResults ? "auto" : "100%",
350
350
  width: "100%",
351
351
  position: "relative",
352
352
  }, children: [jsxRuntime.jsx(reactTableBaseComponents.Thead, { className: "z-default", children: props.getHeaderGroups().map(headerGroup => (jsxRuntime.jsx(reactTableBaseComponents.Tr, { className: "flex", children: headerGroup.headers.map(header => {
@@ -355,10 +355,12 @@ const Table = (_a) => {
355
355
  width: header.getSize(),
356
356
  minWidth: header.column.columnDef.minSize,
357
357
  maxWidth: header.column.columnDef.maxSize,
358
- textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
358
+ textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
359
359
  }, className: "relative", children: [header.isPlaceholder ? null : (jsxRuntime.jsxs("div", { className: `${header.column.getCanSort() ? "cursor-pointer select-none flex" : ""} items-center gap-2 py-2 overflow-hidden pr-3`,
360
360
  onClick: header.column.getToggleSortingHandler(), children: [jsxRuntime.jsxs("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap", children: [reactTable.flexRender(header.column.columnDef.header, header.getContext()), ((_c = (_b = header.column.columnDef) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c.subHeader) ? (jsxRuntime.jsx(reactComponents.Text, { size: "small", subtle: true, children: (_e = (_d = header.column.columnDef) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.subHeader })) : null] }), header.column.getCanSort() ? (jsxRuntime.jsx(reactTableBaseComponents.SortIndicator, { sortingState: header.column.getIsSorted() })) : null] })), header.column.getCanResize() ? (jsxRuntime.jsx(reactTableBaseComponents.ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null] }, header.id));
361
- }) }, headerGroup.id))) }), hasResults ? (jsxRuntime.jsx(reactTableBaseComponents.Tbody, { className: "text-sm font-normal", children: getVirtualItems().map((virtualRow, index) => {
361
+ }) }, headerGroup.id))) }), hasResults ? (jsxRuntime.jsx(reactTableBaseComponents.Tbody, { className: "text-sm font-normal", style: {
362
+ height: `${getTotalSize()}px`,
363
+ }, children: getVirtualItems().map((virtualRow, index) => {
362
364
  const row = props.getRowModel().rows[virtualRow.index];
363
365
  if (!row) {
364
366
  return null;
@@ -381,11 +383,11 @@ const Table = (_a) => {
381
383
  width: cell.column.getSize(),
382
384
  minWidth: cell.column.columnDef.minSize,
383
385
  maxWidth: cell.column.columnDef.maxSize,
384
- textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
386
+ textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
385
387
  }, children: jsxRuntime.jsx("div", { className: "grid h-full items-center", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
386
388
  }) }, row.id));
387
389
  }
388
- }) })) : (jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsxRuntime.jsx(reactComponents.EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxRuntime.jsxs("div", { className: "flex items-center p-2", children: [jsxRuntime.jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
390
+ }) })) : (jsxRuntime.jsx("tbody", { className: "min-h-[400px]", children: jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsxRuntime.jsx(reactComponents.EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxRuntime.jsxs("div", { className: "flex items-center p-2", children: [jsxRuntime.jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
389
391
  count: props.getRowModel().rows.length,
390
392
  total: ((_c = (_b = props.pagination) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.count) || 0,
391
393
  }) }), props.pagination.isLoading ? (jsxRuntime.jsx("span", { className: "ml-2", children: jsxRuntime.jsx(reactComponents.Spinner, { size: "small" }) })) : null, props.footerRightActions && jsxRuntime.jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] }))] }));
@@ -403,9 +405,9 @@ const cvaColumnFilterGrabbable = cssClassVarianceUtilities.cvaMerge(["flex", "it
403
405
  /**
404
406
  * ColumnFilter component for managing visibility and order of table columns.
405
407
  *
406
- * @template T - The type representing the data model associated with the columns.
407
- * @template V - The type representing the value of columns.
408
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
408
+ * @template TColumnFilter - The type representing the data model associated with the columns.
409
+ * @template TColumnFilterValue - The type representing the value of columns.
410
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
409
411
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
410
412
  */
411
413
  const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
@@ -556,12 +558,12 @@ const CompactIcon = () => {
556
558
  /**
557
559
  * Sorting component for managing table column sorting.
558
560
  *
559
- * @template T - The type representing the data model associated with the columns.
560
- * @template V - The type representing the value of columns.
561
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
561
+ * @template TSorting - The type representing the data model associated with the columns.
562
+ * @template TSortingValue - The type representing the value of columns.
563
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
562
564
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
563
565
  */
564
- const Sorting = ({ columns }) => {
566
+ const Sorting = ({ columns, }) => {
565
567
  var _a, _b;
566
568
  const [t] = useTranslation();
567
569
  const sortableColumns = columns.filter(column => column.getCanSort());
@@ -586,60 +588,6 @@ const Sorting = ({ columns }) => {
586
588
  }) }), jsxRuntime.jsxs(reactFormComponents.RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
587
589
  };
588
590
 
589
- /**
590
- * Custom hook for handling Relay pagination in tables.
591
- *
592
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
593
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
594
- */
595
- const useRelayPagination = (props = { pageSize: 50 }) => {
596
- const [variables, setVariables] = React.useState({ first: props.pageSize });
597
- const [pageInfo, setPageInfo] = React.useState();
598
- const [isLoading, setIsLoading] = React.useState(false);
599
- const nextPage = React.useCallback(() => {
600
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
601
- setVariables({
602
- after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
603
- first: props.pageSize,
604
- });
605
- }
606
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
607
- const previousPage = React.useCallback(() => {
608
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
609
- setVariables({
610
- before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
611
- last: props.pageSize,
612
- });
613
- }
614
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
615
- const reset = React.useCallback(() => {
616
- setVariables({
617
- last: undefined,
618
- before: undefined,
619
- after: undefined,
620
- first: props.pageSize,
621
- });
622
- if (props.onReset) {
623
- props.onReset();
624
- }
625
- }, [props.onReset, props.pageSize]);
626
- const pagination = React.useMemo(() => {
627
- return {
628
- variables,
629
- table: {
630
- nextPage,
631
- previousPage,
632
- isLoading,
633
- setIsLoading,
634
- reset,
635
- pageInfo: pageInfo === null ? undefined : pageInfo,
636
- setPageInfo,
637
- },
638
- };
639
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
640
- return pagination;
641
- };
642
-
643
591
  /**
644
592
  * Hook for managing and controlling a table's state and behavior.
645
593
  *
@@ -743,7 +691,7 @@ const useTable = (_a) => {
743
691
  * columns,
744
692
  * });
745
693
  */
746
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
694
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
747
695
  const [rowSelection, setRowSelection] = React.useState({});
748
696
  React.useEffect(() => {
749
697
  const initialSelection = {};
@@ -784,8 +732,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
784
732
  const selectionTableProps = React.useMemo(() => ({
785
733
  onRowSelectionChange: setRowSelection,
786
734
  getRowId: row => row.id,
787
- enableRowSelection: true,
788
- }), []);
735
+ enableRowSelection,
736
+ }), [enableRowSelection]);
789
737
  return React.useMemo(() => ({
790
738
  toggleRowSelectionState,
791
739
  selectionColumn,
@@ -860,6 +808,5 @@ exports.fromTUSortToTanStack = fromTUSortToTanStack;
860
808
  exports.fromTUSortToTanStackSite = fromTUSortToTanStackSite;
861
809
  exports.fromTanStackToTUSort = fromTanStackToTUSort;
862
810
  exports.fromTanStackToTUSortSite = fromTanStackToTUSortSite;
863
- exports.useRelayPagination = useRelayPagination;
864
811
  exports.useTable = useTable;
865
812
  exports.useTableSelection = useTableSelection;
package/index.esm.js CHANGED
@@ -320,8 +320,8 @@ const Table = (_a) => {
320
320
  rowHeight,
321
321
  });
322
322
  const hasResults = props.getRowModel().rows.length > 0;
323
- return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxs(TableRoot, { style: {
324
- height: getTotalSize() > 0 ? getTotalSize() : "100%",
323
+ return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxs(TableRoot, { style: {
324
+ height: hasResults ? "auto" : "100%",
325
325
  width: "100%",
326
326
  position: "relative",
327
327
  }, children: [jsx(Thead, { className: "z-default", children: props.getHeaderGroups().map(headerGroup => (jsx(Tr, { className: "flex", children: headerGroup.headers.map(header => {
@@ -330,10 +330,12 @@ const Table = (_a) => {
330
330
  width: header.getSize(),
331
331
  minWidth: header.column.columnDef.minSize,
332
332
  maxWidth: header.column.columnDef.maxSize,
333
- textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
333
+ textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
334
334
  }, className: "relative", children: [header.isPlaceholder ? null : (jsxs("div", { className: `${header.column.getCanSort() ? "cursor-pointer select-none flex" : ""} items-center gap-2 py-2 overflow-hidden pr-3`,
335
335
  onClick: header.column.getToggleSortingHandler(), children: [jsxs("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap", children: [flexRender(header.column.columnDef.header, header.getContext()), ((_c = (_b = header.column.columnDef) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c.subHeader) ? (jsx(Text, { size: "small", subtle: true, children: (_e = (_d = header.column.columnDef) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.subHeader })) : null] }), header.column.getCanSort() ? (jsx(SortIndicator, { sortingState: header.column.getIsSorted() })) : null] })), header.column.getCanResize() ? (jsx(ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null] }, header.id));
336
- }) }, headerGroup.id))) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", children: getVirtualItems().map((virtualRow, index) => {
336
+ }) }, headerGroup.id))) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", style: {
337
+ height: `${getTotalSize()}px`,
338
+ }, children: getVirtualItems().map((virtualRow, index) => {
337
339
  const row = props.getRowModel().rows[virtualRow.index];
338
340
  if (!row) {
339
341
  return null;
@@ -356,11 +358,11 @@ const Table = (_a) => {
356
358
  width: cell.column.getSize(),
357
359
  minWidth: cell.column.columnDef.minSize,
358
360
  maxWidth: cell.column.columnDef.maxSize,
359
- textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
361
+ textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
360
362
  }, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
361
363
  }) }, row.id));
362
364
  }
363
- }) })) : (jsx("tbody", { children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsx(Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
365
+ }) })) : (jsx("tbody", { className: "min-h-[400px]", children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsx(Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
364
366
  count: props.getRowModel().rows.length,
365
367
  total: ((_c = (_b = props.pagination) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.count) || 0,
366
368
  }) }), props.pagination.isLoading ? (jsx("span", { className: "ml-2", children: jsx(Spinner, { size: "small" }) })) : null, props.footerRightActions && jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] }))] }));
@@ -378,9 +380,9 @@ const cvaColumnFilterGrabbable = cvaMerge(["flex", "items-center", "justify-cent
378
380
  /**
379
381
  * ColumnFilter component for managing visibility and order of table columns.
380
382
  *
381
- * @template T - The type representing the data model associated with the columns.
382
- * @template V - The type representing the value of columns.
383
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
383
+ * @template TColumnFilter - The type representing the data model associated with the columns.
384
+ * @template TColumnFilterValue - The type representing the value of columns.
385
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
384
386
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
385
387
  */
386
388
  const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
@@ -531,12 +533,12 @@ const CompactIcon = () => {
531
533
  /**
532
534
  * Sorting component for managing table column sorting.
533
535
  *
534
- * @template T - The type representing the data model associated with the columns.
535
- * @template V - The type representing the value of columns.
536
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
536
+ * @template TSorting - The type representing the data model associated with the columns.
537
+ * @template TSortingValue - The type representing the value of columns.
538
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
537
539
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
538
540
  */
539
- const Sorting = ({ columns }) => {
541
+ const Sorting = ({ columns, }) => {
540
542
  var _a, _b;
541
543
  const [t] = useTranslation();
542
544
  const sortableColumns = columns.filter(column => column.getCanSort());
@@ -561,60 +563,6 @@ const Sorting = ({ columns }) => {
561
563
  }) }), jsxs(RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsx(RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsx(RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
562
564
  };
563
565
 
564
- /**
565
- * Custom hook for handling Relay pagination in tables.
566
- *
567
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
568
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
569
- */
570
- const useRelayPagination = (props = { pageSize: 50 }) => {
571
- const [variables, setVariables] = useState({ first: props.pageSize });
572
- const [pageInfo, setPageInfo] = useState();
573
- const [isLoading, setIsLoading] = useState(false);
574
- const nextPage = useCallback(() => {
575
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
576
- setVariables({
577
- after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
578
- first: props.pageSize,
579
- });
580
- }
581
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
582
- const previousPage = useCallback(() => {
583
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
584
- setVariables({
585
- before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
586
- last: props.pageSize,
587
- });
588
- }
589
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
590
- const reset = useCallback(() => {
591
- setVariables({
592
- last: undefined,
593
- before: undefined,
594
- after: undefined,
595
- first: props.pageSize,
596
- });
597
- if (props.onReset) {
598
- props.onReset();
599
- }
600
- }, [props.onReset, props.pageSize]);
601
- const pagination = useMemo(() => {
602
- return {
603
- variables,
604
- table: {
605
- nextPage,
606
- previousPage,
607
- isLoading,
608
- setIsLoading,
609
- reset,
610
- pageInfo: pageInfo === null ? undefined : pageInfo,
611
- setPageInfo,
612
- },
613
- };
614
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
615
- return pagination;
616
- };
617
-
618
566
  /**
619
567
  * Hook for managing and controlling a table's state and behavior.
620
568
  *
@@ -718,7 +666,7 @@ const useTable = (_a) => {
718
666
  * columns,
719
667
  * });
720
668
  */
721
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
669
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
722
670
  const [rowSelection, setRowSelection] = useState({});
723
671
  useEffect(() => {
724
672
  const initialSelection = {};
@@ -759,8 +707,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
759
707
  const selectionTableProps = useMemo(() => ({
760
708
  onRowSelectionChange: setRowSelection,
761
709
  getRowId: row => row.id,
762
- enableRowSelection: true,
763
- }), []);
710
+ enableRowSelection,
711
+ }), [enableRowSelection]);
764
712
  return useMemo(() => ({
765
713
  toggleRowSelectionState,
766
714
  selectionColumn,
@@ -822,4 +770,4 @@ const fromTanStackToTUSortSite = (input) => {
822
770
  */
823
771
  setupLibraryTranslations();
824
772
 
825
- export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useRelayPagination, useTable, useTableSelection };
773
+ export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useTable, useTableSelection };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "0.0.207",
3
+ "version": "0.0.210-alpha-1820203754.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -21,7 +21,8 @@
21
21
  "@trackunit/react-core-contexts-api": "*",
22
22
  "@trackunit/css-class-variance-utilities": "*",
23
23
  "@trackunit/ui-icons": "*",
24
- "@trackunit/i18n-library-translation": "*"
24
+ "@trackunit/i18n-library-translation": "*",
25
+ "@trackunit/react-graphql-hooks": "*"
25
26
  },
26
27
  "module": "./index.esm.js",
27
28
  "main": "./index.cjs.js"
package/src/Table.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Table as ReactTable, Row } from "@tanstack/react-table";
3
3
  import { CommonProps } from "@trackunit/react-components";
4
- import { RelayPagination } from "./types";
4
+ import { RelayPagination } from "@trackunit/react-graphql-hooks";
5
5
  export interface TableProps<TData extends object> extends ReactTable<TData>, CommonProps {
6
6
  pagination: RelayPagination;
7
7
  headerLeftActions?: React.ReactNode;
package/src/index.d.ts CHANGED
@@ -5,7 +5,6 @@ export * from "./menus/ColumnFilter";
5
5
  export * from "./menus/RowSpacing";
6
6
  export * from "./menus/Sorting";
7
7
  export * from "./types";
8
- export * from "./useRelayPagination";
9
8
  export * from "./useTable";
10
9
  export * from "./useTableSelection";
11
10
  export * from "./utils";
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Column, ColumnOrderState, Updater } from "@tanstack/react-table";
3
- export interface IColumnFilterProps<T extends object, V> {
4
- columns: Column<T, V>[];
3
+ export interface ColumnFilterProps<TColumnFilter extends object, TColumnFilterValue> {
4
+ columns: Column<TColumnFilter, TColumnFilterValue>[];
5
5
  defaultColumnOrder: ColumnOrderState;
6
6
  columnOrder?: ColumnOrderState;
7
7
  className?: string;
@@ -11,14 +11,14 @@ export interface IColumnFilterProps<T extends object, V> {
11
11
  /**
12
12
  * ColumnFilter component for managing visibility and order of table columns.
13
13
  *
14
- * @template T - The type representing the data model associated with the columns.
15
- * @template V - The type representing the value of columns.
16
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
14
+ * @template TColumnFilter - The type representing the data model associated with the columns.
15
+ * @template TColumnFilterValue - The type representing the value of columns.
16
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
17
17
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
18
18
  */
19
- export declare const ColumnFilter: <T extends Object, V>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: IColumnFilterProps<T, V>) => JSX.Element | null;
20
- export interface ColumnFiltersDragAndDropProps<T extends object, V> {
21
- columns: Column<T, V>[];
19
+ export declare const ColumnFilter: <TColumnFilter extends Object, TColumnFilterValue>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: ColumnFilterProps<TColumnFilter, TColumnFilterValue>) => JSX.Element | null;
20
+ export interface ColumnFiltersDragAndDropProps<TColumnFiltersDragAndDrop extends object, TColumnFiltersDragAndDropValue> {
21
+ columns: Column<TColumnFiltersDragAndDrop, TColumnFiltersDragAndDropValue>[];
22
22
  setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
23
23
  onUserEvent?: (event: "Column Reordering" | "Column Filter", payload: Record<string, unknown>) => void;
24
24
  }
@@ -1,15 +1,15 @@
1
1
  /// <reference types="react" />
2
2
  import { Column } from "@tanstack/react-table";
3
- interface SortingProps<T extends object, V> {
4
- columns: Column<T, V>[];
3
+ interface SortingProps<TSorting extends object, TSortingValue> {
4
+ columns: Column<TSorting, TSortingValue>[];
5
5
  }
6
6
  /**
7
7
  * Sorting component for managing table column sorting.
8
8
  *
9
- * @template T - The type representing the data model associated with the columns.
10
- * @template V - The type representing the value of columns.
11
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
9
+ * @template TSorting - The type representing the data model associated with the columns.
10
+ * @template TSortingValue - The type representing the value of columns.
11
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
12
12
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
13
13
  */
14
- export declare const Sorting: <T extends Object, V>({ columns }: SortingProps<T, V>) => JSX.Element | null;
14
+ export declare const Sorting: <TSorting extends Object, TSortingValue>({ columns, }: SortingProps<TSorting, TSortingValue>) => JSX.Element | null;
15
15
  export {};
package/src/types.d.ts CHANGED
@@ -9,17 +9,4 @@ declare module "@tanstack/react-table" {
9
9
  isCustomField?: boolean;
10
10
  }
11
11
  }
12
- export interface RelayPageInfo {
13
- count?: number | null;
14
- endCursor?: string | null;
15
- hasNextPage?: boolean;
16
- hasPreviousPage?: boolean;
17
- startCursor?: string | null;
18
- }
19
- export interface RelayPagination {
20
- nextPage: () => void;
21
- previousPage: () => void;
22
- pageInfo?: RelayPageInfo;
23
- isLoading: boolean;
24
- }
25
12
  export type Alignment = "left" | "center" | "right";
@@ -1,6 +1,6 @@
1
1
  import { VirtualItem } from "@tanstack/react-virtual";
2
+ import { RelayPagination } from "@trackunit/react-graphql-hooks";
2
3
  import { RefObject } from "react";
3
- import { RelayPagination } from "./types";
4
4
  interface InfiniteScrollProps {
5
5
  pagination: RelayPagination;
6
6
  containerRef: RefObject<HTMLDivElement>;
@@ -1,6 +1,6 @@
1
1
  import { ColumnDef, RowSelectionState } from "@tanstack/react-table";
2
2
  import { Dispatch, SetStateAction } from "react";
3
- type selectableTableData = {
3
+ export type selectableTableData = {
4
4
  id: string;
5
5
  } & object;
6
6
  export interface TableSelectionReturn<TData extends selectableTableData> {
@@ -21,7 +21,7 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
21
21
  selectionTableProps: {
22
22
  onRowSelectionChange: Dispatch<SetStateAction<RowSelectionState>>;
23
23
  getRowId: (row: TData) => TData["id"];
24
- enableRowSelection: true;
24
+ enableRowSelection: boolean;
25
25
  };
26
26
  /**
27
27
  * A function to update the row selection state.
@@ -39,8 +39,22 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
39
39
  toggleRowSelectionState: (id: TData["id"]) => void;
40
40
  }
41
41
  export interface TableSelectionProps<TData extends selectableTableData> {
42
+ /**
43
+ * The data that is displayed in the table.
44
+ * This must have an `id` field, to enable selection.
45
+ * The same data should be passed to the `data` prop of the `useTable` Hook.
46
+ */
42
47
  data: TData[];
48
+ /**
49
+ * An array of ids of the rows that should be selected by default.
50
+ * This is useful when you want to preselect rows, for example when editing an existing entity.
51
+ */
43
52
  defaultSelectedIds?: TData["id"][];
53
+ /**
54
+ * Whether or not to enable row selection.
55
+ * If set to `false`, the selection column will still be displayed, but the checkboxes will be disabled.
56
+ */
57
+ enableRowSelection?: boolean;
44
58
  }
45
59
  /**
46
60
  * `useTableSelection` is a custom hook that provides functionality for row selection in a table.
@@ -69,5 +83,4 @@ export interface TableSelectionProps<TData extends selectableTableData> {
69
83
  * columns,
70
84
  * });
71
85
  */
72
- export declare const useTableSelection: <TData extends selectableTableData>({ data, defaultSelectedIds, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
73
- export {};
86
+ export declare const useTableSelection: <TData extends selectableTableData>({ data, defaultSelectedIds, enableRowSelection, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
@@ -0,0 +1,11 @@
1
+ import { TableSelectionProps, selectableTableData } from "./useTableSelection";
2
+ export interface UseTableSelectionDemoComponentProps<TData extends selectableTableData> extends TableSelectionProps<TData> {
3
+ }
4
+ /**
5
+ * The `useTableSelection` Hook provides functionality for row selection in a table.
6
+ *
7
+ * It returns an object containing methods and values related to row selection.
8
+ *
9
+ * It Also returns a `selectionColumn` object that can be used as a column definition in a table.
10
+ */
11
+ export declare const UseTableSelectionDemoComponent: <TData extends selectableTableData>(props: UseTableSelectionDemoComponentProps<TData>) => JSX.Element;
@@ -1,29 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- import { RelayPageInfo, RelayPagination } from "./types";
3
- export interface RelayPaginationProps {
4
- pageSize?: number;
5
- onReset?: () => void;
6
- }
7
- export interface RelayPaginationQueryVariables {
8
- first?: number | null;
9
- last?: number | null;
10
- before?: string | null;
11
- after?: string | null;
12
- }
13
- export interface RelayTableSupport extends RelayPagination {
14
- isLoading: boolean;
15
- setIsLoading: Dispatch<SetStateAction<boolean>>;
16
- reset: () => void;
17
- setPageInfo: Dispatch<SetStateAction<RelayPageInfo | null | undefined>>;
18
- }
19
- export interface RelayPaginationSupport {
20
- variables: RelayPaginationQueryVariables;
21
- table: RelayTableSupport;
22
- }
23
- /**
24
- * Custom hook for handling Relay pagination in tables.
25
- *
26
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
27
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
28
- */
29
- export declare const useRelayPagination: (props?: RelayPaginationProps) => RelayPaginationSupport;