@trackunit/react-table 0.0.207-alpha-11d90c6ca6.0 → 0.0.209
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 +68 -11
- package/index.esm.js +68 -12
- package/package.json +2 -3
- package/src/Table.d.ts +1 -1
- package/src/index.d.ts +1 -0
- package/src/menus/ColumnFilter.d.ts +8 -8
- package/src/menus/Sorting.d.ts +6 -6
- package/src/types.d.ts +13 -0
- package/src/useInfiniteScroll.d.ts +1 -1
- package/src/useRelayPagination.d.ts +29 -0
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: "
|
|
349
|
-
height:
|
|
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 => {
|
|
@@ -358,7 +358,9 @@ const Table = (_a) => {
|
|
|
358
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",
|
|
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;
|
|
@@ -385,7 +387,7 @@ const Table = (_a) => {
|
|
|
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
|
|
407
|
-
* @template
|
|
408
|
-
* @param {
|
|
408
|
+
* @template T - The type representing the data model associated with the columns.
|
|
409
|
+
* @template V - The type representing the value of columns.
|
|
410
|
+
* @param {IColumnFilterProps<T, V>} 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
|
|
560
|
-
* @template
|
|
561
|
-
* @param {SortingProps<
|
|
561
|
+
* @template T - The type representing the data model associated with the columns.
|
|
562
|
+
* @template V - The type representing the value of columns.
|
|
563
|
+
* @param {SortingProps<T, V>} 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,6 +588,60 @@ 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
|
|
|
591
|
+
/**
|
|
592
|
+
* Custom hook for handling Relay pagination in tables.
|
|
593
|
+
*
|
|
594
|
+
* @param {RelayPaginationProps} props - The props object containing pagination configuration.
|
|
595
|
+
* @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
|
|
596
|
+
*/
|
|
597
|
+
const useRelayPagination = (props = { pageSize: 50 }) => {
|
|
598
|
+
const [variables, setVariables] = React.useState({ first: props.pageSize });
|
|
599
|
+
const [pageInfo, setPageInfo] = React.useState();
|
|
600
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
601
|
+
const nextPage = React.useCallback(() => {
|
|
602
|
+
if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
|
|
603
|
+
setVariables({
|
|
604
|
+
after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
|
|
605
|
+
first: props.pageSize,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
}, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
|
|
609
|
+
const previousPage = React.useCallback(() => {
|
|
610
|
+
if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
|
|
611
|
+
setVariables({
|
|
612
|
+
before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
|
|
613
|
+
last: props.pageSize,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
}, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
|
|
617
|
+
const reset = React.useCallback(() => {
|
|
618
|
+
setVariables({
|
|
619
|
+
last: undefined,
|
|
620
|
+
before: undefined,
|
|
621
|
+
after: undefined,
|
|
622
|
+
first: props.pageSize,
|
|
623
|
+
});
|
|
624
|
+
if (props.onReset) {
|
|
625
|
+
props.onReset();
|
|
626
|
+
}
|
|
627
|
+
}, [props.onReset, props.pageSize]);
|
|
628
|
+
const pagination = React.useMemo(() => {
|
|
629
|
+
return {
|
|
630
|
+
variables,
|
|
631
|
+
table: {
|
|
632
|
+
nextPage,
|
|
633
|
+
previousPage,
|
|
634
|
+
isLoading,
|
|
635
|
+
setIsLoading,
|
|
636
|
+
reset,
|
|
637
|
+
pageInfo: pageInfo === null ? undefined : pageInfo,
|
|
638
|
+
setPageInfo,
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
|
|
642
|
+
return pagination;
|
|
643
|
+
};
|
|
644
|
+
|
|
589
645
|
/**
|
|
590
646
|
* Hook for managing and controlling a table's state and behavior.
|
|
591
647
|
*
|
|
@@ -806,5 +862,6 @@ exports.fromTUSortToTanStack = fromTUSortToTanStack;
|
|
|
806
862
|
exports.fromTUSortToTanStackSite = fromTUSortToTanStackSite;
|
|
807
863
|
exports.fromTanStackToTUSort = fromTanStackToTUSort;
|
|
808
864
|
exports.fromTanStackToTUSortSite = fromTanStackToTUSortSite;
|
|
865
|
+
exports.useRelayPagination = useRelayPagination;
|
|
809
866
|
exports.useTable = useTable;
|
|
810
867
|
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: "
|
|
324
|
-
height:
|
|
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 => {
|
|
@@ -333,7 +333,9 @@ const Table = (_a) => {
|
|
|
333
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",
|
|
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;
|
|
@@ -360,7 +362,7 @@ const Table = (_a) => {
|
|
|
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
|
|
382
|
-
* @template
|
|
383
|
-
* @param {
|
|
383
|
+
* @template T - The type representing the data model associated with the columns.
|
|
384
|
+
* @template V - The type representing the value of columns.
|
|
385
|
+
* @param {IColumnFilterProps<T, V>} 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
|
|
535
|
-
* @template
|
|
536
|
-
* @param {SortingProps<
|
|
536
|
+
* @template T - The type representing the data model associated with the columns.
|
|
537
|
+
* @template V - The type representing the value of columns.
|
|
538
|
+
* @param {SortingProps<T, V>} 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,6 +563,60 @@ 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
|
|
|
566
|
+
/**
|
|
567
|
+
* Custom hook for handling Relay pagination in tables.
|
|
568
|
+
*
|
|
569
|
+
* @param {RelayPaginationProps} props - The props object containing pagination configuration.
|
|
570
|
+
* @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
|
|
571
|
+
*/
|
|
572
|
+
const useRelayPagination = (props = { pageSize: 50 }) => {
|
|
573
|
+
const [variables, setVariables] = useState({ first: props.pageSize });
|
|
574
|
+
const [pageInfo, setPageInfo] = useState();
|
|
575
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
576
|
+
const nextPage = useCallback(() => {
|
|
577
|
+
if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
|
|
578
|
+
setVariables({
|
|
579
|
+
after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
|
|
580
|
+
first: props.pageSize,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
|
|
584
|
+
const previousPage = useCallback(() => {
|
|
585
|
+
if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
|
|
586
|
+
setVariables({
|
|
587
|
+
before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
|
|
588
|
+
last: props.pageSize,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
|
|
592
|
+
const reset = useCallback(() => {
|
|
593
|
+
setVariables({
|
|
594
|
+
last: undefined,
|
|
595
|
+
before: undefined,
|
|
596
|
+
after: undefined,
|
|
597
|
+
first: props.pageSize,
|
|
598
|
+
});
|
|
599
|
+
if (props.onReset) {
|
|
600
|
+
props.onReset();
|
|
601
|
+
}
|
|
602
|
+
}, [props.onReset, props.pageSize]);
|
|
603
|
+
const pagination = useMemo(() => {
|
|
604
|
+
return {
|
|
605
|
+
variables,
|
|
606
|
+
table: {
|
|
607
|
+
nextPage,
|
|
608
|
+
previousPage,
|
|
609
|
+
isLoading,
|
|
610
|
+
setIsLoading,
|
|
611
|
+
reset,
|
|
612
|
+
pageInfo: pageInfo === null ? undefined : pageInfo,
|
|
613
|
+
setPageInfo,
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
}, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
|
|
617
|
+
return pagination;
|
|
618
|
+
};
|
|
619
|
+
|
|
564
620
|
/**
|
|
565
621
|
* Hook for managing and controlling a table's state and behavior.
|
|
566
622
|
*
|
|
@@ -768,4 +824,4 @@ const fromTanStackToTUSortSite = (input) => {
|
|
|
768
824
|
*/
|
|
769
825
|
setupLibraryTranslations();
|
|
770
826
|
|
|
771
|
-
export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useTable, useTableSelection };
|
|
827
|
+
export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useRelayPagination, useTable, useTableSelection };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.209",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"@trackunit/react-core-contexts-api": "*",
|
|
22
22
|
"@trackunit/css-class-variance-utilities": "*",
|
|
23
23
|
"@trackunit/ui-icons": "*",
|
|
24
|
-
"@trackunit/i18n-library-translation": "*"
|
|
25
|
-
"@trackunit/react-graphql-hooks": "*"
|
|
24
|
+
"@trackunit/i18n-library-translation": "*"
|
|
26
25
|
},
|
|
27
26
|
"module": "./index.esm.js",
|
|
28
27
|
"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 "
|
|
4
|
+
import { RelayPagination } from "./types";
|
|
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,6 +5,7 @@ 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";
|
|
8
9
|
export * from "./useTable";
|
|
9
10
|
export * from "./useTableSelection";
|
|
10
11
|
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
|
|
4
|
-
columns: Column<
|
|
3
|
+
export interface IColumnFilterProps<T extends object, V> {
|
|
4
|
+
columns: Column<T, V>[];
|
|
5
5
|
defaultColumnOrder: ColumnOrderState;
|
|
6
6
|
columnOrder?: ColumnOrderState;
|
|
7
7
|
className?: string;
|
|
@@ -11,14 +11,14 @@ export interface ColumnFilterProps<TColumnFilter extends object, TColumnFilterVa
|
|
|
11
11
|
/**
|
|
12
12
|
* ColumnFilter component for managing visibility and order of table columns.
|
|
13
13
|
*
|
|
14
|
-
* @template
|
|
15
|
-
* @template
|
|
16
|
-
* @param {
|
|
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.
|
|
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: <
|
|
20
|
-
export interface ColumnFiltersDragAndDropProps<
|
|
21
|
-
columns: Column<
|
|
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>[];
|
|
22
22
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
|
|
23
23
|
onUserEvent?: (event: "Column Reordering" | "Column Filter", payload: Record<string, unknown>) => void;
|
|
24
24
|
}
|
package/src/menus/Sorting.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Column } from "@tanstack/react-table";
|
|
3
|
-
interface SortingProps<
|
|
4
|
-
columns: Column<
|
|
3
|
+
interface SortingProps<T extends object, V> {
|
|
4
|
+
columns: Column<T, V>[];
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Sorting component for managing table column sorting.
|
|
8
8
|
*
|
|
9
|
-
* @template
|
|
10
|
-
* @template
|
|
11
|
-
* @param {SortingProps<
|
|
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.
|
|
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: <
|
|
14
|
+
export declare const Sorting: <T extends Object, V>({ columns }: SortingProps<T, V>) => JSX.Element | null;
|
|
15
15
|
export {};
|
package/src/types.d.ts
CHANGED
|
@@ -9,4 +9,17 @@ 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
|
+
}
|
|
12
25
|
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";
|
|
3
2
|
import { RefObject } from "react";
|
|
3
|
+
import { RelayPagination } from "./types";
|
|
4
4
|
interface InfiniteScrollProps {
|
|
5
5
|
pagination: RelayPagination;
|
|
6
6
|
containerRef: RefObject<HTMLDivElement>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|