@trackunit/react-table 0.0.176 → 0.0.178
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/README.md +1 -1
- package/index.cjs.js +17 -4
- package/index.esm.js +17 -4
- package/package.json +1 -1
- package/src/useTableSelection.d.ts +5 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The `@trackunit/react-table` package is the home of our implementation of a Tabl
|
|
|
7
7
|
|
|
8
8
|
This library is exposed publicly for use in the the Trackunit [Iris App SDK](https://www.npmjs.com/package/@trackunit/iris-app).
|
|
9
9
|
|
|
10
|
-
To browse all available components visit our [Public Storybook](https://
|
|
10
|
+
To browse all available components visit our [Public Storybook](https://apps.iris.trackunit.com/storybook/).
|
|
11
11
|
|
|
12
12
|
For more info and a full guide on Iris App SDK Development, please visit our [Developer Hub](https://developers.trackunit.com/).
|
|
13
13
|
|
package/index.cjs.js
CHANGED
|
@@ -345,6 +345,7 @@ const Table = (_a) => {
|
|
|
345
345
|
rowHeight,
|
|
346
346
|
});
|
|
347
347
|
const hasResults = props.getRowModel().rows.length > 0;
|
|
348
|
+
console.log("onRowClick", props.onRowClick);
|
|
348
349
|
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
350
|
height: getTotalSize() > 0 ? getTotalSize() : "100%",
|
|
350
351
|
width: "100%",
|
|
@@ -366,7 +367,14 @@ const Table = (_a) => {
|
|
|
366
367
|
return (jsxRuntime.jsx(reactTableBaseComponents.Tr, { layout: "flex", style: {
|
|
367
368
|
height: `${virtualRow.size}px`,
|
|
368
369
|
transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
|
|
369
|
-
}, onClick: () =>
|
|
370
|
+
}, onClick: () => {
|
|
371
|
+
if (props.onRowClick) {
|
|
372
|
+
props.onRowClick(row);
|
|
373
|
+
}
|
|
374
|
+
else if (row.getCanSelect()) {
|
|
375
|
+
row.toggleSelected();
|
|
376
|
+
}
|
|
377
|
+
}, className: `${(props.onRowClick || row.getCanSelect()) && "cursor-pointer"} hover:bg-neutral-100`, dataTestId: `table-body-row-${virtualRow.index}`, children: row === null || row === void 0 ? void 0 : row.getVisibleCells().map(cell => {
|
|
370
378
|
return (jsxRuntime.jsx(reactTableBaseComponents.Td, { key: cell.id,
|
|
371
379
|
style: {
|
|
372
380
|
width: cell.column.getSize(),
|
|
@@ -715,6 +723,9 @@ const useTable = (_a) => {
|
|
|
715
723
|
*/
|
|
716
724
|
const useTableSelection = ({ data, }) => {
|
|
717
725
|
const [rowSelection, setRowSelection] = React.useState({});
|
|
726
|
+
const toggleRowSelectionState = React.useCallback((id) => {
|
|
727
|
+
setRowSelection(prevRowSelection => (Object.assign(Object.assign({}, prevRowSelection), { [id]: !prevRowSelection[id] })));
|
|
728
|
+
}, []);
|
|
718
729
|
const selectedIds = React.useMemo(() => Object.entries(rowSelection)
|
|
719
730
|
.filter(([_, selected]) => selected)
|
|
720
731
|
.map(([id]) => id), [rowSelection]);
|
|
@@ -724,7 +735,8 @@ const useTableSelection = ({ data, }) => {
|
|
|
724
735
|
checked: row.getIsSelected(),
|
|
725
736
|
disabled: !row.getCanSelect(),
|
|
726
737
|
indeterminate: row.getIsSomeSelected(),
|
|
727
|
-
onChange: row.getToggleSelectedHandler()
|
|
738
|
+
onChange: row.getToggleSelectedHandler(),
|
|
739
|
+
stopPropagation: true })),
|
|
728
740
|
header: ({ table }) => (jsxRuntime.jsx(reactFormComponents.Checkbox, { checked: table.getIsAllRowsSelected(),
|
|
729
741
|
indeterminate: table.getIsSomeRowsSelected(),
|
|
730
742
|
onChange: table.getToggleAllRowsSelectedHandler() })),
|
|
@@ -745,13 +757,14 @@ const useTableSelection = ({ data, }) => {
|
|
|
745
757
|
getRowId: row => row.id,
|
|
746
758
|
enableRowSelection: true,
|
|
747
759
|
}), []);
|
|
748
|
-
return {
|
|
760
|
+
return React.useMemo(() => ({
|
|
761
|
+
toggleRowSelectionState,
|
|
749
762
|
selectionColumn,
|
|
750
763
|
selectedIds,
|
|
751
764
|
selectionTableState,
|
|
752
765
|
selectionTableProps,
|
|
753
766
|
setRowSelection,
|
|
754
|
-
};
|
|
767
|
+
}), [selectedIds, selectionColumn, selectionTableProps, selectionTableState, toggleRowSelectionState]);
|
|
755
768
|
};
|
|
756
769
|
|
|
757
770
|
//TODO: find a more appropriate place for this file
|
package/index.esm.js
CHANGED
|
@@ -320,6 +320,7 @@ const Table = (_a) => {
|
|
|
320
320
|
rowHeight,
|
|
321
321
|
});
|
|
322
322
|
const hasResults = props.getRowModel().rows.length > 0;
|
|
323
|
+
console.log("onRowClick", props.onRowClick);
|
|
323
324
|
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
325
|
height: getTotalSize() > 0 ? getTotalSize() : "100%",
|
|
325
326
|
width: "100%",
|
|
@@ -341,7 +342,14 @@ const Table = (_a) => {
|
|
|
341
342
|
return (jsx(Tr, { layout: "flex", style: {
|
|
342
343
|
height: `${virtualRow.size}px`,
|
|
343
344
|
transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
|
|
344
|
-
}, onClick: () =>
|
|
345
|
+
}, onClick: () => {
|
|
346
|
+
if (props.onRowClick) {
|
|
347
|
+
props.onRowClick(row);
|
|
348
|
+
}
|
|
349
|
+
else if (row.getCanSelect()) {
|
|
350
|
+
row.toggleSelected();
|
|
351
|
+
}
|
|
352
|
+
}, className: `${(props.onRowClick || row.getCanSelect()) && "cursor-pointer"} hover:bg-neutral-100`, dataTestId: `table-body-row-${virtualRow.index}`, children: row === null || row === void 0 ? void 0 : row.getVisibleCells().map(cell => {
|
|
345
353
|
return (jsx(Td, { key: cell.id,
|
|
346
354
|
style: {
|
|
347
355
|
width: cell.column.getSize(),
|
|
@@ -690,6 +698,9 @@ const useTable = (_a) => {
|
|
|
690
698
|
*/
|
|
691
699
|
const useTableSelection = ({ data, }) => {
|
|
692
700
|
const [rowSelection, setRowSelection] = useState({});
|
|
701
|
+
const toggleRowSelectionState = useCallback((id) => {
|
|
702
|
+
setRowSelection(prevRowSelection => (Object.assign(Object.assign({}, prevRowSelection), { [id]: !prevRowSelection[id] })));
|
|
703
|
+
}, []);
|
|
693
704
|
const selectedIds = useMemo(() => Object.entries(rowSelection)
|
|
694
705
|
.filter(([_, selected]) => selected)
|
|
695
706
|
.map(([id]) => id), [rowSelection]);
|
|
@@ -699,7 +710,8 @@ const useTableSelection = ({ data, }) => {
|
|
|
699
710
|
checked: row.getIsSelected(),
|
|
700
711
|
disabled: !row.getCanSelect(),
|
|
701
712
|
indeterminate: row.getIsSomeSelected(),
|
|
702
|
-
onChange: row.getToggleSelectedHandler()
|
|
713
|
+
onChange: row.getToggleSelectedHandler(),
|
|
714
|
+
stopPropagation: true })),
|
|
703
715
|
header: ({ table }) => (jsx(Checkbox, { checked: table.getIsAllRowsSelected(),
|
|
704
716
|
indeterminate: table.getIsSomeRowsSelected(),
|
|
705
717
|
onChange: table.getToggleAllRowsSelectedHandler() })),
|
|
@@ -720,13 +732,14 @@ const useTableSelection = ({ data, }) => {
|
|
|
720
732
|
getRowId: row => row.id,
|
|
721
733
|
enableRowSelection: true,
|
|
722
734
|
}), []);
|
|
723
|
-
return {
|
|
735
|
+
return useMemo(() => ({
|
|
736
|
+
toggleRowSelectionState,
|
|
724
737
|
selectionColumn,
|
|
725
738
|
selectedIds,
|
|
726
739
|
selectionTableState,
|
|
727
740
|
selectionTableProps,
|
|
728
741
|
setRowSelection,
|
|
729
|
-
};
|
|
742
|
+
}), [selectedIds, selectionColumn, selectionTableProps, selectionTableState, toggleRowSelectionState]);
|
|
730
743
|
};
|
|
731
744
|
|
|
732
745
|
//TODO: find a more appropriate place for this file
|
package/package.json
CHANGED
|
@@ -32,6 +32,11 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
|
|
|
32
32
|
* A `ColumnDef` object for the selection column, which includes a checkbox in each cell and header.
|
|
33
33
|
*/
|
|
34
34
|
selectionColumn: ColumnDef<TData, string>;
|
|
35
|
+
/**
|
|
36
|
+
* A function to toggle the selection state of a single row.
|
|
37
|
+
* This is usefull for example when you want to select a row when clicking on it, instead of the checkbox.
|
|
38
|
+
*/
|
|
39
|
+
toggleRowSelectionState: (id: TData["id"]) => void;
|
|
35
40
|
}
|
|
36
41
|
export interface TableSelectionProps<TData extends selectableTableData> {
|
|
37
42
|
data: TData[];
|