@prt-ts/fluent-react-table-v2 9.40.0-build.1.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 +440 -102
- package/package.json +2 -1
- 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/FilterNumberRange.d.ts +7 -0
- package/src/lib/components/filters/{FilterMultiSelectRadio.d.ts → FilterSelectRadio.d.ts} +1 -1
- package/src/lib/components/grid-header/GridHeader.d.ts +5 -1
- package/src/lib/components/useGridContainer.d.ts +9 -3
- 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/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
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,
|
|
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,33 +163,21 @@ const useGridHeaderStyles = makeStyles({
|
|
|
162
163
|
const GridHeader = (props) => {
|
|
163
164
|
const { table, gridTitle, globalFilter, setGlobalFilter } = props;
|
|
164
165
|
const styles = useGridHeaderStyles();
|
|
165
|
-
|
|
166
|
-
table.setGlobalFilter('');
|
|
167
|
-
table.resetColumnFilters();
|
|
168
|
-
}, [table]);
|
|
169
|
-
const resetAllGrouping = React.useCallback(() => {
|
|
170
|
-
table.resetGrouping();
|
|
171
|
-
}, [table]);
|
|
172
|
-
const clearAllSelection = React.useCallback(() => {
|
|
173
|
-
table.toggleAllRowsSelected(false);
|
|
174
|
-
}, [table]);
|
|
175
|
-
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" }), table.getAllLeafColumns().map((column) => {
|
|
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) => {
|
|
176
167
|
if (column.id === 'select')
|
|
177
168
|
return null;
|
|
178
169
|
if (column.id === 'id')
|
|
179
170
|
return null;
|
|
180
|
-
return (jsx(Checkbox, { checked: column.getIsGrouped(), onChange: column.getToggleGroupingHandler(), disabled: !column.getCanGroup(), label: jsx("span", { children: column.id }) }, column.id));
|
|
171
|
+
return (jsx(Checkbox, { checked: column.getIsGrouped(), onChange: column.getToggleGroupingHandler(), disabled: !column.getCanGroup() || !column.getIsVisible(), label: jsx("span", { children: column.columnDef.id }) }, column.id));
|
|
181
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) => {
|
|
182
173
|
if (column.id === 'select')
|
|
183
174
|
return null;
|
|
184
|
-
if (column.id === 'id')
|
|
185
|
-
return null;
|
|
186
175
|
return (jsx(Checkbox, { checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler(), label: column.id, disabled: !column.getCanHide() }, column.id));
|
|
187
|
-
})] })) })] })),
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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 })] }))] })));
|
|
192
181
|
};
|
|
193
182
|
// A debounced input react component
|
|
194
183
|
function DebouncedInput({ value: initialValue, onChange, debounce = 500, openFilterDrawer, setFilterDrawerOpen, }) {
|
|
@@ -202,7 +191,7 @@ function DebouncedInput({ value: initialValue, onChange, debounce = 500, openFil
|
|
|
202
191
|
}, debounce);
|
|
203
192
|
return () => clearTimeout(timeout);
|
|
204
193
|
}, [value, onChange, debounce]);
|
|
205
|
-
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", icon: openFilterDrawer ? jsx(FilterDismissFilled, {}) : jsx(FilterFilled, {}), "aria-label": "View Menu", onClick: () => {
|
|
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: () => {
|
|
206
195
|
setFilterDrawerOpen((open) => !open);
|
|
207
196
|
} }) }));
|
|
208
197
|
}
|
|
@@ -212,10 +201,57 @@ const arrIncludesSome = (row, columnId, value) => {
|
|
|
212
201
|
const rowValue = row.getValue(columnId);
|
|
213
202
|
const passed = Array.isArray(value) &&
|
|
214
203
|
((value === null || value === void 0 ? void 0 : value.length) === 0 || value.includes(`${rowValue}`));
|
|
215
|
-
// console.log("rowValue", rowValue, "value", value, "passed", passed, "columnId", columnId)
|
|
216
|
-
// Return if the item should be filtered in/out
|
|
217
204
|
return passed;
|
|
218
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
|
+
|
|
219
255
|
const useGridContainer = (props, ref) => {
|
|
220
256
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
221
257
|
const { columns, data, rowSelectionMode } = props;
|
|
@@ -225,21 +261,31 @@ const useGridContainer = (props, ref) => {
|
|
|
225
261
|
});
|
|
226
262
|
const [sorting, setSorting] = React.useState((_a = props.sortingState) !== null && _a !== void 0 ? _a : []);
|
|
227
263
|
const [columnFilters, setColumnFilters] = React.useState((_b = props.columnFilterState) !== null && _b !== void 0 ? _b : []);
|
|
228
|
-
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 : '');
|
|
229
265
|
const [grouping, setGrouping] = React.useState((_d = props.groupingState) !== null && _d !== void 0 ? _d : []);
|
|
230
266
|
const [rowSelection, setRowSelection] = React.useState((_e = props.rowSelectionState) !== null && _e !== void 0 ? _e : {});
|
|
231
267
|
const [columnVisibility, setColumnVisibility] = React.useState((_f = props.columnVisibility) !== null && _f !== void 0 ? _f : {});
|
|
232
|
-
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
|
+
});
|
|
233
275
|
const [expanded, setExpanded] = React.useState((_g = props.expandedState) !== null && _g !== void 0 ? _g : {});
|
|
234
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]);
|
|
235
279
|
const table = useReactTable({
|
|
236
280
|
columns: columns,
|
|
237
281
|
data,
|
|
238
282
|
filterFns: {
|
|
239
|
-
arrIncludesSome,
|
|
283
|
+
arrIncludesSome: arrIncludesSome,
|
|
284
|
+
inDateRange: dateRange,
|
|
285
|
+
matchDate: date,
|
|
240
286
|
},
|
|
241
287
|
initialState: {
|
|
242
|
-
expanded: true
|
|
288
|
+
expanded: true,
|
|
243
289
|
},
|
|
244
290
|
state: {
|
|
245
291
|
pagination,
|
|
@@ -252,10 +298,11 @@ const useGridContainer = (props, ref) => {
|
|
|
252
298
|
columnOrder,
|
|
253
299
|
columnVisibility,
|
|
254
300
|
columnPinning,
|
|
301
|
+
columnSizing,
|
|
255
302
|
},
|
|
256
|
-
columnResizeMode:
|
|
303
|
+
columnResizeMode: 'onChange',
|
|
257
304
|
enableRowSelection: rowSelectionMode !== undefined,
|
|
258
|
-
enableMultiRowSelection: rowSelectionMode ===
|
|
305
|
+
enableMultiRowSelection: rowSelectionMode === 'multiple',
|
|
259
306
|
enableFilters: true,
|
|
260
307
|
enableGlobalFilter: true,
|
|
261
308
|
enableColumnFilters: true,
|
|
@@ -271,6 +318,7 @@ const useGridContainer = (props, ref) => {
|
|
|
271
318
|
onExpandedChange: setExpanded,
|
|
272
319
|
onColumnVisibilityChange: setColumnVisibility,
|
|
273
320
|
onColumnPinningChange: setColumnPinning,
|
|
321
|
+
onColumnSizingChange: setColumnSizing,
|
|
274
322
|
getCoreRowModel: getCoreRowModel(),
|
|
275
323
|
getPaginationRowModel: getPaginationRowModel(),
|
|
276
324
|
getSortedRowModel: getSortedRowModel(),
|
|
@@ -292,6 +340,7 @@ const useGridContainer = (props, ref) => {
|
|
|
292
340
|
columnOrder,
|
|
293
341
|
columnVisibility,
|
|
294
342
|
columnPinning,
|
|
343
|
+
columnSizing
|
|
295
344
|
};
|
|
296
345
|
}, [
|
|
297
346
|
pagination,
|
|
@@ -304,43 +353,105 @@ const useGridContainer = (props, ref) => {
|
|
|
304
353
|
columnOrder,
|
|
305
354
|
columnVisibility,
|
|
306
355
|
columnPinning,
|
|
356
|
+
columnSizing
|
|
307
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
|
+
};
|
|
308
408
|
React.useImperativeHandle(ref, () => {
|
|
309
409
|
return {
|
|
310
410
|
table,
|
|
311
|
-
getTableState
|
|
312
|
-
|
|
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();
|
|
313
432
|
const tableState = getTableState();
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
setGrouping(tableState.grouping);
|
|
326
|
-
setExpanded(tableState.expanded);
|
|
327
|
-
setRowSelection(tableState.rowSelection);
|
|
328
|
-
setColumnOrder(tableState.columnOrder);
|
|
329
|
-
setColumnVisibility(tableState.columnVisibility);
|
|
330
|
-
setColumnPinning(tableState.columnPinning);
|
|
331
|
-
setTimeout(() => {
|
|
332
|
-
setPagination(tableState.pagination);
|
|
333
|
-
}, 10);
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
return false;
|
|
337
|
-
},
|
|
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);
|
|
338
444
|
};
|
|
339
|
-
}, [
|
|
445
|
+
}, [getTableState]);
|
|
340
446
|
return {
|
|
341
447
|
table,
|
|
342
448
|
globalFilter,
|
|
449
|
+
tableViews,
|
|
450
|
+
headerMenu,
|
|
343
451
|
setGlobalFilter,
|
|
452
|
+
resetToDefaultView,
|
|
453
|
+
applyTableState,
|
|
454
|
+
getTableState
|
|
344
455
|
};
|
|
345
456
|
};
|
|
346
457
|
|
|
@@ -406,7 +517,7 @@ const FilterMultiSelectCheckbox = ({ column, table, }) => {
|
|
|
406
517
|
: (columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) === (filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length) &&
|
|
407
518
|
(filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.length) > 0;
|
|
408
519
|
const styles = useCheckboxFilterStyles();
|
|
409
|
-
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("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: () => {
|
|
410
521
|
if ((columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue.length) > 0) {
|
|
411
522
|
column.setFilterValue(undefined);
|
|
412
523
|
return;
|
|
@@ -451,7 +562,7 @@ const useRadioFilterStyles = makeStyles({
|
|
|
451
562
|
'background-color': '#555',
|
|
452
563
|
} }),
|
|
453
564
|
});
|
|
454
|
-
const
|
|
565
|
+
const FilterSelectRadio = ({ column, table, }) => {
|
|
455
566
|
var _a, _b, _c;
|
|
456
567
|
const firstValue = (_a = table
|
|
457
568
|
.getPreFilteredRowModel()
|
|
@@ -459,8 +570,8 @@ const FilterMultiSelectRadio = ({ column, table }) => {
|
|
|
459
570
|
const columnFilterValue = column.getFilterValue();
|
|
460
571
|
const [filterOptions, setFilterOptions] = React.useState([]);
|
|
461
572
|
React.useEffect(() => {
|
|
462
|
-
const uniqueSortedOptions = typeof firstValue ===
|
|
463
|
-
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))
|
|
464
575
|
: Array.from(column.getFacetedUniqueValues().keys()).sort();
|
|
465
576
|
setFilterOptions(uniqueSortedOptions);
|
|
466
577
|
},
|
|
@@ -499,28 +610,168 @@ const FilterMultiSelectRadio = ({ column, table }) => {
|
|
|
499
610
|
})] })), paddingBottom > 0 && (jsx("div", { style: { paddingBottom: `${paddingBottom}px` } }))] }))] }));
|
|
500
611
|
};
|
|
501
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 }) })));
|
|
721
|
+
};
|
|
722
|
+
|
|
502
723
|
const useFilterStyles = makeStyles({
|
|
503
|
-
|
|
504
|
-
|
|
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
|
+
},
|
|
505
737
|
});
|
|
506
|
-
const Filter = ({ column, table }) => {
|
|
507
|
-
var _a;
|
|
508
|
-
const
|
|
738
|
+
const Filter = ({ column, table, }) => {
|
|
739
|
+
var _a, _b;
|
|
740
|
+
const filterFunctionName = column.columnDef.filterFn;
|
|
509
741
|
const styles = useFilterStyles();
|
|
510
|
-
switch (
|
|
511
|
-
case
|
|
512
|
-
return
|
|
513
|
-
case
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
+
}
|
|
517
768
|
}
|
|
518
|
-
return (jsx("div", Object.assign({ className: styles.
|
|
519
|
-
|
|
520
|
-
|
|
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 }) })) })));
|
|
521
772
|
};
|
|
522
773
|
|
|
523
|
-
const useFilterDrawerStyles = makeStyles({
|
|
774
|
+
const useFilterDrawerStyles$1 = makeStyles({
|
|
524
775
|
drawerBody: Object.assign(Object.assign({}, shorthands.overflow('hidden', 'auto')), {
|
|
525
776
|
/* width */
|
|
526
777
|
':hover': Object.assign({}, shorthands.overflow('auto', 'auto')), '::-webkit-scrollbar': Object.assign({ width: '6px', height: '4px' }, shorthands.borderRadius('50%')),
|
|
@@ -539,7 +790,7 @@ const useFilterDrawerStyles = makeStyles({
|
|
|
539
790
|
});
|
|
540
791
|
const FilterDrawer = ({ open, setOpen, table }) => {
|
|
541
792
|
const headerGroups = table.getHeaderGroups();
|
|
542
|
-
const styles = useFilterDrawerStyles();
|
|
793
|
+
const styles = useFilterDrawerStyles$1();
|
|
543
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) => {
|
|
544
795
|
const canApplyFilter = headerGroup.depth === (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1;
|
|
545
796
|
if (!canApplyFilter)
|
|
@@ -598,18 +849,20 @@ const HeaderCell = ({ header, table, hideMenu, headerDepth, totalNumberOfHeaderD
|
|
|
598
849
|
const styles = useTableHeaderCellStyles();
|
|
599
850
|
return (jsxs("th", Object.assign({ colSpan: header.colSpan, style: {
|
|
600
851
|
opacity: isDragging ? 0.5 : 1,
|
|
601
|
-
cursor: isDragging ?
|
|
602
|
-
alignItems: headerDepth === totalNumberOfHeaderDepth ?
|
|
852
|
+
cursor: isDragging ? 'grabbing' : 'pointer',
|
|
853
|
+
alignItems: headerDepth === totalNumberOfHeaderDepth ? 'left' : 'center',
|
|
603
854
|
zIndex: 99,
|
|
604
|
-
backgroundColor: isOver ?
|
|
605
|
-
border: isOver ?
|
|
606
|
-
}, 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: {
|
|
607
|
-
display:
|
|
608
|
-
alignItems:
|
|
609
|
-
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',
|
|
610
861
|
flex: 1,
|
|
611
862
|
}, onClick: (e) => {
|
|
612
|
-
|
|
863
|
+
if (!header.column.getCanSort())
|
|
864
|
+
return;
|
|
865
|
+
header.column.toggleSorting(header.column.getIsSorted() === 'asc', e.ctrlKey);
|
|
613
866
|
}, onDoubleClick: () => {
|
|
614
867
|
if (!header.column.getCanGroup())
|
|
615
868
|
return;
|
|
@@ -617,24 +870,28 @@ const HeaderCell = ({ header, table, hideMenu, headerDepth, totalNumberOfHeaderD
|
|
|
617
870
|
}, appearance: "transparent", className: styles.tHeadContentBtn, icon: (_a = {
|
|
618
871
|
asc: (jsx("strong", { children: jsx(SortAscIcon, {}) })),
|
|
619
872
|
desc: (jsx("strong", { children: jsx(SortDescIcon, {}) })),
|
|
620
|
-
}[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) => {
|
|
621
878
|
var _a;
|
|
622
879
|
const isControlKeySelected = e.ctrlKey;
|
|
623
880
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.toggleSorting(false, isControlKeySelected);
|
|
624
|
-
}, 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) => {
|
|
625
882
|
var _a;
|
|
626
883
|
const isControlKeySelected = e.ctrlKey;
|
|
627
884
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.toggleSorting(true, isControlKeySelected);
|
|
628
|
-
}, 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: () => {
|
|
629
886
|
var _a;
|
|
630
|
-
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(
|
|
631
|
-
}, 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: () => {
|
|
632
889
|
var _a;
|
|
633
|
-
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(
|
|
634
|
-
}, 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: () => {
|
|
635
892
|
var _a;
|
|
636
893
|
(_a = header.column) === null || _a === void 0 ? void 0 : _a.pin(false);
|
|
637
|
-
}, 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) }))] })));
|
|
638
895
|
};
|
|
639
896
|
|
|
640
897
|
const useLoadingStyles = makeStyles({
|
|
@@ -715,17 +972,17 @@ const TableContainer = (props) => {
|
|
|
715
972
|
const isLoading = props.isLoading && virtualRows.length === 0;
|
|
716
973
|
const noItems = !isLoading && ((_c = props.data) === null || _c === void 0 ? void 0 : _c.length) === 0;
|
|
717
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;
|
|
718
|
-
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' } }, { children: headerGroup.depth === (headerGroups === null || headerGroups === void 0 ? void 0 : headerGroups.length) - 1 && (jsx(Checkbox, { checked: table.getIsSomeRowsSelected()
|
|
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()
|
|
719
976
|
? 'mixed'
|
|
720
|
-
: table.getIsAllRowsSelected(), onChange: table.getToggleAllRowsSelectedHandler(), "aria-label": "Select All Rows", title: 'Select All Rows' })) }))), rowSelectionMode === 'single' && (jsx("th", Object.assign({ style: { width: '1rem' } }, { children:
|
|
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) => {
|
|
721
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));
|
|
722
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) => {
|
|
723
980
|
const row = rows[virtualRow.index];
|
|
724
981
|
return (jsxs("tr", Object.assign({ className: row.getIsSelected() || row.getIsAllSubRowsSelected()
|
|
725
982
|
? styles.tBodySelectedRow
|
|
726
|
-
: styles.tBodyRow }, { children: [rowSelectionMode === 'multiple' && (jsx("td", Object.assign({ className: styles.tBodyCell }, { children: jsx(Checkbox, { checked: row.getIsSomeSelected()
|
|
983
|
+
: styles.tBodyRow }, { children: [rowSelectionMode === 'multiple' && (jsx("td", Object.assign({ className: styles.tBodyCell, "aria-label": "Select Row Column" }, { children: jsx(Checkbox, { checked: row.getIsSomeSelected()
|
|
727
984
|
? 'mixed'
|
|
728
|
-
: row.getIsSelected() || row.getIsAllSubRowsSelected(), disabled: !row.getCanSelect(), onChange: row.getToggleSelectedHandler(), "aria-label": "Select Row" }) }))), rowSelectionMode === 'single' && (jsx("td", Object.assign({ className: styles.tBodyCell }, { children: jsx(Radio, { checked: row.getIsSelected(), disabled: !row.getCanSelect(), onChange: row.getToggleSelectedHandler(), "aria-label": "Select Row" }) }))), row.getVisibleCells().map((cell) => {
|
|
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) => {
|
|
729
986
|
var _a;
|
|
730
987
|
return (jsx("td", Object.assign({}, {
|
|
731
988
|
key: cell.id,
|
|
@@ -761,11 +1018,92 @@ const TableContainer = (props) => {
|
|
|
761
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 })] })));
|
|
762
1019
|
};
|
|
763
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" }))] }) })] })));
|
|
1099
|
+
};
|
|
1100
|
+
|
|
764
1101
|
function AdvancedTable(props, ref) {
|
|
765
|
-
const { table, globalFilter, setGlobalFilter } = useGridContainer(props, ref);
|
|
766
1102
|
useStaticStyles();
|
|
1103
|
+
const { table, globalFilter, headerMenu, tableViews, setGlobalFilter, resetToDefaultView, applyTableState, getTableState } = useGridContainer(props, ref);
|
|
767
1104
|
const [isFilterDrawerOpen, setIsFilterDrawerOpen] = React.useState(false);
|
|
768
|
-
|
|
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 })] })));
|
|
769
1107
|
}
|
|
770
1108
|
const ForwardedAdvancedTable = React.forwardRef(AdvancedTable);
|
|
771
1109
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prt-ts/fluent-react-table-v2",
|
|
3
|
-
"version": "9.40.0-build.
|
|
3
|
+
"version": "9.40.0-build.10.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./src\\index.d.ts",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"react": ">=17.0.0",
|
|
8
8
|
"react-dom": ">=17.0.0",
|
|
9
9
|
"@fluentui/react-components": ">=9.40.0",
|
|
10
|
+
"@fluentui/react-datepicker-compat": ">=0.4.5",
|
|
10
11
|
"@fluentui/react-icons": ">=2.0.221"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Column, Table } from
|
|
2
|
-
export declare const Filter: <TItem extends object>({ column, table }: {
|
|
1
|
+
import { Column, Table } from '@tanstack/react-table';
|
|
2
|
+
export declare const Filter: <TItem extends object>({ column, table, }: {
|
|
3
3
|
column: Column<TItem, unknown>;
|
|
4
4
|
table: Table<TItem>;
|
|
5
5
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Column, Table } from '@tanstack/react-table';
|
|
2
|
+
type FilterNumberRangeProps<TItem extends object> = {
|
|
3
|
+
column: Column<TItem, unknown>;
|
|
4
|
+
table: Table<TItem>;
|
|
5
|
+
};
|
|
6
|
+
export declare const FilterDate: <TItem extends object>(props: FilterNumberRangeProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Column, Table } from '@tanstack/react-table';
|
|
2
|
+
type FilterNumberRangeProps<TItem extends object> = {
|
|
3
|
+
column: Column<TItem, unknown>;
|
|
4
|
+
table: Table<TItem>;
|
|
5
|
+
};
|
|
6
|
+
export declare const FilterDateRange: <TItem extends object>(props: FilterNumberRangeProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Column, Table } from '@tanstack/react-table';
|
|
2
|
+
type FilterNumberRangeProps<TItem extends object> = {
|
|
3
|
+
column: Column<TItem, unknown>;
|
|
4
|
+
table: Table<TItem>;
|
|
5
|
+
};
|
|
6
|
+
export declare const FilterNumberRange: <TItem extends object>(props: FilterNumberRangeProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Column, Table } from "@tanstack/react-table";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const FilterSelectRadio: <TItem extends object>({ column, table, }: {
|
|
3
3
|
column: Column<TItem, unknown>;
|
|
4
4
|
table: Table<TItem>;
|
|
5
5
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Table } from '@tanstack/react-table';
|
|
2
|
+
import { Table, TableState } from '@tanstack/react-table';
|
|
3
3
|
type GridHeaderProps<TItem extends object> = {
|
|
4
4
|
table: Table<TItem>;
|
|
5
5
|
gridTitle: JSX.Element | React.ReactNode;
|
|
6
|
+
headerMenu?: JSX.Element | React.ReactNode;
|
|
6
7
|
globalFilter: string;
|
|
7
8
|
setGlobalFilter: (value: string) => void;
|
|
9
|
+
applyTableState: (tableState: Partial<TableState>) => boolean;
|
|
8
10
|
openFilterDrawer: boolean;
|
|
9
11
|
setFilterDrawerOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
12
|
+
openViewsDrawer: boolean;
|
|
13
|
+
setViewsDrawerOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
10
14
|
};
|
|
11
15
|
export declare const GridHeader: <TItem extends object>(props: GridHeaderProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
12
16
|
export {};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { TableState } from '@tanstack/react-table';
|
|
2
|
+
import { TableProps } from '..';
|
|
3
|
+
import { TableRef, TableView } from '../types';
|
|
4
|
+
import * as React from 'react';
|
|
4
5
|
export declare const useGridContainer: <TItem extends object>(props: TableProps<TItem>, ref: React.ForwardedRef<TableRef<TItem>>) => {
|
|
5
6
|
table: import("@tanstack/react-table").Table<TItem>;
|
|
6
7
|
globalFilter: string;
|
|
8
|
+
tableViews: TableView[];
|
|
9
|
+
headerMenu: JSX.Element | React.ReactNode;
|
|
7
10
|
setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
|
|
11
|
+
resetToDefaultView: () => boolean;
|
|
12
|
+
applyTableState: (tableState: Partial<TableState>) => boolean;
|
|
13
|
+
getTableState: () => Partial<TableState>;
|
|
8
14
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TableProps } from "../../types";
|
|
2
|
+
import { TableState } from '@tanstack/react-table';
|
|
3
|
+
type ViewSaveFormProps<TItem extends object> = {
|
|
4
|
+
mode: 'create' | 'edit';
|
|
5
|
+
onSave: TableProps<TItem>['onTableViewSave'];
|
|
6
|
+
getTableState: () => Partial<TableState>;
|
|
7
|
+
};
|
|
8
|
+
export declare const ViewSaveForm: <TItem extends object>(props: ViewSaveFormProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TableProps, TableView } from '../../types';
|
|
3
|
+
import { Table, TableState } from '@tanstack/react-table';
|
|
4
|
+
type ViewsDrawerProps<TItem extends object> = {
|
|
5
|
+
open: boolean;
|
|
6
|
+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
|
+
table: Table<TItem>;
|
|
8
|
+
tableViews: TableView[];
|
|
9
|
+
applyTableState: (tableView: Partial<TableState>) => void;
|
|
10
|
+
resetToGridDefaultView: () => boolean;
|
|
11
|
+
getTableState: () => Partial<TableState>;
|
|
12
|
+
onTableViewSave?: TableProps<TItem>['onTableViewSave'];
|
|
13
|
+
onTableViewDelete?: TableProps<TItem>['onTableViewDelete'];
|
|
14
|
+
};
|
|
15
|
+
export declare const ViewsDrawer: <TItem extends object>(props: ViewsDrawerProps<TItem>) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
package/src/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { FilterFn } from "@tanstack/react-table";
|
|
2
|
+
declare module '@tanstack/table-core' {
|
|
3
|
+
interface FilterFns {
|
|
4
|
+
arrIncludesSome: FilterFn<unknown>;
|
|
5
|
+
matchDate: FilterFn<unknown>;
|
|
6
|
+
inDateRange: FilterFn<unknown>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
1
9
|
export { Table } from "./components";
|
|
2
|
-
export type { TableProps, TableRef } from "./types";
|
|
3
|
-
export type { ColumnDef } from "@tanstack/react-table";
|
|
10
|
+
export type { TableProps, TableRef, TableView } from "./types";
|
|
11
|
+
export type { ColumnDef, TableState } from "@tanstack/react-table";
|
|
4
12
|
export { createColumnHelper } from "@tanstack/react-table";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { ColumnDef, ColumnFiltersState, ColumnOrderState, ColumnPinningState, ExpandedState, GroupingState, RowSelectionState, SortingState, VisibilityState } from "@tanstack/react-table";
|
|
3
|
+
import { TableView } from "./TableView";
|
|
3
4
|
export type TableProps<TItem extends object> = {
|
|
4
5
|
/**
|
|
5
6
|
* Table Columns definitions.
|
|
@@ -17,6 +18,10 @@ export type TableProps<TItem extends object> = {
|
|
|
17
18
|
* Grid title
|
|
18
19
|
*/
|
|
19
20
|
gridTitle?: JSX.Element | React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Table header menu
|
|
23
|
+
*/
|
|
24
|
+
headerMenu?: (selectedItems: TItem[]) => JSX.Element | React.ReactNode;
|
|
20
25
|
/**
|
|
21
26
|
* Table default page size.
|
|
22
27
|
*/
|
|
@@ -75,4 +80,16 @@ export type TableProps<TItem extends object> = {
|
|
|
75
80
|
* @default defaultNoItemComponent
|
|
76
81
|
*/
|
|
77
82
|
noItemPage?: React.ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* Table Views
|
|
85
|
+
*/
|
|
86
|
+
views?: TableView[];
|
|
87
|
+
/**
|
|
88
|
+
* Callback when a table view is saved
|
|
89
|
+
*/
|
|
90
|
+
onTableViewSave?: (tableView: TableView) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback when a table view is deleted
|
|
93
|
+
*/
|
|
94
|
+
onTableViewDelete?: (tableView: TableView) => void;
|
|
78
95
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Table } from "@tanstack/react-table";
|
|
1
|
+
import { Table, TableState } from "@tanstack/react-table";
|
|
2
2
|
export type TableRef<TItem extends object> = {
|
|
3
3
|
table: Table<TItem>;
|
|
4
|
-
getTableState: () =>
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
getTableState: () => Partial<TableState>;
|
|
5
|
+
applyTableState: (tableState: Partial<TableState>) => boolean;
|
|
6
|
+
resetToDefaultView: () => boolean;
|
|
7
7
|
};
|
package/src/lib/types/index.d.ts
CHANGED