@bsol-oss/react-datatable5 1.0.63 → 2.0.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/dist/index.d.ts +145 -101
- package/dist/index.js +257 -271
- package/dist/index.mjs +192 -206
- package/dist/types/components/Controls/SelectAllRowsToggle.d.ts +4 -4
- package/dist/types/components/DataTable/DataTable.d.ts +18 -13
- package/dist/types/components/DataTable/DataTableContext.d.ts +4 -3
- package/dist/types/components/DataTable/DataTableServer.d.ts +18 -14
- package/dist/types/components/DataTable/useDataTable.d.ts +33 -7
- package/dist/types/components/DataTable/useDataTableContext.d.ts +8 -0
- package/dist/types/index.d.ts +41 -7
- package/package.json +1 -1
- package/dist/types/components/DataTable.d.ts +0 -33
- package/dist/types/components/DataTableContext.d.ts +0 -10
- package/dist/types/components/DataTableServer.d.ts +0 -38
- package/dist/types/components/DefaultTable.d.ts +0 -5
- package/dist/types/components/DensityFeature.d.ts +0 -23
- package/dist/types/components/DensityToggle.d.ts +0 -1
- package/dist/types/components/DensityToggleButton.d.ts +0 -6
- package/dist/types/components/EditFilterButton.d.ts +0 -9
- package/dist/types/components/EditOrderButton.d.ts +0 -7
- package/dist/types/components/EditSortingButton.d.ts +0 -7
- package/dist/types/components/EditViewButton.d.ts +0 -7
- package/dist/types/components/FilterOptions.d.ts +0 -4
- package/dist/types/components/GlobalFilter.d.ts +0 -3
- package/dist/types/components/PageSizeControl.d.ts +0 -4
- package/dist/types/components/ResetFilteringButton.d.ts +0 -4
- package/dist/types/components/ResetSelectionButton.d.ts +0 -4
- package/dist/types/components/ResetSortingButton.d.ts +0 -4
- package/dist/types/components/RowCountText.d.ts +0 -1
- package/dist/types/components/SelectAllRowsToggle.d.ts +0 -8
- package/dist/types/components/Table.d.ts +0 -8
- package/dist/types/components/TableBody.d.ts +0 -17
- package/dist/types/components/TableCardContainer.d.ts +0 -6
- package/dist/types/components/TableCards.d.ts +0 -4
- package/dist/types/components/TableComponent.d.ts +0 -6
- package/dist/types/components/TableComponentRenderer.d.ts +0 -6
- package/dist/types/components/TableControls.d.ts +0 -13
- package/dist/types/components/TableFilter.d.ts +0 -8
- package/dist/types/components/TableFilterTags.d.ts +0 -1
- package/dist/types/components/TableFooter.d.ts +0 -7
- package/dist/types/components/TableHeader.d.ts +0 -8
- package/dist/types/components/TableLoadingComponent.d.ts +0 -5
- package/dist/types/components/TableOrderer.d.ts +0 -1
- package/dist/types/components/TablePagination.d.ts +0 -3
- package/dist/types/components/TableReloadButton.d.ts +0 -4
- package/dist/types/components/TableSelector.d.ts +0 -1
- package/dist/types/components/TableSorter.d.ts +0 -1
- package/dist/types/components/TableViewer.d.ts +0 -1
- package/dist/types/components/TextCell.d.ts +0 -10
- package/dist/types/components/useDataFromUrl.d.ts +0 -14
- package/dist/types/components/useDataTable.d.ts +0 -7
package/dist/index.js
CHANGED
|
@@ -1,29 +1,119 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('@chakra-ui/react');
|
|
5
|
+
var ai = require('react-icons/ai');
|
|
6
|
+
var md = require('react-icons/md');
|
|
7
|
+
var icons = require('@chakra-ui/icons');
|
|
8
|
+
var react$1 = require('react');
|
|
9
|
+
var io = require('react-icons/io');
|
|
4
10
|
var reactTable = require('@tanstack/react-table');
|
|
5
|
-
var react = require('react');
|
|
6
11
|
var matchSorterUtils = require('@tanstack/match-sorter-utils');
|
|
7
12
|
var axios = require('axios');
|
|
8
|
-
var react$1 = require('@chakra-ui/react');
|
|
9
13
|
var table = require('@chakra-ui/table');
|
|
10
|
-
var
|
|
11
|
-
var icons = require('@chakra-ui/icons');
|
|
14
|
+
var bs = require('react-icons/bs');
|
|
12
15
|
var gr = require('react-icons/gr');
|
|
13
|
-
var ai = require('react-icons/ai');
|
|
14
|
-
var io = require('react-icons/io');
|
|
15
16
|
var io5 = require('react-icons/io5');
|
|
16
17
|
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
17
18
|
var fa = require('react-icons/fa');
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWidth, {}), }) => {
|
|
21
|
+
const { table } = useDataTableContext();
|
|
22
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Toggle Density", icon: icon, onClick: () => {
|
|
23
|
+
table.toggleDensity();
|
|
24
|
+
} })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", "aria-label": "Toggle Density", onClick: () => {
|
|
25
|
+
table.toggleDensity();
|
|
26
|
+
}, children: text }))] }));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsxRuntime.jsx(md.MdFilterAlt, {}), ...props }) => {
|
|
30
|
+
const filterModal = react.useDisclosure();
|
|
31
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxRuntime.jsxs(react.Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.ModalOverlay, {}), jsxRuntime.jsxs(react.ModalContent, { children: [jsxRuntime.jsx(react.ModalHeader, { children: title }), jsxRuntime.jsx(react.ModalCloseButton, {}), jsxRuntime.jsx(react.ModalBody, { children: jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "1rem", children: [jsxRuntime.jsx(TableFilter, {}), jsxRuntime.jsx(ResetFilteringButton, { text: resetText })] }) }), jsxRuntime.jsx(react.ModalFooter, { children: jsxRuntime.jsx(react.Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
35
|
+
const orderModal = react.useDisclosure();
|
|
36
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { icon: icon, variant: "ghost", onClick: orderModal.onOpen, "aria-label": "change order" })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", onClick: orderModal.onOpen, children: text })), jsxRuntime.jsxs(react.Modal, { isOpen: orderModal.isOpen, onClose: orderModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.ModalOverlay, {}), jsxRuntime.jsxs(react.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react.ModalHeader, { children: title }), jsxRuntime.jsx(react.ModalCloseButton, {}), jsxRuntime.jsx(react.ModalBody, { children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) })] })] })] }));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const TableContext = react$1.createContext({
|
|
20
40
|
table: {},
|
|
21
41
|
refreshData: () => { },
|
|
22
|
-
globalFilter: "",
|
|
42
|
+
globalFilter: { globalFilter: "" },
|
|
23
43
|
setGlobalFilter: () => { },
|
|
24
44
|
loading: false,
|
|
45
|
+
hasError: false,
|
|
25
46
|
});
|
|
26
47
|
|
|
48
|
+
const useDataTableContext = () => {
|
|
49
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } = react$1.useContext(TableContext);
|
|
50
|
+
return {
|
|
51
|
+
table,
|
|
52
|
+
refreshData,
|
|
53
|
+
globalFilter,
|
|
54
|
+
setGlobalFilter,
|
|
55
|
+
loading,
|
|
56
|
+
hasError,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const TableSorter = () => {
|
|
61
|
+
const { table } = useDataTableContext();
|
|
62
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
63
|
+
const displayName = header.column.columnDef.meta === undefined
|
|
64
|
+
? header.column.id
|
|
65
|
+
: header.column.columnDef.meta.displayName;
|
|
66
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: header.column.getCanSort() && (jsxRuntime.jsxs(react.Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: () => {
|
|
67
|
+
header.column.toggleSorting();
|
|
68
|
+
}, children: [header.column.getIsSorted() === false && jsxRuntime.jsx(icons.UpDownIcon, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {}))] }), header.column.getIsSorted() && (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
69
|
+
header.column.clearSorting();
|
|
70
|
+
}, children: jsxRuntime.jsx(icons.CloseIcon, {}) }))] })) }));
|
|
71
|
+
}) }))) }));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}), title = "Edit Sorting", }) => {
|
|
75
|
+
const sortingModal = react.useDisclosure();
|
|
76
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { icon: icon, variant: "ghost", onClick: sortingModal.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", onClick: sortingModal.onOpen, children: text })), jsxRuntime.jsxs(react.Modal, { isOpen: sortingModal.isOpen, onClose: sortingModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.ModalOverlay, {}), jsxRuntime.jsxs(react.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react.ModalHeader, { children: title }), jsxRuntime.jsx(react.ModalCloseButton, {}), jsxRuntime.jsx(react.ModalBody, { children: jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(TableSorter, {}), jsxRuntime.jsx(ResetSortingButton, {})] }) })] })] })] }));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
80
|
+
const viewModel = react.useDisclosure();
|
|
81
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxRuntime.jsxs(react.Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.ModalOverlay, {}), jsxRuntime.jsxs(react.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react.ModalHeader, { children: title }), jsxRuntime.jsx(react.ModalCloseButton, {}), jsxRuntime.jsx(react.ModalBody, { children: jsxRuntime.jsx(TableViewer, {}) })] })] })] }));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
85
|
+
const { table } = useDataTableContext();
|
|
86
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react.Menu, { children: [jsxRuntime.jsx(react.MenuButton, { as: react.Button, variant: "ghost", rightIcon: jsxRuntime.jsx(icons.ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsxRuntime.jsx(react.MenuList, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(react.MenuItem, { onClick: () => {
|
|
87
|
+
table.setPageSize(Number(pageSize));
|
|
88
|
+
}, children: pageSize }, crypto.randomUUID()))) })] }) }));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
92
|
+
const { table } = useDataTableContext();
|
|
93
|
+
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
94
|
+
table.resetColumnFilters();
|
|
95
|
+
}, children: text }));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const ResetSelectionButton = ({ text = "Reset Selection", }) => {
|
|
99
|
+
const { table } = useDataTableContext();
|
|
100
|
+
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
101
|
+
table.resetRowSelection();
|
|
102
|
+
}, children: text }));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const ResetSortingButton = ({ text = "Reset Sorting", }) => {
|
|
106
|
+
const { table } = useDataTableContext();
|
|
107
|
+
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
108
|
+
table.resetSorting();
|
|
109
|
+
}, children: text }));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const RowCountText = () => {
|
|
113
|
+
const { table } = useDataTableContext();
|
|
114
|
+
return jsxRuntime.jsx(react.Text, { children: table.getRowCount() });
|
|
115
|
+
};
|
|
116
|
+
|
|
27
117
|
// Reference: https://tanstack.com/table/latest/docs/framework/react/examples/custom-features
|
|
28
118
|
// TypeScript setup for our new feature with all of the same type-safety as stock TanStack Table features
|
|
29
119
|
// end of TS setup!
|
|
@@ -108,15 +198,7 @@ const fuzzyFilter = (row, columnId, value, addMeta) => {
|
|
|
108
198
|
// Return if the item should be filtered in/out
|
|
109
199
|
return itemRank.passed;
|
|
110
200
|
};
|
|
111
|
-
const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder
|
|
112
|
-
pageIndex: 0, //initial page index
|
|
113
|
-
pageSize: 10, //default page size
|
|
114
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, columnVisibility: defaultColumnVisibility = {}, children, }) => {
|
|
115
|
-
const [columnOrder, setColumnOrder] = react.useState(defaultColumnOrder);
|
|
116
|
-
const [globalFilter, setGlobalFilter] = react.useState(defaultGlobalFilter);
|
|
117
|
-
const [densityState, setDensity] = react.useState(density);
|
|
118
|
-
const [rowSelection, setRowSelection] = react.useState(defaultRowSelection);
|
|
119
|
-
const [columnVisibility, setColumnVisibility] = react.useState(defaultColumnVisibility);
|
|
201
|
+
const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }) => {
|
|
120
202
|
const table = reactTable.useReactTable({
|
|
121
203
|
_features: [DensityFeature],
|
|
122
204
|
data: data,
|
|
@@ -130,16 +212,6 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
130
212
|
minSize: 10, //enforced during column resizing
|
|
131
213
|
maxSize: 10000, //enforced during column resizing
|
|
132
214
|
},
|
|
133
|
-
state: {
|
|
134
|
-
columnOrder,
|
|
135
|
-
globalFilter,
|
|
136
|
-
density: densityState,
|
|
137
|
-
rowSelection,
|
|
138
|
-
columnVisibility,
|
|
139
|
-
},
|
|
140
|
-
onColumnOrderChange: (state) => {
|
|
141
|
-
setColumnOrder(state);
|
|
142
|
-
},
|
|
143
215
|
enableRowSelection: enableRowSelection,
|
|
144
216
|
enableMultiRowSelection: enableMultiRowSelection,
|
|
145
217
|
enableSubRowSelection: enableSubRowSelection,
|
|
@@ -148,22 +220,34 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
148
220
|
filterFns: {
|
|
149
221
|
fuzzy: fuzzyFilter,
|
|
150
222
|
},
|
|
151
|
-
onGlobalFilterChange: setGlobalFilter,
|
|
152
223
|
globalFilterFn: "fuzzy",
|
|
153
|
-
|
|
154
|
-
|
|
224
|
+
state: {
|
|
225
|
+
pagination,
|
|
226
|
+
sorting,
|
|
227
|
+
columnFilters,
|
|
228
|
+
rowSelection,
|
|
229
|
+
columnOrder,
|
|
230
|
+
globalFilter,
|
|
231
|
+
density,
|
|
232
|
+
columnVisibility,
|
|
233
|
+
},
|
|
234
|
+
onPaginationChange: setPagination,
|
|
235
|
+
onSortingChange: setSorting,
|
|
236
|
+
onColumnFiltersChange: setColumnFilters,
|
|
155
237
|
onRowSelectionChange: setRowSelection,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
238
|
+
onColumnOrderChange: (state) => {
|
|
239
|
+
setColumnOrder(state);
|
|
240
|
+
},
|
|
241
|
+
onGlobalFilterChange: (state) => {
|
|
242
|
+
setGlobalFilter(state);
|
|
161
243
|
},
|
|
244
|
+
onDensityChange: setDensity,
|
|
245
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
162
246
|
});
|
|
163
|
-
react.useEffect(() => {
|
|
247
|
+
react$1.useEffect(() => {
|
|
164
248
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
165
249
|
}, []);
|
|
166
|
-
react.useEffect(() => {
|
|
250
|
+
react$1.useEffect(() => {
|
|
167
251
|
onRowSelect(table.getState().rowSelection, data);
|
|
168
252
|
}, [table.getState().rowSelection]);
|
|
169
253
|
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
@@ -174,18 +258,20 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
174
258
|
globalFilter: globalFilter,
|
|
175
259
|
setGlobalFilter: setGlobalFilter,
|
|
176
260
|
loading: false,
|
|
261
|
+
hasError: false,
|
|
177
262
|
}, children: children }));
|
|
178
263
|
};
|
|
179
264
|
|
|
180
265
|
const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSuccess = () => { }, defaultData, }) => {
|
|
181
|
-
const [loading, setLoading] = react.useState(true);
|
|
182
|
-
const [hasError, setHasError] = react.useState(false);
|
|
183
|
-
const [data, setData] = react.useState(defaultData);
|
|
266
|
+
const [loading, setLoading] = react$1.useState(true);
|
|
267
|
+
const [hasError, setHasError] = react$1.useState(false);
|
|
268
|
+
const [data, setData] = react$1.useState(defaultData);
|
|
184
269
|
const refreshData = async () => {
|
|
185
270
|
await getData();
|
|
186
271
|
};
|
|
187
272
|
const getData = async () => {
|
|
188
273
|
try {
|
|
274
|
+
setHasError(false);
|
|
189
275
|
setLoading(true);
|
|
190
276
|
const { data } = await axios.get(url, { params: params });
|
|
191
277
|
console.debug("get DataFromUrl success", data);
|
|
@@ -199,7 +285,7 @@ const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSu
|
|
|
199
285
|
setHasError(true);
|
|
200
286
|
}
|
|
201
287
|
};
|
|
202
|
-
react.useEffect(() => {
|
|
288
|
+
react$1.useEffect(() => {
|
|
203
289
|
if (disableFirstFetch) {
|
|
204
290
|
return;
|
|
205
291
|
}
|
|
@@ -210,18 +296,7 @@ const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSu
|
|
|
210
296
|
return { data, loading, hasError, refreshData };
|
|
211
297
|
};
|
|
212
298
|
|
|
213
|
-
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder
|
|
214
|
-
pageIndex: 0, //initial page index
|
|
215
|
-
pageSize: 10, //default page size
|
|
216
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, columnVisibility: defaultColumnVisibility = {}, children, }) => {
|
|
217
|
-
const [sorting, setSorting] = react.useState(defaultSorting);
|
|
218
|
-
const [columnFilters, setColumnFilters] = react.useState(defaultColumnFilter); // can set initial column filter state here
|
|
219
|
-
const [pagination, setPagination] = react.useState(defaultPagination);
|
|
220
|
-
const [rowSelection, setRowSelection] = react.useState(defaultRowSelection);
|
|
221
|
-
const [columnOrder, setColumnOrder] = react.useState(defaultColumnOrder);
|
|
222
|
-
const [globalFilter, setGlobalFilter] = react.useState(defaultGlobalFilter);
|
|
223
|
-
const [densityState, setDensity] = react.useState(density);
|
|
224
|
-
const [columnVisibility, setColumnVisibility] = react.useState(defaultColumnVisibility);
|
|
299
|
+
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, children, }) => {
|
|
225
300
|
const { data, loading, hasError, refreshData } = useDataFromUrl({
|
|
226
301
|
url: url,
|
|
227
302
|
defaultData: {
|
|
@@ -243,7 +318,7 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
243
318
|
obj[filter.id] = filter.value;
|
|
244
319
|
return { ...accumulator, ...obj };
|
|
245
320
|
}, {})),
|
|
246
|
-
searching: globalFilter,
|
|
321
|
+
searching: globalFilter.globalFilter,
|
|
247
322
|
},
|
|
248
323
|
disableFirstFetch: true,
|
|
249
324
|
});
|
|
@@ -254,11 +329,15 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
254
329
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
255
330
|
manualPagination: true,
|
|
256
331
|
manualSorting: true,
|
|
257
|
-
onPaginationChange: setPagination,
|
|
258
|
-
onSortingChange: setSorting,
|
|
259
|
-
onColumnFiltersChange: setColumnFilters,
|
|
260
332
|
columnResizeMode: "onChange",
|
|
261
|
-
|
|
333
|
+
defaultColumn: {
|
|
334
|
+
size: 150, //starting column size
|
|
335
|
+
minSize: 10, //enforced during column resizing
|
|
336
|
+
maxSize: 10000, //enforced during column resizing
|
|
337
|
+
},
|
|
338
|
+
enableRowSelection: enableRowSelection,
|
|
339
|
+
enableMultiRowSelection: enableMultiRowSelection,
|
|
340
|
+
enableSubRowSelection: enableSubRowSelection,
|
|
262
341
|
state: {
|
|
263
342
|
pagination,
|
|
264
343
|
sorting,
|
|
@@ -266,23 +345,21 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
266
345
|
rowSelection,
|
|
267
346
|
columnOrder,
|
|
268
347
|
globalFilter,
|
|
269
|
-
density
|
|
348
|
+
density,
|
|
270
349
|
columnVisibility,
|
|
271
350
|
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
enableRowSelection: enableRowSelection,
|
|
278
|
-
enableMultiRowSelection: enableMultiRowSelection,
|
|
279
|
-
enableSubRowSelection: enableSubRowSelection,
|
|
351
|
+
onPaginationChange: setPagination,
|
|
352
|
+
onSortingChange: setSorting,
|
|
353
|
+
onColumnFiltersChange: setColumnFilters,
|
|
354
|
+
onRowSelectionChange: setRowSelection,
|
|
280
355
|
onColumnOrderChange: (state) => {
|
|
281
356
|
setColumnOrder(state);
|
|
282
357
|
},
|
|
283
358
|
onGlobalFilterChange: (state) => {
|
|
284
359
|
setGlobalFilter(state);
|
|
285
360
|
},
|
|
361
|
+
onDensityChange: setDensity,
|
|
362
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
286
363
|
rowCount: data.count,
|
|
287
364
|
// for tanstack-table ts bug start
|
|
288
365
|
filterFns: {
|
|
@@ -291,16 +368,14 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
291
368
|
},
|
|
292
369
|
},
|
|
293
370
|
// for tanstack-table ts bug end
|
|
294
|
-
onDensityChange: setDensity,
|
|
295
|
-
onColumnVisibilityChange: setColumnVisibility,
|
|
296
371
|
});
|
|
297
|
-
react.useEffect(() => {
|
|
372
|
+
react$1.useEffect(() => {
|
|
298
373
|
refreshData();
|
|
299
|
-
}, [pagination, sorting, columnFilters, globalFilter]);
|
|
300
|
-
react.useEffect(() => {
|
|
374
|
+
}, [pagination, sorting, columnFilters, globalFilter, url]);
|
|
375
|
+
react$1.useEffect(() => {
|
|
301
376
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
302
377
|
}, []);
|
|
303
|
-
react.useEffect(() => {
|
|
378
|
+
react$1.useEffect(() => {
|
|
304
379
|
onRowSelect(table.getState().rowSelection, data.results);
|
|
305
380
|
}, [table.getState().rowSelection]);
|
|
306
381
|
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
@@ -309,13 +384,14 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
309
384
|
globalFilter,
|
|
310
385
|
setGlobalFilter,
|
|
311
386
|
loading: loading,
|
|
387
|
+
hasError: hasError,
|
|
312
388
|
}, children: children }));
|
|
313
389
|
};
|
|
314
390
|
|
|
315
391
|
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
316
|
-
const { table: table$1 } = react.useContext(TableContext);
|
|
392
|
+
const { table: table$1 } = react$1.useContext(TableContext);
|
|
317
393
|
const SELECTION_BOX_WIDTH = 20;
|
|
318
|
-
const [hoveredRow, setHoveredRow] = react.useState(-1);
|
|
394
|
+
const [hoveredRow, setHoveredRow] = react$1.useState(-1);
|
|
319
395
|
const handleRowHover = (index) => {
|
|
320
396
|
setHoveredRow(index);
|
|
321
397
|
};
|
|
@@ -334,7 +410,7 @@ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, })
|
|
|
334
410
|
}) }));
|
|
335
411
|
};
|
|
336
412
|
const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
337
|
-
const { table: table$1 } = react.useContext(TableContext);
|
|
413
|
+
const { table: table$1 } = react$1.useContext(TableContext);
|
|
338
414
|
const SELECTION_BOX_WIDTH = 20;
|
|
339
415
|
const isCheckBoxVisible = (current_index, current_row) => {
|
|
340
416
|
if (current_row.getIsSelected()) {
|
|
@@ -355,27 +431,23 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
|
|
|
355
431
|
}
|
|
356
432
|
: {}),
|
|
357
433
|
// styling resize and pinning end
|
|
358
|
-
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react
|
|
434
|
+
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.FormLabel, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(react.Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
|
|
359
435
|
disabled: !row.getCanSelect(),
|
|
360
436
|
// indeterminate: row.getIsSomeSelected(),
|
|
361
437
|
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
362
438
|
};
|
|
363
439
|
|
|
364
440
|
const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showFilterName = false, showFilterTags = false, filterOptions = [], }) => {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const useDataTable = () => {
|
|
371
|
-
const { table, refreshData, globalFilter, setGlobalFilter, loading } = react.useContext(TableContext);
|
|
372
|
-
return { table, refreshData, globalFilter, setGlobalFilter, loading };
|
|
441
|
+
const { loading, hasError } = useDataTableContext();
|
|
442
|
+
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", justifySelf: "end", children: [loading && jsxRuntime.jsx(react.Spinner, { size: "sm" }), hasError && (jsxRuntime.jsx(react.Tooltip, { label: "An error occurred while fetching data", children: jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(react.Icon, { as: bs.BsExclamationCircleFill, color: "red.400" }) }) })), showFilter && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(GlobalFilter, {}), jsxRuntime.jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] }))] })] }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
|
|
443
|
+
return (jsxRuntime.jsxs(react.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react.Text, { children: [column, ":"] }), jsxRuntime.jsx(FilterOptions, { column: column })] }));
|
|
444
|
+
}) }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", children: showFilterTags && jsxRuntime.jsx(TableFilterTags, {}) }), jsxRuntime.jsx(react.Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: children }), jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", children: [jsxRuntime.jsx(PageSizeControl, {}), jsxRuntime.jsxs(react.Flex, { children: [jsxRuntime.jsx(react.Text, { paddingRight: "0.5rem", children: totalText }), jsxRuntime.jsx(RowCountText, {})] })] }), jsxRuntime.jsx(react.Box, { justifySelf: "end", children: jsxRuntime.jsx(TablePagination, {}) })] }));
|
|
373
445
|
};
|
|
374
446
|
|
|
375
447
|
const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
376
|
-
const table =
|
|
448
|
+
const table = useDataTableContext().table;
|
|
377
449
|
const SELECTION_BOX_WIDTH = 20;
|
|
378
|
-
const [hoveredCheckBox, setHoveredCheckBox] = react.useState(false);
|
|
450
|
+
const [hoveredCheckBox, setHoveredCheckBox] = react$1.useState(false);
|
|
379
451
|
const handleRowHover = (isHovered) => {
|
|
380
452
|
setHoveredCheckBox(isHovered);
|
|
381
453
|
};
|
|
@@ -388,7 +460,7 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }
|
|
|
388
460
|
}
|
|
389
461
|
return false;
|
|
390
462
|
};
|
|
391
|
-
return (jsxRuntime.jsx(react
|
|
463
|
+
return (jsxRuntime.jsx(react.Tfoot, { children: table.getFooterGroups().map((footerGroup) => (jsxRuntime.jsxs(react.Tr, { display: "flex", children: [jsxRuntime.jsxs(react.Th
|
|
392
464
|
// styling resize and pinning start
|
|
393
465
|
, {
|
|
394
466
|
// styling resize and pinning start
|
|
@@ -402,9 +474,9 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }
|
|
|
402
474
|
}
|
|
403
475
|
: {}),
|
|
404
476
|
// styling resize and pinning end
|
|
405
|
-
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react
|
|
477
|
+
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.FormLabel, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(react.Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
406
478
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
407
|
-
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react
|
|
479
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] }), footerGroup.headers.map((header) => (jsxRuntime.jsx(react.Th, { padding: "0", colSpan: header.colSpan,
|
|
408
480
|
// styling resize and pinning start
|
|
409
481
|
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, left: header.column.getIsPinned()
|
|
410
482
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
@@ -414,17 +486,17 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }
|
|
|
414
486
|
: undefined,
|
|
415
487
|
},
|
|
416
488
|
// styling resize and pinning end
|
|
417
|
-
display: "grid", children: jsxRuntime.jsx(react
|
|
489
|
+
display: "grid", children: jsxRuntime.jsx(react.Menu, { children: jsxRuntime.jsx(react.MenuButton, { as: react.Box, padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", _hover: { backgroundColor: "gray.100" }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
418
490
|
? null
|
|
419
|
-
: reactTable.flexRender(header.column.columnDef.footer, header.getContext()), jsxRuntime.jsx(react
|
|
491
|
+
: reactTable.flexRender(header.column.columnDef.footer, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && (
|
|
420
492
|
// <UpDownIcon />
|
|
421
493
|
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) })] }) }) }) }, crypto.randomUUID())))] }, crypto.randomUUID()))) }));
|
|
422
494
|
};
|
|
423
495
|
|
|
424
496
|
const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
425
|
-
const { table } =
|
|
497
|
+
const { table } = useDataTableContext();
|
|
426
498
|
const SELECTION_BOX_WIDTH = 20;
|
|
427
|
-
const [hoveredCheckBox, setHoveredCheckBox] = react.useState(false);
|
|
499
|
+
const [hoveredCheckBox, setHoveredCheckBox] = react$1.useState(false);
|
|
428
500
|
const handleRowHover = (isHovered) => {
|
|
429
501
|
setHoveredCheckBox(isHovered);
|
|
430
502
|
};
|
|
@@ -437,7 +509,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
437
509
|
}
|
|
438
510
|
return false;
|
|
439
511
|
};
|
|
440
|
-
return (jsxRuntime.jsx(react
|
|
512
|
+
return (jsxRuntime.jsx(react.Thead, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsxs(react.Tr, { display: "flex", children: [jsxRuntime.jsxs(react.Th
|
|
441
513
|
// styling resize and pinning start
|
|
442
514
|
, { ...(table.getIsSomeColumnsPinned("left")
|
|
443
515
|
? {
|
|
@@ -449,16 +521,16 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
449
521
|
}
|
|
450
522
|
: {}),
|
|
451
523
|
// styling resize and pinning end
|
|
452
|
-
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react
|
|
524
|
+
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.FormLabel, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(react.Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
453
525
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
454
|
-
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react
|
|
526
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] }), headerGroup.headers.map((header) => {
|
|
455
527
|
const resizeProps = {
|
|
456
528
|
onClick: () => header.column.resetSize(),
|
|
457
529
|
onMouseDown: header.getResizeHandler(),
|
|
458
530
|
onTouchStart: header.getResizeHandler(),
|
|
459
531
|
cursor: "col-resize",
|
|
460
532
|
};
|
|
461
|
-
return (jsxRuntime.jsxs(react
|
|
533
|
+
return (jsxRuntime.jsxs(react.Th, { padding: "0rem", colSpan: header.colSpan,
|
|
462
534
|
// styling resize and pinning start
|
|
463
535
|
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, left: header.column.getIsPinned()
|
|
464
536
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
@@ -468,13 +540,13 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
468
540
|
: undefined,
|
|
469
541
|
},
|
|
470
542
|
// styling resize and pinning end
|
|
471
|
-
display: "grid", children: [jsxRuntime.jsxs(react
|
|
543
|
+
display: "grid", children: [jsxRuntime.jsxs(react.Menu, { children: [jsxRuntime.jsx(react.MenuButton, { as: react.Box, padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", _hover: { backgroundColor: "gray.100" }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
472
544
|
? null
|
|
473
|
-
: reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react
|
|
545
|
+
: reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && jsxRuntime.jsx(jsxRuntime.Fragment, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) }), jsxRuntime.jsx(react.Box, { children: header.column.getIsFiltered() && jsxRuntime.jsx(md.MdFilterListAlt, {}) })] }) }), jsxRuntime.jsx(react.Portal, { children: jsxRuntime.jsxs(react.MenuList, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(react.MenuItem, { icon: jsxRuntime.jsx(md.MdPushPin, {}), onClick: () => {
|
|
474
546
|
header.column.pin("left");
|
|
475
|
-
}, children: "Pin Column" })), header.column.getIsPinned() && (jsxRuntime.jsx(react
|
|
547
|
+
}, children: "Pin Column" })), header.column.getIsPinned() && (jsxRuntime.jsx(react.MenuItem, { icon: jsxRuntime.jsx(md.MdCancel, {}), onClick: () => {
|
|
476
548
|
header.column.pin(false);
|
|
477
|
-
}, children: "Cancel Pin" })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react
|
|
549
|
+
}, children: "Cancel Pin" })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.MenuItem, { icon: jsxRuntime.jsx(gr.GrAscend, {}), onClick: () => {
|
|
478
550
|
table.setSorting((state) => {
|
|
479
551
|
return [
|
|
480
552
|
...state.filter((column) => {
|
|
@@ -483,7 +555,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
483
555
|
{ id: header.id, desc: false },
|
|
484
556
|
];
|
|
485
557
|
});
|
|
486
|
-
}, children: "Sort Ascending" }), jsxRuntime.jsx(react
|
|
558
|
+
}, children: "Sort Ascending" }), jsxRuntime.jsx(react.MenuItem, { icon: jsxRuntime.jsx(gr.GrDescend, {}), onClick: () => {
|
|
487
559
|
table.setSorting((state) => {
|
|
488
560
|
return [
|
|
489
561
|
...state.filter((column) => {
|
|
@@ -492,9 +564,9 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
492
564
|
{ id: header.id, desc: true },
|
|
493
565
|
];
|
|
494
566
|
});
|
|
495
|
-
}, children: "Sort Descending" }), header.column.getIsSorted() && (jsxRuntime.jsx(react
|
|
567
|
+
}, children: "Sort Descending" }), header.column.getIsSorted() && (jsxRuntime.jsx(react.MenuItem, { icon: jsxRuntime.jsx(md.MdClear, {}), onClick: () => {
|
|
496
568
|
header.column.clearSorting();
|
|
497
|
-
}, children: "Clear Sorting" }))] }))] }) })] }), canResize && (jsxRuntime.jsx(react
|
|
569
|
+
}, children: "Clear Sorting" }))] }))] }) })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing() ? "gray.700" : "transparent", position: "absolute", right: "0", top: "0", height: "100%", width: "5px", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
498
570
|
borderRightColor: header.column.getIsResizing()
|
|
499
571
|
? "gray.700"
|
|
500
572
|
: "gray.400",
|
|
@@ -506,135 +578,26 @@ const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = f
|
|
|
506
578
|
return (jsxRuntime.jsx(TableControls, { totalText: totalText, showFilter: showFilter, fitTableWidth: fitTableWidth, fitTableHeight: fitTableHeight, isMobile: isMobile, filterOptions: filterOptions, showFilterName: showFilterName, showFilterTags: showFilterTags, children: jsxRuntime.jsxs(Table, { variant: "striped", children: [jsxRuntime.jsx(TableHeader, { canResize: true }), jsxRuntime.jsx(TableBody, {}), showFooter && jsxRuntime.jsx(TableFooter, {})] }) }));
|
|
507
579
|
};
|
|
508
580
|
|
|
509
|
-
const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWidth, {}), }) => {
|
|
510
|
-
const { table } = useDataTable();
|
|
511
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { variant: "ghost", "aria-label": "Toggle Density", icon: icon, onClick: () => {
|
|
512
|
-
table.toggleDensity();
|
|
513
|
-
} })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", "aria-label": "Toggle Density", onClick: () => {
|
|
514
|
-
table.toggleDensity();
|
|
515
|
-
}, children: text }))] }));
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsxRuntime.jsx(md.MdFilterAlt, {}), ...props }) => {
|
|
519
|
-
const filterModal = react$1.useDisclosure();
|
|
520
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "1rem", children: [jsxRuntime.jsx(TableFilter, {}), jsxRuntime.jsx(ResetFilteringButton, { text: resetText })] }) }), jsxRuntime.jsx(react$1.ModalFooter, { children: jsxRuntime.jsx(react$1.Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
524
|
-
const orderModal = react$1.useDisclosure();
|
|
525
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: orderModal.onOpen, "aria-label": "change order" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: orderModal.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: orderModal.isOpen, onClose: orderModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsx(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) })] })] })] }));
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
const TableSorter = () => {
|
|
529
|
-
const { table } = useDataTable();
|
|
530
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
531
|
-
const displayName = header.column.columnDef.meta === undefined
|
|
532
|
-
? header.column.id
|
|
533
|
-
: header.column.columnDef.meta.displayName;
|
|
534
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: header.column.getCanSort() && (jsxRuntime.jsxs(react$1.Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsxs(react$1.Button, { variant: "ghost", onClick: (e) => {
|
|
535
|
-
header.column.toggleSorting();
|
|
536
|
-
}, children: [header.column.getIsSorted() === false && (
|
|
537
|
-
// <Text>To No sort</Text>
|
|
538
|
-
jsxRuntime.jsx(icons.UpDownIcon, {})), header.column.getIsSorted() === "asc" && (
|
|
539
|
-
// <Text>To asc</Text>
|
|
540
|
-
jsxRuntime.jsx(icons.ChevronDownIcon, {})), header.column.getIsSorted() === "desc" && (
|
|
541
|
-
// <Text>To desc</Text>
|
|
542
|
-
jsxRuntime.jsx(icons.ChevronUpIcon, {}))] }), header.column.getIsSorted() && (jsxRuntime.jsx(react$1.Button, { onClick: (e) => {
|
|
543
|
-
header.column.clearSorting();
|
|
544
|
-
}, children: jsxRuntime.jsx(icons.CloseIcon, {}) }))] })) }));
|
|
545
|
-
}) }))) }));
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}), title = "Edit Sorting", }) => {
|
|
549
|
-
const sortingModal = react$1.useDisclosure();
|
|
550
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: sortingModal.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: sortingModal.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: sortingModal.isOpen, onClose: sortingModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(TableSorter, {}), jsxRuntime.jsx(ResetSortingButton, {})] }) })] })] })] }));
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
554
|
-
const viewModel = react$1.useDisclosure();
|
|
555
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsx(TableViewer, {}) })] })] })] }));
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
const FilterOptions = ({ column }) => {
|
|
559
|
-
const { table } = useDataTable();
|
|
560
|
-
const tableColumn = table.getColumn(column);
|
|
561
|
-
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
562
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
563
|
-
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
564
|
-
return (jsxRuntime.jsxs(react$1.Button, { size: "sm", onClick: () => {
|
|
565
|
-
if (selected) {
|
|
566
|
-
table.setColumnFilters((state) => {
|
|
567
|
-
return state.filter((filter) => {
|
|
568
|
-
return filter.id !== column;
|
|
569
|
-
});
|
|
570
|
-
});
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
table.getColumn(column)?.setFilterValue(option);
|
|
574
|
-
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
|
|
575
|
-
}) }));
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
const GlobalFilter = ({ icon = md.MdSearch }) => {
|
|
579
|
-
const { globalFilter, setGlobalFilter } = useDataTable();
|
|
580
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Box, { children: jsxRuntime.jsxs(react$1.InputGroup, { children: [jsxRuntime.jsx(react$1.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react$1.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react$1.Input, { value: globalFilter, onChange: (e) => {
|
|
581
|
-
setGlobalFilter(e.target.value);
|
|
582
|
-
} })] }) }) }));
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
586
|
-
const { table } = useDataTable();
|
|
587
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react$1.Menu, { children: [jsxRuntime.jsx(react$1.MenuButton, { as: react$1.Button, variant: "ghost", rightIcon: jsxRuntime.jsx(icons.ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsxRuntime.jsx(react$1.MenuList, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(react$1.MenuItem, { onClick: () => {
|
|
588
|
-
table.setPageSize(Number(pageSize));
|
|
589
|
-
}, children: pageSize }, crypto.randomUUID()))) })] }) }));
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
593
|
-
const { table } = useDataTable();
|
|
594
|
-
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
595
|
-
table.resetColumnFilters();
|
|
596
|
-
}, children: text }));
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
const ResetSelectionButton = ({ text = "Reset Selection", }) => {
|
|
600
|
-
const { table } = useDataTable();
|
|
601
|
-
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
602
|
-
table.resetRowSelection();
|
|
603
|
-
}, children: text }));
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
const ResetSortingButton = ({ text = "Reset Sorting", }) => {
|
|
607
|
-
const { table } = useDataTable();
|
|
608
|
-
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
609
|
-
table.resetSorting();
|
|
610
|
-
}, children: text }));
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
const RowCountText = () => {
|
|
614
|
-
const { table } = useDataTable();
|
|
615
|
-
return jsxRuntime.jsx(react$1.Text, { children: table.getRowCount() });
|
|
616
|
-
};
|
|
617
|
-
|
|
618
581
|
const Table = ({ children, showLoading = false, loadingComponent = jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading..." }), ...props }) => {
|
|
619
|
-
const { table, loading } =
|
|
582
|
+
const { table, loading } = useDataTableContext();
|
|
620
583
|
if (showLoading) {
|
|
621
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react
|
|
584
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react.Table, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
|
|
622
585
|
}
|
|
623
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react
|
|
586
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Table, { width: table.getCenterTotalSize(), overflowX: "auto", ...props, children: children }) }));
|
|
624
587
|
};
|
|
625
588
|
|
|
626
589
|
const TableCardContainer = ({ children, ...props }) => {
|
|
627
|
-
return (jsxRuntime.jsx(react
|
|
590
|
+
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns: ["1fr", "1fr 1fr", "1fr 1fr 1fr"], gap: "0.5rem", ...props, children: children }));
|
|
628
591
|
};
|
|
629
592
|
|
|
630
593
|
const TableCards = ({ isSelectable = false }) => {
|
|
631
|
-
const { table } = react.useContext(TableContext);
|
|
594
|
+
const { table } = react$1.useContext(TableContext);
|
|
632
595
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getRowModel().rows.map((row) => {
|
|
633
|
-
return (jsxRuntime.jsx(react
|
|
596
|
+
return (jsxRuntime.jsx(react.Card, { children: jsxRuntime.jsxs(react.CardBody, { display: "flex", flexFlow: "column", gap: "0.5rem", children: [isSelectable && (jsxRuntime.jsx(react.Checkbox, { isChecked: row.getIsSelected(),
|
|
634
597
|
disabled: !row.getCanSelect(),
|
|
635
598
|
// indeterminate: row.getIsSomeSelected(),
|
|
636
599
|
onChange: row.getToggleSelectedHandler() })), row.getVisibleCells().map((cell) => {
|
|
637
|
-
return (jsxRuntime.jsx(react
|
|
600
|
+
return (jsxRuntime.jsx(react.Box, { children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, crypto.randomUUID()));
|
|
638
601
|
})] }) }, crypto.randomUUID()));
|
|
639
602
|
}) }));
|
|
640
603
|
};
|
|
@@ -642,17 +605,17 @@ const TableCards = ({ isSelectable = false }) => {
|
|
|
642
605
|
const TableComponent = ({ render = () => {
|
|
643
606
|
throw Error("Not Implemented");
|
|
644
607
|
}, }) => {
|
|
645
|
-
const { table } =
|
|
608
|
+
const { table } = useDataTableContext();
|
|
646
609
|
return render(table);
|
|
647
610
|
};
|
|
648
611
|
|
|
649
612
|
const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
|
|
650
613
|
console.log(startDate, endDate, "dflp");
|
|
651
|
-
return (jsxRuntime.jsx(react
|
|
614
|
+
return (jsxRuntime.jsx(react.Box, { p: '1rem', children: jsxRuntime.jsxs(react.VStack, { spacing: 4, children: [jsxRuntime.jsxs(react.FormControl, { children: [jsxRuntime.jsx(react.FormLabel, { htmlFor: "start-date", children: "Start Date" }), jsxRuntime.jsx(react.Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxRuntime.jsxs(react.FormControl, { children: [jsxRuntime.jsx(react.FormLabel, { htmlFor: "end-date", children: "End Date" }), jsxRuntime.jsx(react.Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
|
|
652
615
|
};
|
|
653
616
|
|
|
654
617
|
const RangeFilter = ({ range, setRange, defaultValue, min, max, step, }) => {
|
|
655
|
-
return (jsxRuntime.jsx(react
|
|
618
|
+
return (jsxRuntime.jsx(react.Box, { p: 8, children: jsxRuntime.jsxs(react.VStack, { spacing: 4, children: [jsxRuntime.jsxs(react.Text, { children: ["Selected Range: ", range[0], " - ", range[1]] }), jsxRuntime.jsxs(react.RangeSlider, { "aria-label": ["min", "max"], defaultValue: defaultValue, min: min, max: max, step: step, onChangeEnd: (val) => setRange(val), children: [jsxRuntime.jsx(react.RangeSliderTrack, { children: jsxRuntime.jsx(react.RangeSliderFilledTrack, {}) }), jsxRuntime.jsx(react.RangeSliderThumb, { index: 0 }), jsxRuntime.jsx(react.RangeSliderThumb, { index: 1 })] })] }) }));
|
|
656
619
|
};
|
|
657
620
|
|
|
658
621
|
const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
@@ -664,7 +627,7 @@ const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
|
664
627
|
onTagChange([...selectedTags, tag]);
|
|
665
628
|
}
|
|
666
629
|
};
|
|
667
|
-
return (jsxRuntime.jsx(react
|
|
630
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsxRuntime.jsx(react.WrapItem, { children: jsxRuntime.jsxs(react.Tag, { size: "lg", variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", onClick: () => toggleTag(tag), children: [jsxRuntime.jsx(react.TagLabel, { children: tag }), selectedTags.includes(tag) && jsxRuntime.jsx(react.TagCloseButton, {})] }) }, tag))) }));
|
|
668
631
|
};
|
|
669
632
|
|
|
670
633
|
function Filter({ column }) {
|
|
@@ -672,7 +635,7 @@ function Filter({ column }) {
|
|
|
672
635
|
const displayName = column.columnDef.meta?.displayName ?? column.id;
|
|
673
636
|
const filterOptions = column.columnDef.meta?.filterOptions ?? [];
|
|
674
637
|
if (column.columns.length > 0) {
|
|
675
|
-
return (jsxRuntime.jsxs(react
|
|
638
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), column.columns.map((column) => {
|
|
676
639
|
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
677
640
|
})] }, column.id));
|
|
678
641
|
}
|
|
@@ -680,14 +643,14 @@ function Filter({ column }) {
|
|
|
680
643
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
681
644
|
}
|
|
682
645
|
if (filterVariant === "select") {
|
|
683
|
-
return (jsxRuntime.jsxs(react
|
|
646
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(react.Select, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", placeholder: "Select option", onChange: (e) => {
|
|
684
647
|
column.setFilterValue(e.target.value);
|
|
685
648
|
}, children: filterOptions.map((option) => {
|
|
686
649
|
return (jsxRuntime.jsx("option", { value: option, children: option }, `${option}`));
|
|
687
650
|
}) })] }, column.id));
|
|
688
651
|
}
|
|
689
652
|
if (filterVariant === "tag") {
|
|
690
|
-
return (jsxRuntime.jsxs(react
|
|
653
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
691
654
|
if (tags.length === 0) {
|
|
692
655
|
return column.setFilterValue(undefined);
|
|
693
656
|
}
|
|
@@ -695,7 +658,7 @@ function Filter({ column }) {
|
|
|
695
658
|
} })] }, column.id));
|
|
696
659
|
}
|
|
697
660
|
if (filterVariant === "boolean") {
|
|
698
|
-
return (jsxRuntime.jsxs(react
|
|
661
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: ["true", "false"], selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
699
662
|
if (tags.length === 0) {
|
|
700
663
|
return column.setFilterValue(undefined);
|
|
701
664
|
}
|
|
@@ -724,7 +687,7 @@ function Filter({ column }) {
|
|
|
724
687
|
"",
|
|
725
688
|
"",
|
|
726
689
|
];
|
|
727
|
-
return (jsxRuntime.jsxs(react
|
|
690
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(DateRangeFilter, { startDate: start, endDate: end, setStartDate: function (value) {
|
|
728
691
|
column.setFilterValue((state) => {
|
|
729
692
|
return [value, (state ?? ["", ""])[1]];
|
|
730
693
|
});
|
|
@@ -741,47 +704,47 @@ function Filter({ column }) {
|
|
|
741
704
|
}
|
|
742
705
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderFilter(column) });
|
|
743
706
|
}
|
|
744
|
-
return (jsxRuntime.jsxs(react
|
|
707
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(react.Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
|
|
745
708
|
column.setFilterValue(e.target.value);
|
|
746
709
|
} })] }, column.id));
|
|
747
710
|
}
|
|
748
711
|
const TableFilter = () => {
|
|
749
|
-
const { table } =
|
|
712
|
+
const { table } = useDataTableContext();
|
|
750
713
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getAllColumns().map((column) => {
|
|
751
714
|
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
752
715
|
}) }));
|
|
753
716
|
};
|
|
754
717
|
|
|
755
718
|
const TableFilterTags = () => {
|
|
756
|
-
const { table } =
|
|
757
|
-
return (jsxRuntime.jsx(react
|
|
758
|
-
return (jsxRuntime.jsxs(react
|
|
759
|
-
table.setColumnFilters(table.getState().columnFilters.filter((
|
|
760
|
-
return
|
|
719
|
+
const { table } = useDataTableContext();
|
|
720
|
+
return (jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }) => {
|
|
721
|
+
return (jsxRuntime.jsxs(react.Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Text, { children: `${id}: ${value}` }), jsxRuntime.jsx(react.IconButton, { size: "xs", variant: "ghost", icon: jsxRuntime.jsx(icons.CloseIcon, {}), onClick: () => {
|
|
722
|
+
table.setColumnFilters(table.getState().columnFilters.filter((filter) => {
|
|
723
|
+
return filter.value != value;
|
|
761
724
|
}));
|
|
762
725
|
}, "aria-label": "remove filter" })] }, `${id}-${value}`));
|
|
763
726
|
}) }));
|
|
764
727
|
};
|
|
765
728
|
|
|
766
729
|
const TableLoadingComponent = ({ render, }) => {
|
|
767
|
-
const { loading } =
|
|
730
|
+
const { loading } = useDataTableContext();
|
|
768
731
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(loading) });
|
|
769
732
|
};
|
|
770
733
|
|
|
771
734
|
const ColumnOrderChanger = ({ columns }) => {
|
|
772
|
-
const [order, setOrder] = react.useState([]);
|
|
773
|
-
const [originalOrder, setOriginalOrder] = react.useState([]);
|
|
774
|
-
const { table } =
|
|
735
|
+
const [order, setOrder] = react$1.useState([]);
|
|
736
|
+
const [originalOrder, setOriginalOrder] = react$1.useState([]);
|
|
737
|
+
const { table } = useDataTableContext();
|
|
775
738
|
const handleChangeOrder = (startIndex, endIndex) => {
|
|
776
739
|
const newOrder = Array.from(order);
|
|
777
740
|
const [removed] = newOrder.splice(startIndex, 1);
|
|
778
741
|
newOrder.splice(endIndex, 0, removed);
|
|
779
742
|
setOrder(newOrder);
|
|
780
743
|
};
|
|
781
|
-
react.useEffect(() => {
|
|
744
|
+
react$1.useEffect(() => {
|
|
782
745
|
setOrder(columns);
|
|
783
746
|
}, [columns]);
|
|
784
|
-
react.useEffect(() => {
|
|
747
|
+
react$1.useEffect(() => {
|
|
785
748
|
if (originalOrder.length > 0) {
|
|
786
749
|
return;
|
|
787
750
|
}
|
|
@@ -790,7 +753,7 @@ const ColumnOrderChanger = ({ columns }) => {
|
|
|
790
753
|
}
|
|
791
754
|
setOriginalOrder(columns);
|
|
792
755
|
}, [columns]);
|
|
793
|
-
return (jsxRuntime.jsxs(react
|
|
756
|
+
return (jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", flexFlow: "column", children: [jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "column", children: order.map((columnId, index) => (jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", justifyContent: "space-between", children: [jsxRuntime.jsx(react.IconButton, { onClick: () => {
|
|
794
757
|
const prevIndex = index - 1;
|
|
795
758
|
if (prevIndex >= 0) {
|
|
796
759
|
handleChangeOrder(index, prevIndex);
|
|
@@ -805,56 +768,54 @@ const ColumnOrderChanger = ({ columns }) => {
|
|
|
805
768
|
? column.id
|
|
806
769
|
: column.columnDef.meta.displayName;
|
|
807
770
|
return jsxRuntime.jsx("span", { children: displayName }, column.id);
|
|
808
|
-
}), jsxRuntime.jsx(react
|
|
771
|
+
}), jsxRuntime.jsx(react.IconButton, { onClick: () => {
|
|
809
772
|
const nextIndex = index + 1;
|
|
810
773
|
if (nextIndex < order.length) {
|
|
811
774
|
handleChangeOrder(index, nextIndex);
|
|
812
775
|
}
|
|
813
|
-
}, disabled: index === order.length - 1, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowDownward, {}) })] }, columnId))) }), jsxRuntime.jsxs(react
|
|
776
|
+
}, disabled: index === order.length - 1, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowDownward, {}) })] }, columnId))) }), jsxRuntime.jsxs(react.Flex, { gap: "0.25rem", children: [jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
814
777
|
table.setColumnOrder(order);
|
|
815
|
-
}, children: "Apply" }), jsxRuntime.jsx(react
|
|
778
|
+
}, children: "Apply" }), jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
816
779
|
table.setColumnOrder(originalOrder);
|
|
817
780
|
}, children: "Reset" })] })] }));
|
|
818
781
|
};
|
|
819
782
|
const TableOrderer = () => {
|
|
820
|
-
const { table } =
|
|
783
|
+
const { table } = useDataTableContext();
|
|
821
784
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
822
785
|
};
|
|
823
786
|
|
|
824
787
|
const TablePagination = ({}) => {
|
|
825
|
-
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } =
|
|
826
|
-
return (jsxRuntime.jsxs(react
|
|
788
|
+
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTableContext().table;
|
|
789
|
+
return (jsxRuntime.jsxs(react.ButtonGroup, { isAttached: true, children: [jsxRuntime.jsx(react.IconButton, { icon: jsxRuntime.jsx(md.MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsxRuntime.jsx(react.IconButton, { icon: jsxRuntime.jsx(md.MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsxRuntime.jsx(react.Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react.IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react.IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
827
790
|
};
|
|
828
791
|
|
|
829
792
|
const ReloadButton = ({ text = "Reload" }) => {
|
|
830
|
-
const { refreshData } =
|
|
831
|
-
return (jsxRuntime.jsx(react
|
|
793
|
+
const { refreshData } = useDataTableContext();
|
|
794
|
+
return (jsxRuntime.jsx(react.Button, { leftIcon: jsxRuntime.jsx(io5.IoReload, {}), onClick: () => {
|
|
832
795
|
refreshData();
|
|
833
796
|
}, children: text }));
|
|
834
797
|
};
|
|
835
798
|
|
|
836
|
-
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText, clearAllText, }) => {
|
|
837
|
-
const { table } =
|
|
838
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react
|
|
799
|
+
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
800
|
+
const { table } = useDataTableContext();
|
|
801
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react.IconButton, { icon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
|
|
839
802
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
840
|
-
} })), !!selectAllText !== false && (jsxRuntime.jsx(react
|
|
803
|
+
} })), !!selectAllText !== false && (jsxRuntime.jsx(react.Button, { leftIcon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", onClick: (event) => {
|
|
841
804
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
842
805
|
}, children: table.getIsAllRowsSelected() ? clearAllText : selectAllText }))] }));
|
|
843
806
|
};
|
|
844
807
|
|
|
845
808
|
const TableSelector = () => {
|
|
846
|
-
const { table } = react.useContext(TableContext);
|
|
847
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsxs(react
|
|
809
|
+
const { table } = react$1.useContext(TableContext);
|
|
810
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsxs(react.Button, { onClick: () => { }, variant: "ghost", display: "flex", gap: "0.25rem", children: [jsxRuntime.jsx(react.Box, { fontSize: "sm", children: `${table.getSelectedRowModel().rows.length}` }), jsxRuntime.jsx(react.Icon, { as: io.IoMdCheckbox })] })), !table.getIsAllPageRowsSelected() && jsxRuntime.jsx(SelectAllRowsToggle, {}), table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", icon: jsxRuntime.jsx(react.Icon, { as: md.MdClear }), onClick: () => {
|
|
848
811
|
table.resetRowSelection();
|
|
849
812
|
}, "aria-label": "reset selection" }))] }));
|
|
850
813
|
};
|
|
851
814
|
|
|
852
815
|
const TableViewer = () => {
|
|
853
|
-
const { table } =
|
|
816
|
+
const { table } = useDataTableContext();
|
|
854
817
|
const columns = table.getAllLeafColumns();
|
|
855
|
-
const [columnOrder, setColumnOrder] = react.useState(columns.map(
|
|
856
|
-
return column.id;
|
|
857
|
-
}));
|
|
818
|
+
const [columnOrder, setColumnOrder] = react$1.useState(columns.map(column => column.id));
|
|
858
819
|
const handleDragEnd = (result) => {
|
|
859
820
|
if (!result.destination)
|
|
860
821
|
return;
|
|
@@ -864,19 +825,44 @@ const TableViewer = () => {
|
|
|
864
825
|
setColumnOrder(newColumnOrder);
|
|
865
826
|
table.setColumnOrder(newColumnOrder);
|
|
866
827
|
};
|
|
867
|
-
return (jsxRuntime.jsx(
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxRuntime.jsxs(react$1.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react$1.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsxRuntime.jsx(react$1.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react$1.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsxs(react$1.Box, { children: [" ", displayName] }), jsxRuntime.jsx(react$1.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
|
|
872
|
-
}), provided.placeholder] })) }) }) }));
|
|
828
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.DragDropContext, { onDragEnd: handleDragEnd, children: jsxRuntime.jsx(reactBeautifulDnd.Droppable, { droppableId: "columns", children: (provided) => (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, index) => {
|
|
829
|
+
const displayName = column.columnDef.meta?.displayName || column.id;
|
|
830
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: index, children: (provided) => (jsxRuntime.jsxs(react.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "0", children: jsxRuntime.jsx(react.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsx(react.Box, { children: displayName }), jsxRuntime.jsx(react.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] })) }, column.id));
|
|
831
|
+
}), provided.placeholder] })) }) }));
|
|
873
832
|
};
|
|
874
833
|
|
|
875
834
|
const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipProps, ...props }) => {
|
|
876
835
|
if (label) {
|
|
877
|
-
return (jsxRuntime.jsx(react
|
|
836
|
+
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react.Tooltip, { label: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", noOfLines: [5], children: label }), placement: "auto", ...tooltipProps, children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }) }));
|
|
878
837
|
}
|
|
879
|
-
return (jsxRuntime.jsx(react
|
|
838
|
+
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }));
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
const FilterOptions = ({ column }) => {
|
|
842
|
+
const { table } = useDataTableContext();
|
|
843
|
+
const tableColumn = table.getColumn(column);
|
|
844
|
+
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
845
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
846
|
+
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
847
|
+
return (jsxRuntime.jsxs(react.Button, { size: "sm", onClick: () => {
|
|
848
|
+
if (selected) {
|
|
849
|
+
table.setColumnFilters((state) => {
|
|
850
|
+
return state.filter((filter) => {
|
|
851
|
+
return filter.id !== column;
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
table.getColumn(column)?.setFilterValue(option);
|
|
857
|
+
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
|
|
858
|
+
}) }));
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
const GlobalFilter = ({ icon = md.MdSearch }) => {
|
|
862
|
+
const { table } = useDataTableContext();
|
|
863
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsxs(react.InputGroup, { children: [jsxRuntime.jsx(react.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react.Input, { value: table.getState().globalFilter.globalFilter, onChange: (e) => {
|
|
864
|
+
table.setGlobalFilter(e.target.value);
|
|
865
|
+
} })] }) }) }));
|
|
880
866
|
};
|
|
881
867
|
|
|
882
868
|
exports.DataTable = DataTable;
|
|
@@ -913,4 +899,4 @@ exports.TableSorter = TableSorter;
|
|
|
913
899
|
exports.TableViewer = TableViewer;
|
|
914
900
|
exports.TextCell = TextCell;
|
|
915
901
|
exports.useDataFromUrl = useDataFromUrl;
|
|
916
|
-
exports.
|
|
902
|
+
exports.useDataTableContext = useDataTableContext;
|