@trackunit/react-table 1.0.25 → 1.0.28
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 +38 -57
- package/index.esm.js +11 -12
- package/package.json +10 -10
package/index.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
5
5
|
var reactComponents = require('@trackunit/react-components');
|
|
6
6
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
7
|
-
var
|
|
7
|
+
var react = require('react');
|
|
8
8
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
9
9
|
var reactRouter = require('@tanstack/react-router');
|
|
10
10
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
@@ -17,25 +17,6 @@ var reactTablePagination = require('@trackunit/react-table-pagination');
|
|
|
17
17
|
var tailwindMerge = require('tailwind-merge');
|
|
18
18
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
19
19
|
|
|
20
|
-
function _interopNamespaceDefault(e) {
|
|
21
|
-
var n = Object.create(null);
|
|
22
|
-
if (e) {
|
|
23
|
-
Object.keys(e).forEach(function (k) {
|
|
24
|
-
if (k !== 'default') {
|
|
25
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () { return e[k]; }
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
n.default = e;
|
|
34
|
-
return Object.freeze(n);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
38
|
-
|
|
39
20
|
var defaultTranslations = {
|
|
40
21
|
"layout.actions.reset": "Reset",
|
|
41
22
|
"table.actionsheet.selected": "{{count}} selected",
|
|
@@ -245,7 +226,7 @@ const ActionIcon = ({ action }) => {
|
|
|
245
226
|
* @returns {ReactElement} The rendered component.
|
|
246
227
|
*/
|
|
247
228
|
const ActionContainerAndOverflow = ({ actions, dropdownActions, moreActions, dataTestId, }) => {
|
|
248
|
-
const children =
|
|
229
|
+
const children = react.useMemo(() => actions.map(action => actionDataToActionButton(action)), [actions]);
|
|
249
230
|
const { overflowContainerRef, itemOverflowMap } = reactComponents.useOverflowItems({
|
|
250
231
|
children,
|
|
251
232
|
childUniqueIdentifierAttribute: "id",
|
|
@@ -258,8 +239,8 @@ const ActionContainerAndOverflow = ({ actions, dropdownActions, moreActions, dat
|
|
|
258
239
|
return "visible";
|
|
259
240
|
};
|
|
260
241
|
const overflowItemCount = sharedUtils.objectValues(itemOverflowMap).filter(isOverflowing => isOverflowing).length;
|
|
261
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: cvaActionContainerAndOverflow({ isDropdown: dropdownActions !== undefined }), ref: overflowContainerRef, children:
|
|
262
|
-
return
|
|
242
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: cvaActionContainerAndOverflow({ isDropdown: dropdownActions !== undefined }), ref: overflowContainerRef, children: react.Children.map(children, child => {
|
|
243
|
+
return react.cloneElement(child, {
|
|
263
244
|
className: `${child.props.className} ${itemVisibilityClassName(child.props.id)}`,
|
|
264
245
|
});
|
|
265
246
|
}) }), jsxRuntime.jsxs("div", { className: cvaMoreContainer({ isDropdown: dropdownActions !== undefined }), children: [dropdownActions
|
|
@@ -268,7 +249,7 @@ const ActionContainerAndOverflow = ({ actions, dropdownActions, moreActions, dat
|
|
|
268
249
|
// eslint-disable-next-line local-rules/design-guideline-button-icon-size-match
|
|
269
250
|
prefix: jsxRuntime.jsx(ActionIcon, { action: action }), children: action.label }), dataTestId: `${dataTestId}-dropdown-more-menu`, popoverProps: { placement: "top-end" }, children: !action.loading ? action.dropdown : null }, action.id));
|
|
270
251
|
})
|
|
271
|
-
: null,
|
|
252
|
+
: null, react.Children.count(moreActions) > 0 || overflowItemCount ? (jsxRuntime.jsx(reactComponents.MoreMenu, { dataTestId: `${dataTestId}-more-menu`, iconButtonProps: { variant: "primary" }, iconProps: { color: "white" }, popoverProps: { placement: "top-end" }, children: close => (jsxRuntime.jsxs(reactComponents.MenuList, { className: "relative -right-2", onClick: close, children: [moreActions ? moreActions : null, actions.map(action => {
|
|
272
253
|
return itemOverflowMap[action.id] ? actionDataToMenuItem(action, dataTestId) : null;
|
|
273
254
|
})] })) })) : null] })] }));
|
|
274
255
|
};
|
|
@@ -309,17 +290,17 @@ const cvaColumnFilterGrabbable = cssClassVarianceUtilities.cvaMerge(["flex", "it
|
|
|
309
290
|
const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder = [], columnOrder, onUserEvent, }) => {
|
|
310
291
|
const [t] = useTranslation();
|
|
311
292
|
const numberOfHiddenColumns = columns.filter(column => !column.getIsVisible()).length;
|
|
312
|
-
|
|
293
|
+
react.useEffect(() => {
|
|
313
294
|
if (defaultColumnOrder.length > 0) {
|
|
314
295
|
setColumnOrder(defaultColumnOrder);
|
|
315
296
|
}
|
|
316
297
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
317
298
|
}, []); //This should only run once, at page load
|
|
318
|
-
const resetHiddenColumns =
|
|
299
|
+
const resetHiddenColumns = react.useCallback(() => {
|
|
319
300
|
columns.forEach(column => column.toggleVisibility(!column.columnDef.meta?.hiddenByDefault));
|
|
320
301
|
setColumnOrder(defaultColumnOrder);
|
|
321
302
|
}, [columns, defaultColumnOrder, setColumnOrder]);
|
|
322
|
-
const sortedColumns =
|
|
303
|
+
const sortedColumns = react.useMemo(() => {
|
|
323
304
|
const result = columnOrder && (columnOrder.length || 0) > 0
|
|
324
305
|
? columns.sort((a, b) => columnOrder.indexOf(a.id) - columnOrder.indexOf(b.id))
|
|
325
306
|
: columns;
|
|
@@ -337,11 +318,11 @@ const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder = [], column
|
|
|
337
318
|
return (jsxRuntime.jsx(reactDnd.DndProvider, { backend: reactDndHtml5Backend.HTML5Backend, children: jsxRuntime.jsx(reactComponents.Tooltip, { label: t("table.columnFilters.tooltip"), placement: "bottom", children: jsxRuntime.jsxs(reactComponents.Popover, { placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: jsxRuntime.jsx(reactComponents.Button, { prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "ViewColumns", size: "small" }), size: "small", variant: "ghost-neutral", children: jsxRuntime.jsx("span", { className: "hidden sm:block", children: getColumnButtonText() }) }) }), jsxRuntime.jsx(reactComponents.PopoverContent, { children: () => (jsxRuntime.jsxs(reactComponents.MenuList, { className: "relative max-h-[55vh] w-72 overflow-y-auto pr-4", children: [jsxRuntime.jsxs("div", { className: "mb-2 flex items-center justify-between", children: [jsxRuntime.jsx(reactComponents.Text, { size: "small", subtle: true, children: t("table.columnFilters.title") }), jsxRuntime.jsx(reactComponents.Button, { className: "p-0", onClick: () => resetHiddenColumns(), size: "small", variant: "ghost-neutral", children: t("layout.actions.reset") })] }), jsxRuntime.jsx(ColumnFiltersDragAndDrop, { columns: sortedColumns, defaultColumnOrder: defaultColumnOrder, onUserEvent: onUserEvent, setColumnOrder: setColumnOrder })] })) })] }) }) }));
|
|
338
319
|
};
|
|
339
320
|
const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, defaultColumnOrder, }) => {
|
|
340
|
-
const [localColumns, setLocalColumns] =
|
|
341
|
-
|
|
321
|
+
const [localColumns, setLocalColumns] = react.useState(columns);
|
|
322
|
+
react.useEffect(() => {
|
|
342
323
|
setLocalColumns(columns);
|
|
343
324
|
}, [columns]);
|
|
344
|
-
const onColumDrop =
|
|
325
|
+
const onColumDrop = react.useCallback(() => {
|
|
345
326
|
const firstElement = defaultColumnOrder[0];
|
|
346
327
|
const firstLocalColumnId = localColumns[0]?.id;
|
|
347
328
|
const newColumnOrder = firstElement === firstLocalColumnId
|
|
@@ -349,10 +330,10 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, defaul
|
|
|
349
330
|
: [firstElement, ...localColumns.map(column => column.id)].filter((id) => id !== undefined);
|
|
350
331
|
setColumnOrder(newColumnOrder);
|
|
351
332
|
}, [localColumns, setColumnOrder, defaultColumnOrder]);
|
|
352
|
-
const onCancelColumDrop =
|
|
333
|
+
const onCancelColumDrop = react.useCallback(() => {
|
|
353
334
|
setLocalColumns(columns);
|
|
354
335
|
}, [columns]);
|
|
355
|
-
const moveColumn =
|
|
336
|
+
const moveColumn = react.useCallback((dragIndex, hoverIndex) => {
|
|
356
337
|
const dragColumn = localColumns[dragIndex];
|
|
357
338
|
if (dragColumn) {
|
|
358
339
|
setLocalColumns(update(localColumns, {
|
|
@@ -385,7 +366,7 @@ const ItemTypes = {
|
|
|
385
366
|
COLUMN: "column",
|
|
386
367
|
};
|
|
387
368
|
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, onDrop, onCancelDrop, id, }) => {
|
|
388
|
-
const ref =
|
|
369
|
+
const ref = react.useRef(null);
|
|
389
370
|
const [, drop] = reactDnd.useDrop({
|
|
390
371
|
accept: ItemTypes.COLUMN,
|
|
391
372
|
hover(item, monitor) {
|
|
@@ -493,10 +474,9 @@ const Sorting = ({ columns, }) => {
|
|
|
493
474
|
* @param {ReactTable} props - The props for the Table component
|
|
494
475
|
* @returns {JSX.Element} Table component
|
|
495
476
|
*/
|
|
496
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
497
477
|
const Table = ({ rowHeight = 75, ...props }) => {
|
|
498
478
|
//we need a reference to the scrolling element for logic down below
|
|
499
|
-
const tableContainerRef =
|
|
479
|
+
const tableContainerRef = react.useRef(null);
|
|
500
480
|
const [t] = useTranslation();
|
|
501
481
|
const { fetchMoreOnBottomReached, getVirtualItems, getTotalSize } = reactTablePagination.useInfiniteScroll({
|
|
502
482
|
pagination: props.pagination || reactTablePagination.noPagination,
|
|
@@ -581,7 +561,7 @@ const cvaTBody = cssClassVarianceUtilities.cvaMerge(["min-h-[40dvh]"], {
|
|
|
581
561
|
* Creates and returns a memoized instance of a columnHelper
|
|
582
562
|
*/
|
|
583
563
|
const useColumnHelper = () => {
|
|
584
|
-
return
|
|
564
|
+
return react.useMemo(() => {
|
|
585
565
|
return reactTable.createColumnHelper();
|
|
586
566
|
}, []);
|
|
587
567
|
};
|
|
@@ -594,10 +574,10 @@ const useColumnHelper = () => {
|
|
|
594
574
|
* @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
|
|
595
575
|
*/
|
|
596
576
|
const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
|
|
597
|
-
const updatedInitialColumnVisibility =
|
|
577
|
+
const updatedInitialColumnVisibility = react.useMemo(() => {
|
|
598
578
|
const initialStateColumnVisibility = initialState?.columnVisibility;
|
|
599
579
|
const resultFromInitialState = initialStateColumnVisibility
|
|
600
|
-
?
|
|
580
|
+
?
|
|
601
581
|
Object.fromEntries(columns
|
|
602
582
|
.map(column => {
|
|
603
583
|
if (column.id && initialStateColumnVisibility[column.id]) {
|
|
@@ -614,7 +594,7 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
614
594
|
});
|
|
615
595
|
return resultFromInitialState;
|
|
616
596
|
}, [columns, initialState?.columnVisibility]);
|
|
617
|
-
const updatedInitialColumnOrder =
|
|
597
|
+
const updatedInitialColumnOrder = react.useMemo(() => {
|
|
618
598
|
const resultFromInitialState = initialState?.columnOrder || [];
|
|
619
599
|
columns.forEach(column => {
|
|
620
600
|
if (column.id && !resultFromInitialState.includes(column.id)) {
|
|
@@ -623,11 +603,11 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
623
603
|
});
|
|
624
604
|
return resultFromInitialState;
|
|
625
605
|
}, [columns, initialState?.columnOrder]);
|
|
626
|
-
const [columnVisibility, setColumnVisibility] =
|
|
627
|
-
const [columnOrder, setColumnOrder] =
|
|
628
|
-
const [sorting, setSorting] =
|
|
629
|
-
const [columnSizing, setColumnSizing] =
|
|
630
|
-
|
|
606
|
+
const [columnVisibility, setColumnVisibility] = react.useState(reactTableProps.state?.columnVisibility || updatedInitialColumnVisibility || {});
|
|
607
|
+
const [columnOrder, setColumnOrder] = react.useState(reactTableProps.state?.columnOrder || updatedInitialColumnOrder);
|
|
608
|
+
const [sorting, setSorting] = react.useState(reactTableProps.state?.sorting || initialState?.sorting || []);
|
|
609
|
+
const [columnSizing, setColumnSizing] = react.useState(reactTableProps.state?.columnSizing || initialState?.columnSizing || {});
|
|
610
|
+
react.useEffect(() => {
|
|
631
611
|
if (initialState && sharedUtils.objectKeys(initialState).length > 0) {
|
|
632
612
|
setColumnVisibility(updatedInitialColumnVisibility);
|
|
633
613
|
setColumnOrder(updatedInitialColumnOrder);
|
|
@@ -635,7 +615,7 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
635
615
|
setColumnSizing(initialState.columnSizing || {});
|
|
636
616
|
}
|
|
637
617
|
}, [initialState, updatedInitialColumnOrder, updatedInitialColumnVisibility]);
|
|
638
|
-
const state =
|
|
618
|
+
const state = react.useMemo(() => {
|
|
639
619
|
return {
|
|
640
620
|
sorting,
|
|
641
621
|
columnVisibility,
|
|
@@ -670,12 +650,12 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
670
650
|
columns,
|
|
671
651
|
state,
|
|
672
652
|
});
|
|
673
|
-
|
|
653
|
+
react.useEffect(() => {
|
|
674
654
|
if (onTableStateChange) {
|
|
675
655
|
onTableStateChange(state);
|
|
676
656
|
}
|
|
677
657
|
}, [onTableStateChange, state]);
|
|
678
|
-
return
|
|
658
|
+
return react.useMemo(() => {
|
|
679
659
|
return { table };
|
|
680
660
|
}, [table]);
|
|
681
661
|
};
|
|
@@ -709,15 +689,15 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
709
689
|
*/
|
|
710
690
|
const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
|
|
711
691
|
const [t] = useTranslation();
|
|
712
|
-
const [rowSelection, setRowSelection] =
|
|
713
|
-
|
|
692
|
+
const [rowSelection, setRowSelection] = react.useState({});
|
|
693
|
+
react.useEffect(() => {
|
|
714
694
|
const initialSelection = {};
|
|
715
695
|
defaultSelectedIds?.forEach(id => {
|
|
716
696
|
initialSelection[id] = true;
|
|
717
697
|
});
|
|
718
698
|
setRowSelection(() => ({ ...initialSelection }));
|
|
719
699
|
}, [defaultSelectedIds]);
|
|
720
|
-
const toggleRowSelectionState =
|
|
700
|
+
const toggleRowSelectionState = react.useCallback((id) => {
|
|
721
701
|
setRowSelection(prevRowSelection => {
|
|
722
702
|
const newSelection = { ...prevRowSelection, [id]: !prevRowSelection[id] };
|
|
723
703
|
const entries = sharedUtils.objectEntries(newSelection);
|
|
@@ -727,17 +707,18 @@ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true
|
|
|
727
707
|
return newSelection;
|
|
728
708
|
});
|
|
729
709
|
}, []);
|
|
730
|
-
const selectedIds =
|
|
710
|
+
const selectedIds = react.useMemo(() => sharedUtils.objectEntries(rowSelection)
|
|
731
711
|
.filter(([_, selected]) => selected)
|
|
732
712
|
.map(([id]) => id), [rowSelection]);
|
|
733
|
-
const columnHelper =
|
|
734
|
-
const selectionColumn =
|
|
713
|
+
const columnHelper = react.useMemo(() => reactTable.createColumnHelper(), []);
|
|
714
|
+
const selectionColumn = react.useMemo(() => columnHelper.accessor(row => row.id, {
|
|
735
715
|
cell: ({ row }) => (jsxRuntime.jsx(reactFormComponents.Checkbox, { className: "ml-1 p-1", // Aligns the checkbox with the one in the header.
|
|
736
716
|
checked: row.getIsSelected(),
|
|
737
717
|
disabled: !row.getCanSelect(),
|
|
738
718
|
indeterminate: row.getIsSomeSelected(),
|
|
739
719
|
onChange: row.getToggleSelectedHandler(),
|
|
740
|
-
stopPropagation: true
|
|
720
|
+
stopPropagation: true,
|
|
721
|
+
"aria-label": "rowSelector" })),
|
|
741
722
|
header: ({ table }) => (jsxRuntime.jsx(reactFormComponents.Checkbox, { className: "p-1",
|
|
742
723
|
checked: table.getIsAllRowsSelected(),
|
|
743
724
|
indeterminate: table.getIsSomeRowsSelected(),
|
|
@@ -753,15 +734,15 @@ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true
|
|
|
753
734
|
columnFilterLabel: t("table.selection.label"),
|
|
754
735
|
},
|
|
755
736
|
}), [columnHelper, data.length, t]);
|
|
756
|
-
const selectionTableState =
|
|
737
|
+
const selectionTableState = react.useMemo(() => ({
|
|
757
738
|
rowSelection,
|
|
758
739
|
}), [rowSelection]);
|
|
759
|
-
const selectionTableProps =
|
|
740
|
+
const selectionTableProps = react.useMemo(() => ({
|
|
760
741
|
onRowSelectionChange: setRowSelection,
|
|
761
742
|
getRowId: row => row.id,
|
|
762
743
|
enableRowSelection,
|
|
763
744
|
}), [enableRowSelection]);
|
|
764
|
-
return
|
|
745
|
+
return react.useMemo(() => ({
|
|
765
746
|
toggleRowSelectionState,
|
|
766
747
|
selectionColumn,
|
|
767
748
|
selectedIds,
|
package/index.esm.js
CHANGED
|
@@ -2,8 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { MenuItem, Icon, Button, useOverflowItems, MoreMenu, MenuList, Spacer, Tooltip, Popover, PopoverTrigger, PopoverContent, Text, Card, cvaInteractableItem, Spinner, EmptyState } from '@trackunit/react-components';
|
|
4
4
|
import { objectValues, nonNullable, objectKeys, objectEntries } from '@trackunit/shared-utils';
|
|
5
|
-
import
|
|
6
|
-
import { useMemo, Children, cloneElement, useEffect, useRef, useState, useCallback } from 'react';
|
|
5
|
+
import { useMemo, Children, cloneElement, useEffect, useCallback, useState, useRef } from 'react';
|
|
7
6
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
8
7
|
import { Link } from '@tanstack/react-router';
|
|
9
8
|
import { Toggle, RadioGroup, RadioItem, Checkbox } from '@trackunit/react-form-components';
|
|
@@ -296,7 +295,7 @@ const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder = [], column
|
|
|
296
295
|
}
|
|
297
296
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
298
297
|
}, []); //This should only run once, at page load
|
|
299
|
-
const resetHiddenColumns =
|
|
298
|
+
const resetHiddenColumns = useCallback(() => {
|
|
300
299
|
columns.forEach(column => column.toggleVisibility(!column.columnDef.meta?.hiddenByDefault));
|
|
301
300
|
setColumnOrder(defaultColumnOrder);
|
|
302
301
|
}, [columns, defaultColumnOrder, setColumnOrder]);
|
|
@@ -318,11 +317,11 @@ const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder = [], column
|
|
|
318
317
|
return (jsx(DndProvider, { backend: HTML5Backend, children: jsx(Tooltip, { label: t("table.columnFilters.tooltip"), placement: "bottom", children: jsxs(Popover, { placement: "bottom-start", children: [jsx(PopoverTrigger, { children: jsx(Button, { prefix: jsx(Icon, { name: "ViewColumns", size: "small" }), size: "small", variant: "ghost-neutral", children: jsx("span", { className: "hidden sm:block", children: getColumnButtonText() }) }) }), jsx(PopoverContent, { children: () => (jsxs(MenuList, { className: "relative max-h-[55vh] w-72 overflow-y-auto pr-4", children: [jsxs("div", { className: "mb-2 flex items-center justify-between", children: [jsx(Text, { size: "small", subtle: true, children: t("table.columnFilters.title") }), jsx(Button, { className: "p-0", onClick: () => resetHiddenColumns(), size: "small", variant: "ghost-neutral", children: t("layout.actions.reset") })] }), jsx(ColumnFiltersDragAndDrop, { columns: sortedColumns, defaultColumnOrder: defaultColumnOrder, onUserEvent: onUserEvent, setColumnOrder: setColumnOrder })] })) })] }) }) }));
|
|
319
318
|
};
|
|
320
319
|
const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, defaultColumnOrder, }) => {
|
|
321
|
-
const [localColumns, setLocalColumns] =
|
|
322
|
-
|
|
320
|
+
const [localColumns, setLocalColumns] = useState(columns);
|
|
321
|
+
useEffect(() => {
|
|
323
322
|
setLocalColumns(columns);
|
|
324
323
|
}, [columns]);
|
|
325
|
-
const onColumDrop =
|
|
324
|
+
const onColumDrop = useCallback(() => {
|
|
326
325
|
const firstElement = defaultColumnOrder[0];
|
|
327
326
|
const firstLocalColumnId = localColumns[0]?.id;
|
|
328
327
|
const newColumnOrder = firstElement === firstLocalColumnId
|
|
@@ -330,10 +329,10 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, defaul
|
|
|
330
329
|
: [firstElement, ...localColumns.map(column => column.id)].filter((id) => id !== undefined);
|
|
331
330
|
setColumnOrder(newColumnOrder);
|
|
332
331
|
}, [localColumns, setColumnOrder, defaultColumnOrder]);
|
|
333
|
-
const onCancelColumDrop =
|
|
332
|
+
const onCancelColumDrop = useCallback(() => {
|
|
334
333
|
setLocalColumns(columns);
|
|
335
334
|
}, [columns]);
|
|
336
|
-
const moveColumn =
|
|
335
|
+
const moveColumn = useCallback((dragIndex, hoverIndex) => {
|
|
337
336
|
const dragColumn = localColumns[dragIndex];
|
|
338
337
|
if (dragColumn) {
|
|
339
338
|
setLocalColumns(update(localColumns, {
|
|
@@ -366,7 +365,7 @@ const ItemTypes = {
|
|
|
366
365
|
COLUMN: "column",
|
|
367
366
|
};
|
|
368
367
|
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, onDrop, onCancelDrop, id, }) => {
|
|
369
|
-
const ref =
|
|
368
|
+
const ref = useRef(null);
|
|
370
369
|
const [, drop] = useDrop({
|
|
371
370
|
accept: ItemTypes.COLUMN,
|
|
372
371
|
hover(item, monitor) {
|
|
@@ -474,7 +473,6 @@ const Sorting = ({ columns, }) => {
|
|
|
474
473
|
* @param {ReactTable} props - The props for the Table component
|
|
475
474
|
* @returns {JSX.Element} Table component
|
|
476
475
|
*/
|
|
477
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
478
476
|
const Table = ({ rowHeight = 75, ...props }) => {
|
|
479
477
|
//we need a reference to the scrolling element for logic down below
|
|
480
478
|
const tableContainerRef = useRef(null);
|
|
@@ -578,7 +576,7 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
578
576
|
const updatedInitialColumnVisibility = useMemo(() => {
|
|
579
577
|
const initialStateColumnVisibility = initialState?.columnVisibility;
|
|
580
578
|
const resultFromInitialState = initialStateColumnVisibility
|
|
581
|
-
?
|
|
579
|
+
?
|
|
582
580
|
Object.fromEntries(columns
|
|
583
581
|
.map(column => {
|
|
584
582
|
if (column.id && initialStateColumnVisibility[column.id]) {
|
|
@@ -718,7 +716,8 @@ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true
|
|
|
718
716
|
disabled: !row.getCanSelect(),
|
|
719
717
|
indeterminate: row.getIsSomeSelected(),
|
|
720
718
|
onChange: row.getToggleSelectedHandler(),
|
|
721
|
-
stopPropagation: true
|
|
719
|
+
stopPropagation: true,
|
|
720
|
+
"aria-label": "rowSelector" })),
|
|
722
721
|
header: ({ table }) => (jsx(Checkbox, { className: "p-1",
|
|
723
722
|
checked: table.getIsAllRowsSelected(),
|
|
724
723
|
indeterminate: table.getIsSomeRowsSelected(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"jest-fetch-mock": "^3.0.3",
|
|
16
16
|
"@tanstack/react-router": "1.47.1",
|
|
17
17
|
"tailwind-merge": "^2.0.0",
|
|
18
|
-
"@trackunit/react-components": "
|
|
19
|
-
"@trackunit/shared-utils": "
|
|
20
|
-
"@trackunit/css-class-variance-utilities": "
|
|
21
|
-
"@trackunit/ui-icons": "
|
|
22
|
-
"@trackunit/react-table-base-components": "
|
|
23
|
-
"@trackunit/react-table-pagination": "
|
|
24
|
-
"@trackunit/react-form-components": "
|
|
25
|
-
"@trackunit/i18n-library-translation": "
|
|
26
|
-
"@trackunit/react-core-contexts-api": "
|
|
18
|
+
"@trackunit/react-components": "1.1.7",
|
|
19
|
+
"@trackunit/shared-utils": "1.2.1",
|
|
20
|
+
"@trackunit/css-class-variance-utilities": "1.0.4",
|
|
21
|
+
"@trackunit/ui-icons": "1.0.7",
|
|
22
|
+
"@trackunit/react-table-base-components": "1.0.25",
|
|
23
|
+
"@trackunit/react-table-pagination": "1.0.5",
|
|
24
|
+
"@trackunit/react-form-components": "1.0.25",
|
|
25
|
+
"@trackunit/i18n-library-translation": "1.0.13",
|
|
26
|
+
"@trackunit/react-core-contexts-api": "1.0.9"
|
|
27
27
|
},
|
|
28
28
|
"module": "./index.esm.js",
|
|
29
29
|
"main": "./index.cjs.js",
|