@prt-ts/fluent-react-table-v2 9.36.0-build.3.0 → 9.40.0-build.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +603 -179
- package/package.json +3 -2
- package/src/lib/components/filters/Filter.d.ts +2 -2
- package/src/lib/components/filters/FilterDate.d.ts +7 -0
- package/src/lib/components/filters/FilterDateRange.d.ts +7 -0
- package/src/lib/components/filters/FilterDrawer.d.ts +9 -0
- package/src/lib/components/filters/FilterMultiSelectCheckbox.d.ts +2 -2
- package/src/lib/components/filters/FilterNumberRange.d.ts +7 -0
- package/src/lib/components/filters/{FilterMultiSelectRadio.d.ts → FilterSelectRadio.d.ts} +1 -1
- package/src/lib/components/filters/index.d.ts +1 -0
- package/src/lib/components/grid-header/GridHeader.d.ts +7 -1
- package/src/lib/components/table/Table.d.ts +3 -3
- package/src/lib/components/useGridContainer.d.ts +14 -0
- package/src/lib/components/views/ViewSaveForm.d.ts +9 -0
- package/src/lib/components/views/ViewsDrawer.d.ts +16 -0
- package/src/lib/helpers/FilterHelpers.d.ts +4 -0
- package/src/lib/helpers/Helpers.d.ts +2 -0
- package/src/lib/index.d.ts +10 -2
- package/src/lib/types/TableProps.d.ts +17 -0
- package/src/lib/types/TableRef.d.ts +4 -4
- package/src/lib/types/TableView.d.ts +8 -0
- package/src/lib/types/index.d.ts +1 -0
- package/src/lib/components/thead/useGridContainer.d.ts +0 -8
package/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import * as React from 'react';
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { useDrop, useDrag, DndProvider } from 'react-dnd';
|
|
5
5
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
6
|
-
import { makeStaticStyles, makeStyles, shorthands, tokens, useId, Dropdown, Option, Input, Button, Popover, PopoverTrigger, PopoverSurface, MenuGroupHeader, Checkbox,
|
|
7
|
-
import { PreviousRegular, ArrowPreviousFilled, ArrowNextFilled, NextRegular, bundleIcon, SaveFilled, SaveRegular, TableSimpleCheckmarkFilled, TableSimpleCheckmarkRegular, SearchFilled, SearchRegular, FilterFilled, FilterRegular, CodeTextOff16Filled, CodeTextOff16Regular, ColumnEditFilled, ColumnEditRegular, GroupFilled, GroupRegular, ChevronRightFilled, ChevronRightRegular, ChevronDownRegular, ChevronDownFilled, DragFilled, DragRegular, Search24Regular, ArrowSortDown20Filled, ArrowSortDown20Regular, ArrowSortUp20Filled, ArrowSortUp20Regular, GroupListRegular, PinRegular, TextSortAscendingFilled, TextSortDescendingFilled, GroupDismissFilled, ArrowStepInLeftRegular, ArrowStepInRightRegular, PinOffRegular, DocumentSearch24Regular } from '@fluentui/react-icons';
|
|
6
|
+
import { makeStaticStyles, makeStyles, shorthands, tokens, useId, Dropdown, Option, Input, Button, Divider, Popover, PopoverTrigger, PopoverSurface, MenuGroupHeader, Checkbox, RadioGroup, Radio, Field, InlineDrawer, DrawerHeader, DrawerHeaderTitle, DrawerBody, Caption1Stronger, Menu, MenuTrigger, MenuButton, MenuPopover, MenuList, MenuGroup, MenuItem, MenuDivider, mergeClasses, Skeleton, SkeletonItem, Subtitle2Stronger, MenuItemRadio, DrawerFooter } from '@fluentui/react-components';
|
|
7
|
+
import { PreviousRegular, ArrowPreviousFilled, ArrowNextFilled, NextRegular, bundleIcon, SaveFilled, SaveRegular, TableSimpleCheckmarkFilled, TableSimpleCheckmarkRegular, SearchFilled, SearchRegular, FilterFilled, FilterRegular, CodeTextOff16Filled, CodeTextOff16Regular, ColumnEditFilled, ColumnEditRegular, GroupFilled, GroupRegular, ChevronRightFilled, ChevronRightRegular, ChevronDownRegular, ChevronDownFilled, DragFilled, DragRegular, Album24Regular, Search24Regular, FilterDismissFilled, Dismiss24Regular, ArrowSortDown20Filled, ArrowSortDown20Regular, ArrowSortUp20Filled, ArrowSortUp20Regular, GroupListRegular, PinRegular, TextSortAscendingFilled, TextSortDescendingFilled, GroupDismissFilled, ArrowStepInLeftRegular, ArrowStepInRightRegular, PinOffRegular, DocumentSearch24Regular, Save20Filled, ViewDesktop20Filled, ViewDesktop20Regular } from '@fluentui/react-icons';
|
|
8
8
|
import { useReactTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, getFilteredRowModel, getGroupedRowModel, getExpandedRowModel, getFacetedUniqueValues, getFacetedMinMaxValues, flexRender } from '@tanstack/react-table';
|
|
9
9
|
export { createColumnHelper } from '@tanstack/react-table';
|
|
10
10
|
import { useVirtual } from 'react-virtual';
|
|
11
|
+
import { DatePicker } from '@fluentui/react-datepicker-compat';
|
|
11
12
|
|
|
12
13
|
const useStaticStyles = makeStaticStyles({
|
|
13
14
|
"*": {
|
|
@@ -162,34 +163,25 @@ const useGridHeaderStyles = makeStyles({
|
|
|
162
163
|
const GridHeader = (props) => {
|
|
163
164
|
const { table, gridTitle, globalFilter, setGlobalFilter } = props;
|
|
164
165
|
const styles = useGridHeaderStyles();
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
table.setGlobalFilter("");
|
|
168
|
-
table.resetColumnFilters();
|
|
169
|
-
}, [table]);
|
|
170
|
-
const resetAllGrouping = React.useCallback(() => {
|
|
171
|
-
table.resetGrouping();
|
|
172
|
-
}, [table]);
|
|
173
|
-
const clearAllSelection = React.useCallback(() => {
|
|
174
|
-
table.toggleAllRowsSelected(false);
|
|
175
|
-
}, [table]);
|
|
176
|
-
return (jsxs("div", Object.assign({ className: styles.tableTopHeaderContainer }, { children: [jsx("div", Object.assign({ className: styles.tableTopHeaderLeft }, { children: gridTitle })), jsxs("div", Object.assign({ className: styles.tableTopHeaderRight }, { children: [jsxs(Popover, Object.assign({ withArrow: true }, { children: [jsx(PopoverTrigger, Object.assign({ disableButtonEnhancement: true }, { children: jsx(Button, { icon: jsx(ToggleGroupColumnIcon, {}), "aria-label": 'Toggle Group Column' }) })), jsx(PopoverSurface, { children: jsxs("div", Object.assign({ className: styles.tableTopHeaderColumnTogglePopover }, { children: [jsx(MenuGroupHeader, { children: "Group Columns" }), allLeafColumns.map((column) => {
|
|
177
|
-
if (column.id === "select")
|
|
178
|
-
return null;
|
|
179
|
-
if (column.id === "id")
|
|
166
|
+
return (jsxs("div", Object.assign({ className: styles.tableTopHeaderContainer }, { children: [jsx("div", Object.assign({ className: styles.tableTopHeaderLeft }, { children: gridTitle })), jsxs("div", Object.assign({ className: styles.tableTopHeaderRight }, { children: [props.headerMenu, props.headerMenu && jsx(Divider, { vertical: true }), jsxs(Popover, Object.assign({ withArrow: true }, { children: [jsx(PopoverTrigger, Object.assign({ disableButtonEnhancement: true }, { children: jsx(Button, { icon: jsx(ToggleGroupColumnIcon, {}), "aria-label": "Toggle Group Column" }) })), jsx(PopoverSurface, { children: jsxs("div", Object.assign({ className: styles.tableTopHeaderColumnTogglePopover }, { children: [jsx(MenuGroupHeader, { children: "Group Columns" }), table.getAllLeafColumns().map((column) => {
|
|
167
|
+
if (column.id === 'select')
|
|
180
168
|
return null;
|
|
181
|
-
|
|
182
|
-
})] })) })] })), jsxs(Popover, Object.assign({ withArrow: true }, { children: [jsx(PopoverTrigger, Object.assign({ disableButtonEnhancement: true }, { children: jsx(Button, { icon: jsx(ToggleSelectColumnIcon, {}), "aria-label": 'Toggle Column Visibility' }) })), jsx(PopoverSurface, { children: jsxs("div", Object.assign({ className: styles.tableTopHeaderColumnTogglePopover }, { children: [jsx(MenuGroupHeader, { children: "Toggle Columns" }), jsx(Checkbox, { checked: table.getIsAllColumnsVisible(), onChange: table.getToggleAllColumnsVisibilityHandler(), label: "Toggle All" }), jsx(Divider, {}), table.getAllLeafColumns().map((column) => {
|
|
183
|
-
if (column.id === "select")
|
|
169
|
+
if (column.id === 'id')
|
|
184
170
|
return null;
|
|
185
|
-
|
|
171
|
+
return (jsx(Checkbox, { checked: column.getIsGrouped(), onChange: column.getToggleGroupingHandler(), disabled: !column.getCanGroup() || !column.getIsVisible(), label: jsx("span", { children: column.columnDef.id }) }, column.id));
|
|
172
|
+
})] })) })] })), jsxs(Popover, Object.assign({ withArrow: true }, { children: [jsx(PopoverTrigger, Object.assign({ disableButtonEnhancement: true }, { children: jsx(Button, { icon: jsx(ToggleSelectColumnIcon, {}), "aria-label": "Toggle Column Visibility" }) })), jsx(PopoverSurface, { children: jsxs("div", Object.assign({ className: styles.tableTopHeaderColumnTogglePopover }, { children: [jsx(MenuGroupHeader, { children: "Toggle Columns" }), jsx(Checkbox, { checked: table.getIsAllColumnsVisible(), onChange: table.getToggleAllColumnsVisibilityHandler(), label: 'Toggle All' }), jsx(Divider, {}), table.getAllLeafColumns().map((column) => {
|
|
173
|
+
if (column.id === 'select')
|
|
186
174
|
return null;
|
|
187
175
|
return (jsx(Checkbox, { checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler(), label: column.id, disabled: !column.getCanHide() }, column.id));
|
|
188
|
-
})] })) })] })), jsx(
|
|
176
|
+
})] })) })] })), jsx(Button
|
|
177
|
+
// appearance="subtle"
|
|
178
|
+
, {
|
|
179
|
+
// appearance="subtle"
|
|
180
|
+
onClick: () => props.setViewsDrawerOpen((value) => !value), icon: jsx(Album24Regular, {}), "aria-label": "View Menu" }), jsx(DebouncedInput, { value: globalFilter !== null && globalFilter !== void 0 ? globalFilter : '', onChange: (value) => setGlobalFilter(String(value)), className: "p-2 font-lg shadow border border-block", placeholder: "Search all columns...", openFilterDrawer: props.openFilterDrawer, setFilterDrawerOpen: props.setFilterDrawerOpen })] }))] })));
|
|
189
181
|
};
|
|
190
182
|
// A debounced input react component
|
|
191
|
-
function DebouncedInput({ value: initialValue, onChange, debounce = 500,
|
|
192
|
-
const [value, setValue] = React.useState(
|
|
183
|
+
function DebouncedInput({ value: initialValue, onChange, debounce = 500, openFilterDrawer, setFilterDrawerOpen, }) {
|
|
184
|
+
const [value, setValue] = React.useState('');
|
|
193
185
|
React.useEffect(() => {
|
|
194
186
|
setValue(initialValue);
|
|
195
187
|
}, [initialValue]);
|
|
@@ -199,7 +191,9 @@ function DebouncedInput({ value: initialValue, onChange, debounce = 500, resetAl
|
|
|
199
191
|
}, debounce);
|
|
200
192
|
return () => clearTimeout(timeout);
|
|
201
193
|
}, [value, onChange, debounce]);
|
|
202
|
-
return (jsx(Input, { placeholder: "Search Keyword", value: value, onChange: (_, data) => setValue(data.value), type: "search", autoComplete: "off", contentBefore: jsx(Search24Regular, {}), style: { width:
|
|
194
|
+
return (jsx(Input, { placeholder: "Search Keyword", value: value, onChange: (_, data) => setValue(data.value), type: "search", autoComplete: "off", contentBefore: jsx(Search24Regular, {}), style: { width: '300px' }, contentAfter: jsx(Button, { appearance: "subtle", title: 'Ad', icon: openFilterDrawer ? jsx(FilterDismissFilled, {}) : jsx(FilterFilled, {}), "aria-label": "View Menu", onClick: () => {
|
|
195
|
+
setFilterDrawerOpen((open) => !open);
|
|
196
|
+
} }) }));
|
|
203
197
|
}
|
|
204
198
|
|
|
205
199
|
const arrIncludesSome = (row, columnId, value) => {
|
|
@@ -207,10 +201,57 @@ const arrIncludesSome = (row, columnId, value) => {
|
|
|
207
201
|
const rowValue = row.getValue(columnId);
|
|
208
202
|
const passed = Array.isArray(value) &&
|
|
209
203
|
((value === null || value === void 0 ? void 0 : value.length) === 0 || value.includes(`${rowValue}`));
|
|
210
|
-
// console.log("rowValue", rowValue, "value", value, "passed", passed, "columnId", columnId)
|
|
211
|
-
// Return if the item should be filtered in/out
|
|
212
204
|
return passed;
|
|
213
205
|
};
|
|
206
|
+
const dateRange = (row, columnId, value) => {
|
|
207
|
+
// filter by date range
|
|
208
|
+
const rowValue = row.getValue(columnId);
|
|
209
|
+
// compare the date range
|
|
210
|
+
// case if no start date or end date is selected
|
|
211
|
+
// case if start date is selected
|
|
212
|
+
// case if end date is selected
|
|
213
|
+
if (!value || value.length === 0) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
else if (value.length === 2 && value[0] && !value[1]) {
|
|
217
|
+
return typeof rowValue.getMonth === 'function' && rowValue >= value[0];
|
|
218
|
+
}
|
|
219
|
+
else if (value.length === 2 && !value[0] && value[1]) {
|
|
220
|
+
return typeof rowValue.getMonth === 'function' && rowValue <= value[1];
|
|
221
|
+
}
|
|
222
|
+
else if (value.length === 2 && !value[0] && !value[1]) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
const passed = typeof rowValue.getMonth === 'function' && value[0] <= rowValue && rowValue <= value[1];
|
|
226
|
+
return passed;
|
|
227
|
+
};
|
|
228
|
+
const date = (row, columnId, value) => {
|
|
229
|
+
var _a;
|
|
230
|
+
// filter by date range
|
|
231
|
+
const rowValue = row.getValue(columnId);
|
|
232
|
+
// compare the date range
|
|
233
|
+
// case if no start date or end date is selected
|
|
234
|
+
// case if start date is selected
|
|
235
|
+
// case if end date is selected
|
|
236
|
+
if (!value) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
const passed = typeof rowValue.getMonth === 'function' && ((_a = new Date(value)) === null || _a === void 0 ? void 0 : _a.toDateString()) === (rowValue === null || rowValue === void 0 ? void 0 : rowValue.toDateString());
|
|
240
|
+
return passed;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const getLeafColumns = (columns) => {
|
|
244
|
+
if (!columns || !columns.length) {
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
return columns.reduce((totalItems, col) => {
|
|
248
|
+
if (!col.columns) {
|
|
249
|
+
totalItems.push(col);
|
|
250
|
+
}
|
|
251
|
+
return totalItems.concat(getLeafColumns(col.columns));
|
|
252
|
+
}, []);
|
|
253
|
+
};
|
|
254
|
+
|
|
214
255
|
const useGridContainer = (props, ref) => {
|
|
215
256
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
216
257
|
const { columns, data, rowSelectionMode } = props;
|
|
@@ -220,21 +261,31 @@ const useGridContainer = (props, ref) => {
|
|
|
220
261
|
});
|
|
221
262
|
const [sorting, setSorting] = React.useState((_a = props.sortingState) !== null && _a !== void 0 ? _a : []);
|
|
222
263
|
const [columnFilters, setColumnFilters] = React.useState((_b = props.columnFilterState) !== null && _b !== void 0 ? _b : []);
|
|
223
|
-
const [globalFilter, setGlobalFilter] = React.useState((_c = props.defaultGlobalFilter) !== null && _c !== void 0 ? _c :
|
|
264
|
+
const [globalFilter, setGlobalFilter] = React.useState((_c = props.defaultGlobalFilter) !== null && _c !== void 0 ? _c : '');
|
|
224
265
|
const [grouping, setGrouping] = React.useState((_d = props.groupingState) !== null && _d !== void 0 ? _d : []);
|
|
225
266
|
const [rowSelection, setRowSelection] = React.useState((_e = props.rowSelectionState) !== null && _e !== void 0 ? _e : {});
|
|
226
267
|
const [columnVisibility, setColumnVisibility] = React.useState((_f = props.columnVisibility) !== null && _f !== void 0 ? _f : {});
|
|
227
|
-
const [columnOrder, setColumnOrder] = React.useState(() => {
|
|
268
|
+
const [columnOrder, setColumnOrder] = React.useState(() => {
|
|
269
|
+
if (props.columnOrderState) {
|
|
270
|
+
return props.columnOrderState;
|
|
271
|
+
}
|
|
272
|
+
const leafColumns = getLeafColumns(columns);
|
|
273
|
+
return leafColumns.map((col) => col.id);
|
|
274
|
+
});
|
|
228
275
|
const [expanded, setExpanded] = React.useState((_g = props.expandedState) !== null && _g !== void 0 ? _g : {});
|
|
229
276
|
const [columnPinning, setColumnPinning] = React.useState((_h = props.columnPinningState) !== null && _h !== void 0 ? _h : {});
|
|
277
|
+
const [columnSizing, setColumnSizing] = React.useState({});
|
|
278
|
+
const tableViews = React.useMemo(() => { var _a; return (_a = props.views) !== null && _a !== void 0 ? _a : []; }, [props.views]);
|
|
230
279
|
const table = useReactTable({
|
|
231
280
|
columns: columns,
|
|
232
281
|
data,
|
|
233
282
|
filterFns: {
|
|
234
|
-
arrIncludesSome,
|
|
283
|
+
arrIncludesSome: arrIncludesSome,
|
|
284
|
+
inDateRange: dateRange,
|
|
285
|
+
matchDate: date,
|
|
235
286
|
},
|
|
236
287
|
initialState: {
|
|
237
|
-
expanded: true
|
|
288
|
+
expanded: true,
|
|
238
289
|
},
|
|
239
290
|
state: {
|
|
240
291
|
pagination,
|
|
@@ -247,10 +298,11 @@ const useGridContainer = (props, ref) => {
|
|
|
247
298
|
columnOrder,
|
|
248
299
|
columnVisibility,
|
|
249
300
|
columnPinning,
|
|
301
|
+
columnSizing,
|
|
250
302
|
},
|
|
251
|
-
columnResizeMode:
|
|
303
|
+
columnResizeMode: 'onChange',
|
|
252
304
|
enableRowSelection: rowSelectionMode !== undefined,
|
|
253
|
-
enableMultiRowSelection: rowSelectionMode ===
|
|
305
|
+
enableMultiRowSelection: rowSelectionMode === 'multiple',
|
|
254
306
|
enableFilters: true,
|
|
255
307
|
enableGlobalFilter: true,
|
|
256
308
|
enableColumnFilters: true,
|
|
@@ -266,6 +318,7 @@ const useGridContainer = (props, ref) => {
|
|
|
266
318
|
onExpandedChange: setExpanded,
|
|
267
319
|
onColumnVisibilityChange: setColumnVisibility,
|
|
268
320
|
onColumnPinningChange: setColumnPinning,
|
|
321
|
+
onColumnSizingChange: setColumnSizing,
|
|
269
322
|
getCoreRowModel: getCoreRowModel(),
|
|
270
323
|
getPaginationRowModel: getPaginationRowModel(),
|
|
271
324
|
getSortedRowModel: getSortedRowModel(),
|
|
@@ -287,6 +340,7 @@ const useGridContainer = (props, ref) => {
|
|
|
287
340
|
columnOrder,
|
|
288
341
|
columnVisibility,
|
|
289
342
|
columnPinning,
|
|
343
|
+
columnSizing
|
|
290
344
|
};
|
|
291
345
|
}, [
|
|
292
346
|
pagination,
|
|
@@ -299,55 +353,130 @@ const useGridContainer = (props, ref) => {
|
|
|
299
353
|
columnOrder,
|
|
300
354
|
columnVisibility,
|
|
301
355
|
columnPinning,
|
|
356
|
+
columnSizing
|
|
302
357
|
]);
|
|
358
|
+
const resetToDefaultView = () => {
|
|
359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
360
|
+
const defaultTableState = {
|
|
361
|
+
pagination: {
|
|
362
|
+
pageSize: props.pageSize || 10,
|
|
363
|
+
pageIndex: 0,
|
|
364
|
+
},
|
|
365
|
+
sorting: (_a = props.sortingState) !== null && _a !== void 0 ? _a : [],
|
|
366
|
+
columnFilters: (_b = props.columnFilterState) !== null && _b !== void 0 ? _b : [],
|
|
367
|
+
globalFilter: (_c = props.defaultGlobalFilter) !== null && _c !== void 0 ? _c : '',
|
|
368
|
+
grouping: (_d = props.groupingState) !== null && _d !== void 0 ? _d : [],
|
|
369
|
+
expanded: (_e = props.expandedState) !== null && _e !== void 0 ? _e : {},
|
|
370
|
+
rowSelection: (_f = props.rowSelectionState) !== null && _f !== void 0 ? _f : {},
|
|
371
|
+
columnOrder: (() => {
|
|
372
|
+
if (props.columnOrderState) {
|
|
373
|
+
return props.columnOrderState;
|
|
374
|
+
}
|
|
375
|
+
const leafColumns = getLeafColumns(columns);
|
|
376
|
+
return leafColumns.map((col) => col.id);
|
|
377
|
+
})(),
|
|
378
|
+
columnVisibility: (_g = props.columnVisibility) !== null && _g !== void 0 ? _g : {},
|
|
379
|
+
columnPinning: (_h = props.columnPinningState) !== null && _h !== void 0 ? _h : {},
|
|
380
|
+
columnSizing: {}
|
|
381
|
+
};
|
|
382
|
+
return applyTableState(defaultTableState);
|
|
383
|
+
};
|
|
384
|
+
const applyTableState = (tableState) => {
|
|
385
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
386
|
+
if (tableState) {
|
|
387
|
+
setSorting((_a = tableState.sorting) !== null && _a !== void 0 ? _a : []);
|
|
388
|
+
setColumnFilters((_b = tableState.columnFilters) !== null && _b !== void 0 ? _b : []);
|
|
389
|
+
setGlobalFilter((_c = tableState.globalFilter) !== null && _c !== void 0 ? _c : '');
|
|
390
|
+
setGrouping((_d = tableState.grouping) !== null && _d !== void 0 ? _d : []);
|
|
391
|
+
setExpanded((_e = tableState.expanded) !== null && _e !== void 0 ? _e : {});
|
|
392
|
+
setRowSelection((_f = tableState.rowSelection) !== null && _f !== void 0 ? _f : {});
|
|
393
|
+
setColumnOrder((_g = tableState.columnOrder) !== null && _g !== void 0 ? _g : []);
|
|
394
|
+
setColumnVisibility((_h = tableState.columnVisibility) !== null && _h !== void 0 ? _h : {});
|
|
395
|
+
setColumnPinning((_j = tableState.columnPinning) !== null && _j !== void 0 ? _j : {});
|
|
396
|
+
setColumnSizing((_k = tableState.columnSizing) !== null && _k !== void 0 ? _k : {});
|
|
397
|
+
setTimeout(() => {
|
|
398
|
+
var _a;
|
|
399
|
+
setPagination((_a = tableState.pagination) !== null && _a !== void 0 ? _a : {
|
|
400
|
+
pageSize: props.pageSize || 10,
|
|
401
|
+
pageIndex: 0,
|
|
402
|
+
});
|
|
403
|
+
}, 10);
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
return false;
|
|
407
|
+
};
|
|
303
408
|
React.useImperativeHandle(ref, () => {
|
|
304
409
|
return {
|
|
305
410
|
table,
|
|
306
|
-
getTableState
|
|
307
|
-
|
|
411
|
+
getTableState,
|
|
412
|
+
applyTableState,
|
|
413
|
+
resetToDefaultView
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
417
|
+
[table, getTableState]);
|
|
418
|
+
const headerMenu = React.useMemo(() => {
|
|
419
|
+
if (props.headerMenu) {
|
|
420
|
+
const selectedRows = (table === null || table === void 0 ? void 0 : table.getSelectedRowModel().flatRows.map((row) => row.original)) || [];
|
|
421
|
+
return props.headerMenu(selectedRows);
|
|
422
|
+
}
|
|
423
|
+
return null;
|
|
424
|
+
},
|
|
425
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
426
|
+
[props.headerMenu, rowSelection]);
|
|
427
|
+
// add event listeners to listen ctrl + shift + t and log current table state
|
|
428
|
+
React.useEffect(() => {
|
|
429
|
+
const handleKeyDown = (event) => {
|
|
430
|
+
if (event.ctrlKey && event.altKey && event.key === 'c') {
|
|
431
|
+
event.preventDefault();
|
|
308
432
|
const tableState = getTableState();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
setGrouping(tableState.grouping);
|
|
321
|
-
setExpanded(tableState.expanded);
|
|
322
|
-
setRowSelection(tableState.rowSelection);
|
|
323
|
-
setColumnOrder(tableState.columnOrder);
|
|
324
|
-
setColumnVisibility(tableState.columnVisibility);
|
|
325
|
-
setColumnPinning(tableState.columnPinning);
|
|
326
|
-
setTimeout(() => {
|
|
327
|
-
setPagination(tableState.pagination);
|
|
328
|
-
}, 10);
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
return false;
|
|
332
|
-
},
|
|
433
|
+
// log table state to console
|
|
434
|
+
console.log(tableState);
|
|
435
|
+
// save table state to local storage
|
|
436
|
+
localStorage.setItem('hotkey_table_state_temp', JSON.stringify(tableState));
|
|
437
|
+
// copy table state to clipboard
|
|
438
|
+
navigator.clipboard.writeText(JSON.stringify(tableState));
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
442
|
+
return () => {
|
|
443
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
333
444
|
};
|
|
334
|
-
}, [
|
|
445
|
+
}, [getTableState]);
|
|
335
446
|
return {
|
|
336
447
|
table,
|
|
337
448
|
globalFilter,
|
|
449
|
+
tableViews,
|
|
450
|
+
headerMenu,
|
|
338
451
|
setGlobalFilter,
|
|
452
|
+
resetToDefaultView,
|
|
453
|
+
applyTableState,
|
|
454
|
+
getTableState
|
|
339
455
|
};
|
|
340
456
|
};
|
|
341
457
|
|
|
342
458
|
const useCheckboxFilterStyles = makeStyles({
|
|
343
459
|
searchInput: {
|
|
344
|
-
width:
|
|
345
|
-
marginBottom:
|
|
346
|
-
marginLeft:
|
|
347
|
-
marginRight:
|
|
348
|
-
}
|
|
460
|
+
width: '90%',
|
|
461
|
+
marginBottom: '8px',
|
|
462
|
+
marginLeft: '10px',
|
|
463
|
+
marginRight: '10px',
|
|
464
|
+
},
|
|
465
|
+
searchContainer: Object.assign(Object.assign({ display: 'flex', flexDirection: 'column', maxHeight: '300px', width: '100%' }, shorthands.overflow('auto', 'auto')), { '::-webkit-scrollbar': Object.assign({ width: '6px', height: '4px' }, shorthands.borderRadius('50%')),
|
|
466
|
+
/* Track */
|
|
467
|
+
'::-webkit-scrollbar-track': {
|
|
468
|
+
'background-color': '#f1f1f1',
|
|
469
|
+
},
|
|
470
|
+
/* Handle */
|
|
471
|
+
'::-webkit-scrollbar-thumb': {
|
|
472
|
+
'background-color': '#888',
|
|
473
|
+
},
|
|
474
|
+
/* Handle on hover */
|
|
475
|
+
'::-webkit-scrollbar-thumb:hover': {
|
|
476
|
+
'background-color': '#555',
|
|
477
|
+
} }),
|
|
349
478
|
});
|
|
350
|
-
const FilterMultiSelectCheckbox = ({ column, table }) => {
|
|
479
|
+
const FilterMultiSelectCheckbox = ({ column, table, }) => {
|
|
351
480
|
var _a, _b, _c;
|
|
352
481
|
const firstValue = (_a = table
|
|
353
482
|
.getPreFilteredRowModel()
|
|
@@ -355,18 +484,21 @@ const FilterMultiSelectCheckbox = ({ column, table }) => {
|
|
|
355
484
|
const columnFilterValue = column.getFilterValue();
|
|
356
485
|
const [filterOptions, setFilterOptions] = React.useState([]);
|
|
357
486
|
React.useEffect(() => {
|
|
358
|
-
const uniqueSortedOptions = typeof firstValue ===
|
|
359
|
-
Array.from(column.getFacetedUniqueValues().keys()).sort((a, b) => Number(a) - Number(b))
|
|
487
|
+
const uniqueSortedOptions = typeof firstValue === 'number' || !isNaN(firstValue)
|
|
488
|
+
? Array.from(column.getFacetedUniqueValues().keys()).sort((a, b) => Number(a) - Number(b))
|
|
360
489
|
: Array.from(column.getFacetedUniqueValues().keys()).sort();
|
|
361
490
|
setFilterOptions(uniqueSortedOptions);
|
|
362
491
|
},
|
|
363
492
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
364
493
|
[column.getFacetedUniqueValues()]);
|
|
365
|
-
const [localColumnFilterValue, setLocalColumnFilterValue] = React.useState(
|
|
494
|
+
const [localColumnFilterValue, setLocalColumnFilterValue] = React.useState('');
|
|
366
495
|
const filterOptionsFiltered = React.useMemo(() => {
|
|
367
496
|
if (!localColumnFilterValue)
|
|
368
497
|
return filterOptions;
|
|
369
|
-
return filterOptions.filter(option =>
|
|
498
|
+
return filterOptions.filter((option) => {
|
|
499
|
+
var _a, _b, _c;
|
|
500
|
+
return (_b = (_a = `${option}`) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes((_c = `${localColumnFilterValue}`) === null || _c === void 0 ? void 0 : _c.toLowerCase());
|
|
501
|
+
});
|
|
370
502
|
}, [localColumnFilterValue, filterOptions]);
|
|
371
503
|
const filterContainer = React.useRef(null);
|
|
372
504
|
const rowVirtualizer = useVirtual({
|
|
@@ -379,34 +511,58 @@ const FilterMultiSelectCheckbox = ({ column, table }) => {
|
|
|
379
511
|
const paddingBottom = virtualRows.length > 0
|
|
380
512
|
? totalSize - (((_c = virtualRows === null || virtualRows === void 0 ? void 0 : virtualRows[virtualRows.length - 1]) === null || _c === void 0 ? void 0 : _c.end) || 0)
|
|
381
513
|
: 0;
|
|
382
|
-
const allOptionChecked = (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) > 0 &&
|
|
514
|
+
const allOptionChecked = (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) > 0 &&
|
|
515
|
+
(columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) !== (filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length)
|
|
516
|
+
? 'mixed'
|
|
517
|
+
: (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) === (filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length) &&
|
|
518
|
+
(filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length) > 0;
|
|
383
519
|
const styles = useCheckboxFilterStyles();
|
|
384
|
-
return (jsxs("div", { children: [jsx(Input, { value: localColumnFilterValue, onChange: (_, data) => setLocalColumnFilterValue(data.value), placeholder: "Search Options...", size: "small", className: styles.searchInput }), jsxs("div", Object.assign({ ref: filterContainer, style: {
|
|
385
|
-
display: "flex",
|
|
386
|
-
flexDirection: "column",
|
|
387
|
-
maxHeight: "300px",
|
|
388
|
-
width: "100%",
|
|
389
|
-
overflow: "auto"
|
|
390
|
-
} }, { children: [paddingTop > 0 && jsx("span", { style: { paddingTop: `${paddingTop}px` } }), jsx(Checkbox, { checked: allOptionChecked, onChange: () => {
|
|
520
|
+
return (jsxs("div", { children: [jsx(Input, { type: 'search', value: localColumnFilterValue, onChange: (_, data) => setLocalColumnFilterValue(data.value), placeholder: "Search Options...", size: "small", className: styles.searchInput }), jsxs("div", Object.assign({ ref: filterContainer, className: styles.searchContainer }, { children: [paddingTop > 0 && (jsx("span", { style: { paddingTop: `${paddingTop}px` } })), jsx(Checkbox, { checked: allOptionChecked, onChange: () => {
|
|
391
521
|
if ((columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) > 0) {
|
|
392
522
|
column.setFilterValue(undefined);
|
|
393
523
|
return;
|
|
394
524
|
}
|
|
395
|
-
column.setFilterValue([
|
|
396
|
-
|
|
525
|
+
column.setFilterValue([
|
|
526
|
+
...((filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.map((x) => `${x}`)) || []),
|
|
527
|
+
]);
|
|
528
|
+
}, label: '(Toggle All)' }, `toggle-all-${column.id}`), virtualRows.map((row) => {
|
|
397
529
|
var _a;
|
|
398
530
|
const value = `${filterOptionsFiltered[row.index]}`;
|
|
399
531
|
return (jsx(Checkbox, { checked: (_a = columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.includes(value)) !== null && _a !== void 0 ? _a : false, onChange: () => {
|
|
400
532
|
if (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.includes(value)) {
|
|
401
|
-
column.setFilterValue((old) => old === null || old === void 0 ? void 0 : old.filter(v => v !== value));
|
|
533
|
+
column.setFilterValue((old) => old === null || old === void 0 ? void 0 : old.filter((v) => v !== value));
|
|
402
534
|
return;
|
|
403
535
|
}
|
|
404
|
-
column.setFilterValue((old) => [
|
|
536
|
+
column.setFilterValue((old) => [
|
|
537
|
+
...(old || []),
|
|
538
|
+
value,
|
|
539
|
+
]);
|
|
405
540
|
}, label: value }, `${column.id}-${row.index}`));
|
|
406
|
-
}), paddingBottom > 0 && jsx("span", { style: { paddingBottom: `${paddingBottom}px` } })] }),
|
|
541
|
+
}), paddingBottom > 0 && (jsx("span", { style: { paddingBottom: `${paddingBottom}px` } }))] }), 'filter-multi-select-checkbox')] }));
|
|
407
542
|
};
|
|
408
543
|
|
|
409
|
-
const
|
|
544
|
+
const useRadioFilterStyles = makeStyles({
|
|
545
|
+
searchInput: {
|
|
546
|
+
width: '90%',
|
|
547
|
+
marginBottom: '8px',
|
|
548
|
+
marginLeft: '10px',
|
|
549
|
+
marginRight: '10px',
|
|
550
|
+
},
|
|
551
|
+
searchContainer: Object.assign(Object.assign({ display: 'flex', flexDirection: 'column', maxHeight: '300px', width: '100%' }, shorthands.overflow('auto', 'auto')), { '::-webkit-scrollbar': Object.assign({ width: '6px', height: '4px' }, shorthands.borderRadius('50%')),
|
|
552
|
+
/* Track */
|
|
553
|
+
'::-webkit-scrollbar-track': {
|
|
554
|
+
'background-color': '#f1f1f1',
|
|
555
|
+
},
|
|
556
|
+
/* Handle */
|
|
557
|
+
'::-webkit-scrollbar-thumb': {
|
|
558
|
+
'background-color': '#888',
|
|
559
|
+
},
|
|
560
|
+
/* Handle on hover */
|
|
561
|
+
'::-webkit-scrollbar-thumb:hover': {
|
|
562
|
+
'background-color': '#555',
|
|
563
|
+
} }),
|
|
564
|
+
});
|
|
565
|
+
const FilterSelectRadio = ({ column, table, }) => {
|
|
410
566
|
var _a, _b, _c;
|
|
411
567
|
const firstValue = (_a = table
|
|
412
568
|
.getPreFilteredRowModel()
|
|
@@ -414,17 +570,26 @@ const FilterMultiSelectRadio = ({ column, table }) => {
|
|
|
414
570
|
const columnFilterValue = column.getFilterValue();
|
|
415
571
|
const [filterOptions, setFilterOptions] = React.useState([]);
|
|
416
572
|
React.useEffect(() => {
|
|
417
|
-
const uniqueSortedOptions = typeof firstValue ===
|
|
418
|
-
Array.from(column.getFacetedUniqueValues().keys()).sort((a, b) => Number(a) - Number(b))
|
|
573
|
+
const uniqueSortedOptions = typeof firstValue === 'number' || !isNaN(firstValue)
|
|
574
|
+
? Array.from(column.getFacetedUniqueValues().keys()).sort((a, b) => Number(a) - Number(b))
|
|
419
575
|
: Array.from(column.getFacetedUniqueValues().keys()).sort();
|
|
420
576
|
setFilterOptions(uniqueSortedOptions);
|
|
421
577
|
},
|
|
422
578
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
423
579
|
[column.getFacetedUniqueValues()]);
|
|
580
|
+
const [localColumnFilterValue, setLocalColumnFilterValue] = React.useState('');
|
|
581
|
+
const filterOptionsFiltered = React.useMemo(() => {
|
|
582
|
+
if (!localColumnFilterValue)
|
|
583
|
+
return filterOptions;
|
|
584
|
+
return filterOptions.filter((option) => {
|
|
585
|
+
var _a, _b, _c;
|
|
586
|
+
return (_b = (_a = `${option}`) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes((_c = `${localColumnFilterValue}`) === null || _c === void 0 ? void 0 : _c.toLowerCase());
|
|
587
|
+
});
|
|
588
|
+
}, [localColumnFilterValue, filterOptions]);
|
|
424
589
|
const filterContainer = React.useRef(null);
|
|
425
590
|
const rowVirtualizer = useVirtual({
|
|
426
591
|
parentRef: filterContainer,
|
|
427
|
-
size:
|
|
592
|
+
size: filterOptionsFiltered.length,
|
|
428
593
|
overscan: 15,
|
|
429
594
|
});
|
|
430
595
|
const { virtualItems: virtualRows, totalSize } = rowVirtualizer;
|
|
@@ -432,37 +597,211 @@ const FilterMultiSelectRadio = ({ column, table }) => {
|
|
|
432
597
|
const paddingBottom = virtualRows.length > 0
|
|
433
598
|
? totalSize - (((_c = virtualRows === null || virtualRows === void 0 ? void 0 : virtualRows[virtualRows.length - 1]) === null || _c === void 0 ? void 0 : _c.end) || 0)
|
|
434
599
|
: 0;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
600
|
+
const styles = useRadioFilterStyles();
|
|
601
|
+
return (jsxs("div", { children: [jsx(Input, { value: localColumnFilterValue, onChange: (_, data) => setLocalColumnFilterValue(data.value), placeholder: "Search Options...", size: "small", className: styles.searchInput }), jsxs("div", Object.assign({ ref: filterContainer, className: styles.searchContainer }, { children: [paddingTop > 0 && jsx("div", { style: { paddingTop: `${paddingTop}px` } }), jsxs(RadioGroup, Object.assign({ layout: "vertical", value: (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[0]) || '', onChange: (_, data) => {
|
|
602
|
+
if (data.value === '') {
|
|
603
|
+
column.setFilterValue([]);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
column.setFilterValue([data.value]);
|
|
607
|
+
} }, { children: [jsx(Radio, { value: '', label: 'None' }), virtualRows.map((row) => {
|
|
608
|
+
const value = filterOptionsFiltered[row.index];
|
|
609
|
+
return jsx(Radio, { value: value, label: value }, value);
|
|
610
|
+
})] })), paddingBottom > 0 && (jsx("div", { style: { paddingBottom: `${paddingBottom}px` } }))] }))] }));
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
const useNumberRangeFilterStyles$2 = makeStyles({
|
|
614
|
+
searchInput: {
|
|
615
|
+
width: '100%',
|
|
616
|
+
},
|
|
617
|
+
searchInputField: {
|
|
618
|
+
width: '100%',
|
|
619
|
+
flexGrow: 1,
|
|
620
|
+
},
|
|
621
|
+
searchContainer: {
|
|
622
|
+
display: 'flex',
|
|
623
|
+
marginBottom: '8px',
|
|
624
|
+
marginLeft: '10px',
|
|
625
|
+
marginRight: '10px',
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
const FilterNumberRange = (props) => {
|
|
629
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
630
|
+
const { column } = props;
|
|
631
|
+
const columnFilterValue = column.getFilterValue();
|
|
632
|
+
const min = Number((_b = (_a = column.getFacetedMinMaxValues()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '');
|
|
633
|
+
const max = Number((_d = (_c = column.getFacetedMinMaxValues()) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : '');
|
|
634
|
+
const handleMinChange = (e, data) => {
|
|
635
|
+
const value = Number(data.value);
|
|
636
|
+
column.setFilterValue((old) => [value, old === null || old === void 0 ? void 0 : old[1]]);
|
|
637
|
+
};
|
|
638
|
+
const handleMaxChange = (e, data) => {
|
|
639
|
+
const value = Number(data.value);
|
|
640
|
+
column.setFilterValue((old) => [old === null || old === void 0 ? void 0 : old[0], value]);
|
|
641
|
+
};
|
|
642
|
+
const styles = useNumberRangeFilterStyles$2();
|
|
643
|
+
return (jsxs("div", Object.assign({ className: styles.searchContainer }, { children: [jsx(Field, Object.assign({ label: 'Min:', size: "small", className: styles.searchInputField }, { children: jsx(Input, { type: "number", value: `${(columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[0]) || ''}`, min: min, max: max, onChange: handleMinChange, className: styles.searchInput, placeholder: `Min ${((_e = column.getFacetedMinMaxValues()) === null || _e === void 0 ? void 0 : _e[0])
|
|
644
|
+
? `(${(_f = column.getFacetedMinMaxValues()) === null || _f === void 0 ? void 0 : _f[0]})`
|
|
645
|
+
: ''}` }) })), jsx(Field, Object.assign({ label: 'Max:', size: "small", className: styles.searchInputField }, { children: jsx(Input, { type: "number", value: `${(columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[1]) || ''}`, min: min, max: max, onChange: handleMaxChange, className: styles.searchInput, placeholder: `Max ${((_g = column.getFacetedMinMaxValues()) === null || _g === void 0 ? void 0 : _g[1])
|
|
646
|
+
? `(${(_h = column.getFacetedMinMaxValues()) === null || _h === void 0 ? void 0 : _h[1]})`
|
|
647
|
+
: ''}` }) }))] })));
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
const useNumberRangeFilterStyles$1 = makeStyles({
|
|
651
|
+
searchInput: {
|
|
652
|
+
width: '100%',
|
|
653
|
+
},
|
|
654
|
+
searchInputField: {
|
|
655
|
+
width: '100%',
|
|
656
|
+
flexGrow: 1,
|
|
657
|
+
},
|
|
658
|
+
searchContainer: {
|
|
659
|
+
display: 'flex',
|
|
660
|
+
flexDirection: 'column',
|
|
661
|
+
marginBottom: '8px',
|
|
662
|
+
marginLeft: '10px',
|
|
663
|
+
marginRight: '10px',
|
|
664
|
+
},
|
|
665
|
+
});
|
|
666
|
+
const FilterDateRange = (props) => {
|
|
667
|
+
var _a, _b, _c, _d;
|
|
668
|
+
const { column } = props;
|
|
669
|
+
const columnFilterValue = column.getFilterValue();
|
|
670
|
+
const min = (_b = (_a = column.getFacetedMinMaxValues()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : undefined;
|
|
671
|
+
const max = (_d = (_c = column.getFacetedMinMaxValues()) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : undefined;
|
|
672
|
+
const handleMinChange = (date) => {
|
|
673
|
+
if (!date) {
|
|
674
|
+
column.setFilterValue((old) => [undefined, old === null || old === void 0 ? void 0 : old[1]]);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
column.setFilterValue((old) => [date, old === null || old === void 0 ? void 0 : old[1]]);
|
|
678
|
+
};
|
|
679
|
+
const handleMaxChange = (date) => {
|
|
680
|
+
if (!date) {
|
|
681
|
+
column.setFilterValue((old) => [old === null || old === void 0 ? void 0 : old[0], undefined]);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
column.setFilterValue((old) => [old === null || old === void 0 ? void 0 : old[0], date]);
|
|
685
|
+
};
|
|
686
|
+
const styles = useNumberRangeFilterStyles$1();
|
|
687
|
+
return (jsxs("div", Object.assign({ className: styles.searchContainer }, { children: [jsx(Field, Object.assign({ label: 'From Date:', size: "small", className: styles.searchInputField }, { children: jsx(DatePicker, { value: (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[0]) || null, min: min, max: max, onSelectDate: handleMinChange, className: styles.searchInput, placeholder: `From Date`, size: 'small', allowTextInput: true }) })), jsx(Field, Object.assign({ label: 'To Date:', size: "small", className: styles.searchInputField }, { children: jsx(DatePicker, { value: (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[1]) || null, min: min, max: max, onSelectDate: handleMaxChange, className: styles.searchInput, placeholder: `To Date`, size: 'small', allowTextInput: true }) }))] })));
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
const useNumberRangeFilterStyles = makeStyles({
|
|
691
|
+
searchInput: {
|
|
692
|
+
width: '100%',
|
|
693
|
+
},
|
|
694
|
+
searchInputField: {
|
|
695
|
+
width: '100%',
|
|
696
|
+
flexGrow: 1,
|
|
697
|
+
},
|
|
698
|
+
searchContainer: {
|
|
699
|
+
display: 'flex',
|
|
700
|
+
flexDirection: 'column',
|
|
701
|
+
marginBottom: '8px',
|
|
702
|
+
marginLeft: '10px',
|
|
703
|
+
marginRight: '10px',
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
const FilterDate = (props) => {
|
|
707
|
+
var _a, _b, _c, _d;
|
|
708
|
+
const { column } = props;
|
|
709
|
+
const columnFilterValue = column.getFilterValue();
|
|
710
|
+
const min = (_b = (_a = column.getFacetedMinMaxValues()) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : undefined;
|
|
711
|
+
const max = (_d = (_c = column.getFacetedMinMaxValues()) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : undefined;
|
|
712
|
+
const onDateSelect = (date) => {
|
|
713
|
+
if (!date) {
|
|
714
|
+
column.setFilterValue(undefined);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
column.setFilterValue(date);
|
|
718
|
+
};
|
|
719
|
+
const styles = useNumberRangeFilterStyles();
|
|
720
|
+
return (jsx("div", Object.assign({ className: styles.searchContainer }, { children: jsx(DatePicker, { value: columnFilterValue || null, min: min, max: max, onSelectDate: onDateSelect, className: styles.searchInput, placeholder: `Select a date`, size: 'small', allowTextInput: true }) })));
|
|
445
721
|
};
|
|
446
722
|
|
|
447
723
|
const useFilterStyles = makeStyles({
|
|
448
|
-
|
|
449
|
-
|
|
724
|
+
searchInput: {
|
|
725
|
+
width: '100%',
|
|
726
|
+
},
|
|
727
|
+
searchInputField: {
|
|
728
|
+
width: '100%',
|
|
729
|
+
flexGrow: 1,
|
|
730
|
+
},
|
|
731
|
+
searchContainer: {
|
|
732
|
+
display: 'flex',
|
|
733
|
+
marginBottom: '8px',
|
|
734
|
+
marginLeft: '10px',
|
|
735
|
+
marginRight: '10px',
|
|
736
|
+
},
|
|
450
737
|
});
|
|
451
|
-
const Filter = ({ column, table }) => {
|
|
452
|
-
var _a;
|
|
453
|
-
const
|
|
738
|
+
const Filter = ({ column, table, }) => {
|
|
739
|
+
var _a, _b;
|
|
740
|
+
const filterFunctionName = column.columnDef.filterFn;
|
|
454
741
|
const styles = useFilterStyles();
|
|
455
|
-
switch (
|
|
456
|
-
case
|
|
457
|
-
return
|
|
458
|
-
case
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
742
|
+
switch (filterFunctionName) {
|
|
743
|
+
case 'arrIncludesSome':
|
|
744
|
+
return jsx(FilterMultiSelectCheckbox, { column: column, table: table });
|
|
745
|
+
case 'arrIncludesAll':
|
|
746
|
+
case 'arrIncludes':
|
|
747
|
+
return jsx(FilterSelectRadio, { column: column, table: table });
|
|
748
|
+
case 'inNumberRange':
|
|
749
|
+
return jsx(FilterNumberRange, { column: column, table: table });
|
|
750
|
+
case 'inDateRange': {
|
|
751
|
+
const firstValue = (_a = table
|
|
752
|
+
.getPreFilteredRowModel()
|
|
753
|
+
.flatRows[0]) === null || _a === void 0 ? void 0 : _a.getValue(column.id);
|
|
754
|
+
if (typeof firstValue.getMonth === 'function') {
|
|
755
|
+
return jsx(FilterDateRange, { column: column, table: table });
|
|
756
|
+
}
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
case 'matchDate': {
|
|
760
|
+
const firstValue = (_b = table
|
|
761
|
+
.getPreFilteredRowModel()
|
|
762
|
+
.flatRows[0]) === null || _b === void 0 ? void 0 : _b.getValue(column.id);
|
|
763
|
+
if (typeof firstValue.getMonth === 'function') {
|
|
764
|
+
return jsx(FilterDate, { column: column, table: table });
|
|
765
|
+
}
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
462
768
|
}
|
|
463
|
-
return (jsx("div", Object.assign({ className: styles.
|
|
464
|
-
|
|
465
|
-
|
|
769
|
+
return (jsx("div", Object.assign({ className: styles.searchContainer }, { children: jsx(Field, Object.assign({ size: 'small', className: styles.searchInputField }, { children: jsx(Input, { value: (column.getFilterValue() || ''), onChange: (_, data) => {
|
|
770
|
+
column.setFilterValue(data.value);
|
|
771
|
+
}, placeholder: "Search Keyword...", size: "small", className: styles.searchInput }) })) })));
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
const useFilterDrawerStyles$1 = makeStyles({
|
|
775
|
+
drawerBody: Object.assign(Object.assign({}, shorthands.overflow('hidden', 'auto')), {
|
|
776
|
+
/* width */
|
|
777
|
+
':hover': Object.assign({}, shorthands.overflow('auto', 'auto')), '::-webkit-scrollbar': Object.assign({ width: '6px', height: '4px' }, shorthands.borderRadius('50%')),
|
|
778
|
+
/* Track */
|
|
779
|
+
'::-webkit-scrollbar-track': {
|
|
780
|
+
'background-color': '#f1f1f1',
|
|
781
|
+
},
|
|
782
|
+
/* Handle */
|
|
783
|
+
'::-webkit-scrollbar-thumb': {
|
|
784
|
+
'background-color': '#888',
|
|
785
|
+
},
|
|
786
|
+
/* Handle on hover */
|
|
787
|
+
'::-webkit-scrollbar-thumb:hover': {
|
|
788
|
+
'background-color': '#555',
|
|
789
|
+
} }),
|
|
790
|
+
});
|
|
791
|
+
const FilterDrawer = ({ open, setOpen, table }) => {
|
|
792
|
+
const headerGroups = table.getHeaderGroups();
|
|
793
|
+
const styles = useFilterDrawerStyles$1();
|
|
794
|
+
return (jsxs(InlineDrawer, Object.assign({ position: "end", open: open, separator: true }, { children: [jsx(DrawerHeader, { children: jsx(DrawerHeaderTitle, Object.assign({ action: jsx(Button, { appearance: "subtle", "aria-label": "Close", icon: jsx(Dismiss24Regular, {}), onClick: () => setOpen(false) }) }, { children: "Advance Filters" })) }), jsx(DrawerBody, Object.assign({ className: styles.drawerBody }, { children: headerGroups.map((headerGroup) => {
|
|
795
|
+
const canApplyFilter = headerGroup.depth === (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1;
|
|
796
|
+
if (!canApplyFilter)
|
|
797
|
+
return null;
|
|
798
|
+
return headerGroup.headers.map((header) => {
|
|
799
|
+
const canFilter = header.column.getCanFilter();
|
|
800
|
+
if (!canFilter)
|
|
801
|
+
return null;
|
|
802
|
+
return (jsx("div", { children: header.column.getCanFilter() && (jsxs("div", { children: [jsxs(Caption1Stronger, { children: ["Filter by", ' ', flexRender(header.column.columnDef.header, header.getContext())] }), jsx(Filter, { column: header.column, table: table })] }, 'filter-group')) }, header.column.id));
|
|
803
|
+
});
|
|
804
|
+
}) }))] })));
|
|
466
805
|
};
|
|
467
806
|
|
|
468
807
|
const SortAscIcon = bundleIcon(ArrowSortDown20Filled, ArrowSortDown20Regular);
|
|
@@ -510,18 +849,20 @@ const HeaderCell = ({ header, table, hideMenu, headerDepth, totalNumberOfHeaderD
|
|
|
510
849
|
const styles = useTableHeaderCellStyles();
|
|
511
850
|
return (jsxs("th", Object.assign({ colSpan: header.colSpan, style: {
|
|
512
851
|
opacity: isDragging ? 0.5 : 1,
|
|
513
|
-
cursor: isDragging ?
|
|
514
|
-
alignItems: headerDepth === totalNumberOfHeaderDepth ?
|
|
852
|
+
cursor: isDragging ? 'grabbing' : 'pointer',
|
|
853
|
+
alignItems: headerDepth === totalNumberOfHeaderDepth ? 'left' : 'center',
|
|
515
854
|
zIndex: 99,
|
|
516
|
-
backgroundColor: isOver ?
|
|
517
|
-
border: isOver ?
|
|
518
|
-
}, className: styles.tHeadCell }, { children: [jsx("div", Object.assign({ ref: dragRef }, { children: jsxs("div", Object.assign({ className: styles.tHeadCellContent, ref: dropRef }, { children: [jsx("div", Object.assign({ ref: previewRef }, { children: header.isPlaceholder ? null : (jsxs(Button, Object.assign({ style: {
|
|
519
|
-
display:
|
|
520
|
-
alignItems:
|
|
521
|
-
justifyContent:
|
|
855
|
+
backgroundColor: isOver ? '#0000000d' : 'transparent',
|
|
856
|
+
border: isOver ? '1px dashed #0000000d' : 'none',
|
|
857
|
+
}, className: styles.tHeadCell }, { children: [jsx("div", Object.assign({ ref: header.isPlaceholder ? undefined : dragRef }, { children: jsxs("div", Object.assign({ className: styles.tHeadCellContent, ref: header.isPlaceholder ? undefined : dropRef }, { children: [jsx("div", Object.assign({ ref: header.isPlaceholder ? undefined : previewRef }, { children: header.isPlaceholder ? null : (jsxs(Button, Object.assign({ style: {
|
|
858
|
+
display: 'flex',
|
|
859
|
+
alignItems: 'center',
|
|
860
|
+
justifyContent: 'left',
|
|
522
861
|
flex: 1,
|
|
523
862
|
}, onClick: (e) => {
|
|
524
|
-
|
|
863
|
+
if (!header.column.getCanSort())
|
|
864
|
+
return;
|
|
865
|
+
header.column.toggleSorting(header.column.getIsSorted() === 'asc', e.ctrlKey);
|
|
525
866
|
}, onDoubleClick: () => {
|
|
526
867
|
if (!header.column.getCanGroup())
|
|
527
868
|
return;
|
|
@@ -529,24 +870,28 @@ const HeaderCell = ({ header, table, hideMenu, headerDepth, totalNumberOfHeaderD
|
|
|
529
870
|
}, appearance: "transparent", className: styles.tHeadContentBtn, icon: (_a = {
|
|
530
871
|
asc: (jsx("strong", { children: jsx(SortAscIcon, {}) })),
|
|
531
872
|
desc: (jsx("strong", { children: jsx(SortDescIcon, {}) })),
|
|
532
|
-
}[header.column.getIsSorted()]) !== null && _a !== void 0 ? _a : undefined, iconPosition: "after" }, { children: [jsx("strong", { children: flexRender(header.column.columnDef.header, header.getContext()) }), header.column.getIsGrouped() && jsx(GroupListRegular, {}), header.column.getIsFiltered() && (jsx("strong", { children: jsx(FilterFilled, {}) })), header.column.getIsPinned() && jsx(PinRegular, {})] }))) })), !header.isPlaceholder &&
|
|
873
|
+
}[header.column.getIsSorted()]) !== null && _a !== void 0 ? _a : undefined, iconPosition: "after" }, { children: [jsx("strong", { children: flexRender(header.column.columnDef.header, header.getContext()) }), header.column.getIsGrouped() && jsx(GroupListRegular, {}), header.column.getIsFiltered() && (jsx("strong", { children: jsx(FilterFilled, {}) })), header.column.getIsPinned() && jsx(PinRegular, {})] }))) })), !header.isPlaceholder &&
|
|
874
|
+
!hideMenu &&
|
|
875
|
+
(header.column.getCanSort() ||
|
|
876
|
+
header.column.getCanGroup() ||
|
|
877
|
+
header.column.getCanFilter()) && (jsx("div", { children: jsxs(Menu, { children: [jsx(MenuTrigger, Object.assign({ disableButtonEnhancement: true }, { children: jsx(MenuButton, { appearance: "transparent", "aria-label": "View Column Actions" }) })), jsx(MenuPopover, Object.assign({ className: styles.tHeadMenuPopover }, { children: jsxs(MenuList, { children: [header.column.getCanSort() && (jsxs(MenuGroup, { children: [jsxs(MenuGroupHeader, { children: ["Sort by", ' ', flexRender(header.column.columnDef.header, header.getContext())] }), jsx(MenuItem, Object.assign({ onClick: (e) => {
|
|
533
878
|
var _a;
|
|
534
879
|
const isControlKeySelected = e.ctrlKey;
|
|
535
880
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.toggleSorting(false, isControlKeySelected);
|
|
536
|
-
}, icon: jsx(TextSortAscendingFilled, {}), disabled: header.column.getIsSorted() ===
|
|
881
|
+
}, icon: jsx(TextSortAscendingFilled, {}), disabled: header.column.getIsSorted() === 'asc' }, { children: "Sort A to Z" })), jsx(MenuItem, Object.assign({ onClick: (e) => {
|
|
537
882
|
var _a;
|
|
538
883
|
const isControlKeySelected = e.ctrlKey;
|
|
539
884
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.toggleSorting(true, isControlKeySelected);
|
|
540
|
-
}, icon: jsx(TextSortDescendingFilled, {}), disabled: header.column.getIsSorted() ===
|
|
885
|
+
}, icon: jsx(TextSortDescendingFilled, {}), disabled: header.column.getIsSorted() === 'desc' }, { children: "Sort Z to A" })), jsx(MenuDivider, {})] }, 'sort-group')), header.column.getCanGroup() && (jsxs(MenuGroup, { children: [jsxs(MenuGroupHeader, { children: ["Group by", ' ', flexRender(header.column.columnDef.header, header.getContext())] }), !header.column.getIsGrouped() && (jsxs(MenuItem, Object.assign({ onClick: () => header.column.getToggleGroupingHandler()(), icon: jsx(GroupFilled, {}) }, { children: ["Group by", ' ', flexRender(header.column.columnDef.header, header.getContext())] }))), header.column.getIsGrouped() && (jsxs(MenuItem, Object.assign({ onClick: () => header.column.getToggleGroupingHandler()(), icon: jsx(GroupDismissFilled, {}) }, { children: ["Remove Grouping on", ' ', flexRender(header.column.columnDef.header, header.getContext())] }))), jsx(MenuDivider, {})] }, 'grouping-group')), header.column.getCanSort() && (jsxs(MenuGroup, { children: [jsxs(MenuGroupHeader, { children: ["Pin Column", ' ', flexRender(header.column.columnDef.header, header.getContext())] }), jsx(MenuItem, Object.assign({ onClick: () => {
|
|
541
886
|
var _a;
|
|
542
|
-
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(
|
|
543
|
-
}, icon: jsx(ArrowStepInLeftRegular, {}), disabled: header.column.getIsPinned() ===
|
|
887
|
+
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin('left');
|
|
888
|
+
}, icon: jsx(ArrowStepInLeftRegular, {}), disabled: header.column.getIsPinned() === 'left' }, { children: "To Left" })), jsx(MenuItem, Object.assign({ onClick: () => {
|
|
544
889
|
var _a;
|
|
545
|
-
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(
|
|
546
|
-
}, icon: jsx(ArrowStepInRightRegular, {}), disabled: header.column.getIsPinned() ===
|
|
890
|
+
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin('right');
|
|
891
|
+
}, icon: jsx(ArrowStepInRightRegular, {}), disabled: header.column.getIsPinned() === 'right' }, { children: "To Right" })), ['left', 'right'].includes(header.column.getIsPinned()) && (jsx(MenuItem, Object.assign({ onClick: () => {
|
|
547
892
|
var _a;
|
|
548
893
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(false);
|
|
549
|
-
}, icon: jsx(PinOffRegular, {}) }, { children: "Unpin Column" }))), jsx(MenuDivider, {})] },
|
|
894
|
+
}, icon: jsx(PinOffRegular, {}) }, { children: "Unpin Column" }))), jsx(MenuDivider, {})] }, 'pin columns')), header.column.getCanFilter() && (jsxs(MenuGroup, { children: [jsxs(MenuGroupHeader, { children: ["Filter by", ' ', flexRender(header.column.columnDef.header, header.getContext())] }), jsx(Filter, { column: header.column, table: table })] }, 'filter-group'))] }) }))] }) }))] })) })), header.column.getCanResize() && (jsx("div", { onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), className: mergeClasses(styles.resizer, column.getIsResizing() && styles.resizerActive) }))] })));
|
|
550
895
|
};
|
|
551
896
|
|
|
552
897
|
const useLoadingStyles = makeStyles({
|
|
@@ -624,62 +969,141 @@ const TableContainer = (props) => {
|
|
|
624
969
|
: 0;
|
|
625
970
|
const headerGroups = table.getHeaderGroups();
|
|
626
971
|
// utilities
|
|
627
|
-
const isLoading = props.isLoading && virtualRows.length
|
|
628
|
-
const noItems = !isLoading && ((_c = props.data) === null || _c === void 0 ? void 0 : _c.length)
|
|
629
|
-
const noSearchResult = !isLoading && ((_d = props === null || props === void 0 ? void 0 : props.data) === null || _d === void 0 ? void 0 : _d.length) > 0 && virtualRows.length
|
|
630
|
-
return (
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
972
|
+
const isLoading = props.isLoading && virtualRows.length === 0;
|
|
973
|
+
const noItems = !isLoading && ((_c = props.data) === null || _c === void 0 ? void 0 : _c.length) === 0;
|
|
974
|
+
const noSearchResult = !isLoading && ((_d = props === null || props === void 0 ? void 0 : props.data) === null || _d === void 0 ? void 0 : _d.length) > 0 && virtualRows.length === 0;
|
|
975
|
+
return (jsxs("div", Object.assign({ ref: tableContainerRef, className: styles.tableContainer }, { children: [jsxs("table", Object.assign({ className: styles.table, "aria-label": "Data Grid" }, { children: [jsx("thead", Object.assign({ className: styles.tHead }, { children: headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.map((headerGroup) => (jsxs("tr", { children: [rowSelectionMode === 'multiple' && (jsx("th", Object.assign({ style: { width: '1rem' }, "aria-label": "Select All Row Column" }, { children: headerGroup.depth === (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1 && (jsx(Checkbox, { checked: table.getIsSomeRowsSelected()
|
|
976
|
+
? 'mixed'
|
|
977
|
+
: table.getIsAllRowsSelected(), onChange: table.getToggleAllRowsSelectedHandler(), "aria-label": "Select All Rows", title: 'Select All Rows' })) }))), rowSelectionMode === 'single' && (jsx("th", Object.assign({ style: { width: '1rem' }, "aria-label": "Select All Row Column" }, { children: ' ' }))), headerGroup.headers.map((header) => {
|
|
978
|
+
return (jsx(HeaderCell, { header: header, table: table, hideMenu: headerGroup.depth !== (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1, headerDepth: headerGroup.depth, totalNumberOfHeaderDepth: (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1 }, header.id));
|
|
979
|
+
})] }, headerGroup.id))) })), jsxs("tbody", Object.assign({ className: styles.tBody }, { children: [paddingTop > 0 && (jsx("tr", Object.assign({ className: styles.tBodyRow, "aria-hidden": true }, { children: jsx("td", { style: { height: `${paddingTop}px` } }) }))), virtualRows.map((virtualRow) => {
|
|
980
|
+
const row = rows[virtualRow.index];
|
|
981
|
+
return (jsxs("tr", Object.assign({ className: row.getIsSelected() || row.getIsAllSubRowsSelected()
|
|
982
|
+
? styles.tBodySelectedRow
|
|
983
|
+
: styles.tBodyRow }, { children: [rowSelectionMode === 'multiple' && (jsx("td", Object.assign({ className: styles.tBodyCell, "aria-label": "Select Row Column" }, { children: jsx(Checkbox, { checked: row.getIsSomeSelected()
|
|
984
|
+
? 'mixed'
|
|
985
|
+
: row.getIsSelected() || row.getIsAllSubRowsSelected(), disabled: !row.getCanSelect(), onChange: row.getToggleSelectedHandler(), "aria-label": "Select Row" }) }))), rowSelectionMode === 'single' && (jsx("td", Object.assign({ className: styles.tBodyCell, "aria-label": "Select Row Column" }, { children: jsx(Radio, { checked: row.getIsSelected(), disabled: !row.getCanSelect(), onChange: row.getToggleSelectedHandler(), "aria-label": "Select Row" }) }))), row.getVisibleCells().map((cell) => {
|
|
986
|
+
var _a;
|
|
987
|
+
return (jsx("td", Object.assign({}, {
|
|
988
|
+
key: cell.id,
|
|
989
|
+
style: {
|
|
990
|
+
// background: cell.getIsGrouped()
|
|
991
|
+
// ? "#0aff0082"
|
|
992
|
+
// : cell.getIsAggregated()
|
|
993
|
+
// ? "#ffa50078"
|
|
994
|
+
// : cell.getIsPlaceholder()
|
|
995
|
+
// ? "#ff000042"
|
|
996
|
+
// : "white",
|
|
997
|
+
width: cell.column.getSize(),
|
|
998
|
+
},
|
|
999
|
+
}, { className: styles.tBodyCell }, { children: cell.getIsGrouped() ? (
|
|
1000
|
+
// If it's a grouped cell, add an expander and row count
|
|
1001
|
+
jsx(Button, Object.assign({}, {
|
|
1002
|
+
onClick: row.getToggleExpandedHandler(),
|
|
645
1003
|
style: {
|
|
646
|
-
|
|
647
|
-
// ? "#0aff0082"
|
|
648
|
-
// : cell.getIsAggregated()
|
|
649
|
-
// ? "#ffa50078"
|
|
650
|
-
// : cell.getIsPlaceholder()
|
|
651
|
-
// ? "#ff000042"
|
|
652
|
-
// : "white",
|
|
653
|
-
width: cell.column.getSize(),
|
|
1004
|
+
cursor: row.getCanExpand() ? 'pointer' : 'normal',
|
|
654
1005
|
},
|
|
655
|
-
}, {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
1006
|
+
}, { appearance: "transparent", icon: row.getIsExpanded() ? (jsx(GroupExpandedIcon, {})) : (jsx(GroupCollapsedIcon, {})) }, { children: jsxs("strong", { children: [flexRender(cell.column.columnDef.cell, cell.getContext()), ' ', "(", row.subRows.length, ")"] }) }))) : cell.getIsAggregated() ? (
|
|
1007
|
+
// If the cell is aggregated, use the Aggregated
|
|
1008
|
+
// renderer for cell
|
|
1009
|
+
jsx("strong", { children: flexRender((_a = cell.column.columnDef.aggregatedCell) !== null && _a !== void 0 ? _a : cell.column.columnDef.cell, cell.getContext()) })) : cell.getIsPlaceholder() ? null : ( // For cells with repeated values, render null
|
|
1010
|
+
// Otherwise, just render the regular cell
|
|
1011
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())) })));
|
|
1012
|
+
})] }), row.id));
|
|
1013
|
+
}), paddingBottom > 0 && (jsx("tr", Object.assign({ className: styles.tBodyRow, "aria-hidden": true }, { children: jsx("td", { style: { height: `${paddingBottom}px` } }) })))] })), rowSelectionMode === 'multiple' &&
|
|
1014
|
+
!isLoading &&
|
|
1015
|
+
!noItems &&
|
|
1016
|
+
!noSearchResult && (jsx("tfoot", Object.assign({ className: styles.tFoot }, { children: jsxs("tr", { children: [jsx("td", Object.assign({ className: "p-1" }, { children: jsx(Checkbox, { checked: table.getIsSomePageRowsSelected()
|
|
1017
|
+
? 'mixed'
|
|
1018
|
+
: table.getIsAllPageRowsSelected(), onChange: table.getToggleAllPageRowsSelectedHandler(), "aria-label": "Select All Current Page Rows", title: 'Select All Current Page Rows' }) })), jsxs("td", Object.assign({ colSpan: 20 }, { children: [table.getIsAllPageRowsSelected() ? 'Unselect' : 'Select', " All Current Page Rows (", table.getRowModel().rows.length, ")"] }))] }) })))] })), isLoading && jsx(Loading, {}), noItems && jsx(NoItemGrid, { message: props.noItemPage }), noSearchResult && jsx(NoSearchResult, { message: props.noFilterMatchPage })] })));
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const ViewSaveForm = (props) => {
|
|
1022
|
+
const [errorMessage, setErrorMessage] = React.useState('');
|
|
1023
|
+
const [isFormOpen, setIsFormOpen] = React.useState(false);
|
|
1024
|
+
const inputRef = React.useRef(null);
|
|
1025
|
+
const checkboxRef = React.useRef(null);
|
|
1026
|
+
if (!isFormOpen) {
|
|
1027
|
+
return (jsxs(Fragment, { children: [jsx(MenuList, { children: jsx(MenuItemRadio, Object.assign({ name: 'view-manager', value: 'View Manager', onClick: () => setIsFormOpen(true), icon: jsx(Save20Filled, {}) }, { children: "Save Current View" })) }), jsx(Divider, {})] }));
|
|
1028
|
+
}
|
|
1029
|
+
return (jsxs("div", Object.assign({ style: {
|
|
1030
|
+
boxSizing: 'border-box',
|
|
1031
|
+
padding: '0.4rem',
|
|
1032
|
+
border: '1px solid #ccc',
|
|
1033
|
+
marginBottom: '0.5rem'
|
|
1034
|
+
} }, { children: [jsx(Caption1Stronger, { children: "Enter View Details" }), jsx(Field, Object.assign({ label: "View Name", validationMessage: errorMessage, validationState: errorMessage ? "error" : undefined, hint: jsx(Fragment, { children: "Give your view a name and save it." }) }, { children: jsx(Input, { ref: inputRef, placeholder: "View Name" }) })), jsx(Field, Object.assign({ hint: jsx(Fragment, { children: "Global view is accessible to everybody in the system." }) }, { children: jsx(Checkbox, { ref: checkboxRef, label: "Set as global view" }) })), jsxs("div", Object.assign({ style: {
|
|
1035
|
+
display: 'flex',
|
|
1036
|
+
flexWrap: 'wrap',
|
|
1037
|
+
gap: '0.5rem'
|
|
1038
|
+
} }, { children: [jsx(Button, Object.assign({ onClick: () => {
|
|
1039
|
+
setIsFormOpen(false);
|
|
1040
|
+
setErrorMessage('');
|
|
1041
|
+
} }, { children: "Cancel" })), jsx(Button, Object.assign({ appearance: 'primary', onClick: () => {
|
|
1042
|
+
var _a, _b, _c;
|
|
1043
|
+
if (!((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
1044
|
+
setErrorMessage('View name is required');
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
const viewName = inputRef.current.value;
|
|
1048
|
+
const isGlobal = (_b = checkboxRef.current) === null || _b === void 0 ? void 0 : _b.checked;
|
|
1049
|
+
const tableView = {
|
|
1050
|
+
id: Math.random() * 100,
|
|
1051
|
+
viewName: viewName,
|
|
1052
|
+
tableState: props.getTableState(),
|
|
1053
|
+
isGlobal: isGlobal,
|
|
1054
|
+
isViewOwner: true
|
|
1055
|
+
};
|
|
1056
|
+
(_c = props === null || props === void 0 ? void 0 : props.onSave) === null || _c === void 0 ? void 0 : _c.call(props, tableView);
|
|
1057
|
+
setErrorMessage('');
|
|
1058
|
+
setIsFormOpen(false);
|
|
1059
|
+
} }, { children: "Save" }))] }))] })));
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
const useFilterDrawerStyles = makeStyles({
|
|
1063
|
+
drawerBody: Object.assign(Object.assign({}, shorthands.overflow('hidden', 'auto')), {
|
|
1064
|
+
/* width */
|
|
1065
|
+
':hover': Object.assign({}, shorthands.overflow('auto', 'auto')), '::-webkit-scrollbar': Object.assign({ width: '6px', height: '4px' }, shorthands.borderRadius('50%')),
|
|
1066
|
+
/* Track */
|
|
1067
|
+
'::-webkit-scrollbar-track': {
|
|
1068
|
+
'background-color': '#f1f1f1',
|
|
1069
|
+
},
|
|
1070
|
+
/* Handle */
|
|
1071
|
+
'::-webkit-scrollbar-thumb': {
|
|
1072
|
+
'background-color': '#888',
|
|
1073
|
+
},
|
|
1074
|
+
/* Handle on hover */
|
|
1075
|
+
'::-webkit-scrollbar-thumb:hover': {
|
|
1076
|
+
'background-color': '#555',
|
|
1077
|
+
} }),
|
|
1078
|
+
});
|
|
1079
|
+
const ViewsDrawer = (props) => {
|
|
1080
|
+
const { open, setOpen, table, tableViews, applyTableState, resetToGridDefaultView, getTableState, onTableViewSave } = props;
|
|
1081
|
+
const styles = useFilterDrawerStyles();
|
|
1082
|
+
const [checkedValues, setCheckedValues] = React.useState({ font: ["calibri"] });
|
|
1083
|
+
const onChange = (e, { name, checkedItems }) => {
|
|
1084
|
+
setCheckedValues((s) => (Object.assign(Object.assign({}, s), { [name]: checkedItems })));
|
|
1085
|
+
};
|
|
1086
|
+
const resetAllFilters = React.useCallback(() => {
|
|
1087
|
+
table.setGlobalFilter('');
|
|
1088
|
+
table.resetColumnFilters();
|
|
1089
|
+
}, [table]);
|
|
1090
|
+
const resetAllGrouping = React.useCallback(() => {
|
|
1091
|
+
table.resetGrouping();
|
|
1092
|
+
}, [table]);
|
|
1093
|
+
const clearAllSelection = React.useCallback(() => {
|
|
1094
|
+
table.toggleAllRowsSelected(false);
|
|
1095
|
+
}, [table]);
|
|
1096
|
+
return (jsxs(InlineDrawer, Object.assign({ position: "end", open: open, separator: true }, { children: [jsx(DrawerHeader, { children: jsx(DrawerHeaderTitle, Object.assign({ action: jsx(Button, { appearance: "subtle", "aria-label": "Close", icon: jsx(Dismiss24Regular, {}), onClick: () => setOpen(false) }) }, { children: "Table Views" })) }), jsxs(DrawerBody, Object.assign({ className: styles.drawerBody }, { children: [onTableViewSave && jsx(ViewSaveForm, { mode: 'create', getTableState: getTableState, onSave: onTableViewSave }), jsxs(MenuList, Object.assign({ checkedValues: checkedValues, onCheckedValueChange: onChange }, { children: [jsx(MenuItemRadio, Object.assign({ name: 'table-views', value: 'Default View', icon: jsx(ViewDesktop20Filled, {}), onClick: resetToGridDefaultView }, { children: "Default View" })), tableViews.length > 0 && jsx(MenuDivider, { children: "Additional Views" }), tableViews.map((view) => {
|
|
1097
|
+
return (jsx(MenuItemRadio, Object.assign({ name: 'table-views', value: view.viewName, onClick: () => applyTableState(view.tableState), icon: jsx(ViewDesktop20Regular, {}) }, { children: view.viewName }), view.id));
|
|
1098
|
+
})] }))] })), jsx(DrawerFooter, { children: jsxs(MenuList, { children: [jsx(MenuDivider, {}), jsx(MenuItem, Object.assign({ icon: jsx(ClearFilterIcon, {}), onClick: resetAllFilters }, { children: "Clear All Filters" })), jsx(MenuItem, Object.assign({ icon: jsx(ClearFilterIcon, {}), onClick: resetAllGrouping }, { children: "Clear All Grouping" })), jsx(MenuItem, Object.assign({ icon: jsx(ClearFilterIcon, {}), onClick: clearAllSelection }, { children: "Clear All Selection" }))] }) })] })));
|
|
677
1099
|
};
|
|
678
1100
|
|
|
679
1101
|
function AdvancedTable(props, ref) {
|
|
680
|
-
const { table, globalFilter, setGlobalFilter } = useGridContainer(props, ref);
|
|
681
1102
|
useStaticStyles();
|
|
682
|
-
|
|
1103
|
+
const { table, globalFilter, headerMenu, tableViews, setGlobalFilter, resetToDefaultView, applyTableState, getTableState } = useGridContainer(props, ref);
|
|
1104
|
+
const [isFilterDrawerOpen, setIsFilterDrawerOpen] = React.useState(false);
|
|
1105
|
+
const [isViewsDrawerOpen, setIsViewsDrawerOpen] = React.useState(false);
|
|
1106
|
+
return (jsxs(DndProvider, Object.assign({ backend: HTML5Backend }, { children: [jsx(GridHeader, { table: table, gridTitle: props.gridTitle, headerMenu: headerMenu, globalFilter: globalFilter, openFilterDrawer: isFilterDrawerOpen, openViewsDrawer: isViewsDrawerOpen, setGlobalFilter: setGlobalFilter, setFilterDrawerOpen: setIsFilterDrawerOpen, setViewsDrawerOpen: setIsViewsDrawerOpen, applyTableState: applyTableState }), jsxs("div", Object.assign({ style: { display: 'flex' } }, { children: [jsx(TableContainer, { table: table, data: props.data, isLoading: props.isLoading || false, rowSelectionMode: props.rowSelectionMode, noFilterMatchPage: props.noFilterMatchPage, noItemPage: props.noItemPage }), jsx(FilterDrawer, { open: isFilterDrawerOpen, setOpen: setIsFilterDrawerOpen, table: table }), jsx(ViewsDrawer, { table: table, open: isViewsDrawerOpen, setOpen: setIsViewsDrawerOpen, tableViews: tableViews, applyTableState: applyTableState, resetToGridDefaultView: resetToDefaultView, getTableState: getTableState, onTableViewSave: props.onTableViewSave, onTableViewDelete: props.onTableViewDelete })] })), jsx(Pagination, { table: table, pageSizeOptions: props.pageSizeOptions })] })));
|
|
683
1107
|
}
|
|
684
1108
|
const ForwardedAdvancedTable = React.forwardRef(AdvancedTable);
|
|
685
1109
|
|