@bsol-oss/react-datatable5 1.0.61 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +19 -12
- package/dist/index.js +297 -216
- package/dist/index.mjs +300 -219
- package/dist/types/components/Controls/DensityFeature.d.ts +23 -0
- package/dist/types/components/Controls/DensityToggleButton.d.ts +6 -0
- package/dist/types/components/Controls/EditFilterButton.d.ts +9 -0
- package/dist/types/components/Controls/EditOrderButton.d.ts +7 -0
- package/dist/types/components/Controls/EditSortingButton.d.ts +7 -0
- package/dist/types/components/Controls/EditViewButton.d.ts +7 -0
- package/dist/types/components/Controls/PageSizeControl.d.ts +4 -0
- package/dist/types/components/Controls/ResetFilteringButton.d.ts +4 -0
- package/dist/types/components/Controls/ResetSelectionButton.d.ts +4 -0
- package/dist/types/components/Controls/ResetSortingButton.d.ts +4 -0
- package/dist/types/components/Controls/RowCountText.d.ts +1 -0
- package/dist/types/components/Controls/SelectAllRowsToggle.d.ts +8 -0
- package/dist/types/components/DataTable/DataTable.d.ts +33 -0
- package/dist/types/components/DataTable/DataTableContext.d.ts +10 -0
- package/dist/types/components/DataTable/DataTableServer.d.ts +33 -0
- package/dist/types/components/DataTable/DefaultTable.d.ts +5 -0
- package/dist/types/components/DataTable/Table.d.ts +8 -0
- package/dist/types/components/DataTable/TableBody.d.ts +17 -0
- package/dist/types/components/DataTable/TableCardContainer.d.ts +6 -0
- package/dist/types/components/DataTable/TableCards.d.ts +4 -0
- package/dist/types/components/DataTable/TableComponent.d.ts +6 -0
- package/dist/types/components/DataTable/TableControls.d.ts +13 -0
- package/dist/types/components/DataTable/TableFilter.d.ts +1 -0
- package/dist/types/components/DataTable/TableFilterTags.d.ts +1 -0
- package/dist/types/components/DataTable/TableFooter.d.ts +7 -0
- package/dist/types/components/DataTable/TableHeader.d.ts +8 -0
- package/dist/types/components/DataTable/TableLoadingComponent.d.ts +5 -0
- package/dist/types/components/DataTable/TableOrderer.d.ts +1 -0
- package/dist/types/components/DataTable/TablePagination.d.ts +3 -0
- package/dist/types/components/DataTable/TableReloadButton.d.ts +4 -0
- package/dist/types/components/DataTable/TableSelector.d.ts +1 -0
- package/dist/types/components/DataTable/TableSorter.d.ts +1 -0
- package/dist/types/components/DataTable/TableViewer.d.ts +1 -0
- package/dist/types/components/DataTable/TextCell.d.ts +10 -0
- package/dist/types/components/DataTable/useDataFromUrl.d.ts +14 -0
- package/dist/types/components/DataTable/useDataTable.d.ts +7 -0
- package/dist/types/components/Filter/DateRangeFilter.d.ts +9 -0
- package/dist/types/components/Filter/FilterOptions.d.ts +4 -0
- package/dist/types/components/Filter/GlobalFilter.d.ts +3 -0
- package/dist/types/components/Filter/RangeFilter.d.ts +11 -0
- package/dist/types/components/Filter/TagFilter.d.ts +8 -0
- package/dist/types/index.d.ts +54 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,12 +8,13 @@ var axios = require('axios');
|
|
|
8
8
|
var react$1 = require('@chakra-ui/react');
|
|
9
9
|
var table = require('@chakra-ui/table');
|
|
10
10
|
var md = require('react-icons/md');
|
|
11
|
-
var io = require('react-icons/io');
|
|
12
|
-
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
13
|
-
var fa = require('react-icons/fa');
|
|
14
11
|
var icons = require('@chakra-ui/icons');
|
|
12
|
+
var gr = require('react-icons/gr');
|
|
15
13
|
var ai = require('react-icons/ai');
|
|
14
|
+
var io = require('react-icons/io');
|
|
16
15
|
var io5 = require('react-icons/io5');
|
|
16
|
+
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
17
|
+
var fa = require('react-icons/fa');
|
|
17
18
|
|
|
18
19
|
const TableContext = react.createContext({
|
|
19
20
|
table: {},
|
|
@@ -311,19 +312,6 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
311
312
|
}, children: children }));
|
|
312
313
|
};
|
|
313
314
|
|
|
314
|
-
const useDataTable = () => {
|
|
315
|
-
const { table, refreshData, globalFilter, setGlobalFilter, loading } = react.useContext(TableContext);
|
|
316
|
-
return { table, refreshData, globalFilter, setGlobalFilter, loading };
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const Table = ({ children, showLoading = false, loadingComponent = jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading..." }), ...props }) => {
|
|
320
|
-
const { table, loading } = useDataTable();
|
|
321
|
-
if (showLoading) {
|
|
322
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
|
|
323
|
-
}
|
|
324
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflowX: "auto", ...props, children: children }) }));
|
|
325
|
-
};
|
|
326
|
-
|
|
327
315
|
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
328
316
|
const { table: table$1 } = react.useContext(TableContext);
|
|
329
317
|
const SELECTION_BOX_WIDTH = 20;
|
|
@@ -373,149 +361,17 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
|
|
|
373
361
|
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
374
362
|
};
|
|
375
363
|
|
|
376
|
-
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
377
|
-
const { table } = useDataTable();
|
|
378
|
-
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
379
|
-
table.resetColumnFilters();
|
|
380
|
-
}, children: text }));
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
function Filter({ column }) {
|
|
384
|
-
const { filterVariant } = column.columnDef.meta ?? {};
|
|
385
|
-
const displayName = column.columnDef.meta?.displayName ?? column.id;
|
|
386
|
-
const filterOptions = column.columnDef.meta?.filterOptions ?? [];
|
|
387
|
-
if (column.columns.length > 0) {
|
|
388
|
-
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), column.columns.map((column) => {
|
|
389
|
-
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
390
|
-
})] }, column.id));
|
|
391
|
-
}
|
|
392
|
-
if (!column.getCanFilter()) {
|
|
393
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
394
|
-
}
|
|
395
|
-
if (filterVariant === "select") {
|
|
396
|
-
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(react$1.Select, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", placeholder: "Select option", onChange: (e) => {
|
|
397
|
-
column.setFilterValue(e.target.value);
|
|
398
|
-
}, children: filterOptions.map((option) => {
|
|
399
|
-
return (jsxRuntime.jsx("option", { value: option, children: option }, `${option}`));
|
|
400
|
-
}) })] }, column.id));
|
|
401
|
-
}
|
|
402
|
-
if (filterVariant === "range") {
|
|
403
|
-
const filterValue = column.getFilterValue() ?? [
|
|
404
|
-
undefined,
|
|
405
|
-
undefined,
|
|
406
|
-
];
|
|
407
|
-
const [min, max] = filterValue;
|
|
408
|
-
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsxs(react$1.Flex, { gap: "0.5rem", children: [jsxRuntime.jsx(react$1.Input, { type: "number", placeholder: "min", value: min, onChange: (e) => {
|
|
409
|
-
column.setFilterValue([Number(e.target.value), max]);
|
|
410
|
-
} }), jsxRuntime.jsx(react$1.Input, { type: "number", placeholder: "max", value: max, onChange: (e) => {
|
|
411
|
-
column.setFilterValue([min, Number(e.target.value)]);
|
|
412
|
-
} })] })] }, column.id));
|
|
413
|
-
}
|
|
414
|
-
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(react$1.Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
|
|
415
|
-
column.setFilterValue(e.target.value);
|
|
416
|
-
} })] }, column.id));
|
|
417
|
-
}
|
|
418
|
-
const TableFilter = () => {
|
|
419
|
-
const { table } = useDataTable();
|
|
420
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getAllColumns().map((column) => {
|
|
421
|
-
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
422
|
-
}) }));
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsxRuntime.jsx(md.MdFilterAlt, {}), ...props }) => {
|
|
426
|
-
const filterModal = react$1.useDisclosure();
|
|
427
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "1rem", children: [jsxRuntime.jsx(TableFilter, {}), jsxRuntime.jsx(ResetFilteringButton, { text: resetText })] }) }), jsxRuntime.jsx(react$1.ModalFooter, { children: jsxRuntime.jsx(react$1.Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
const TableViewer = () => {
|
|
431
|
-
const { table } = useDataTable();
|
|
432
|
-
const columns = table.getAllLeafColumns();
|
|
433
|
-
const [columnOrder, setColumnOrder] = react.useState(columns.map((column, index) => {
|
|
434
|
-
return column.id;
|
|
435
|
-
}));
|
|
436
|
-
const handleDragEnd = (result) => {
|
|
437
|
-
if (!result.destination)
|
|
438
|
-
return;
|
|
439
|
-
const newColumnOrder = Array.from(columnOrder);
|
|
440
|
-
const [removed] = newColumnOrder.splice(result.source.index, 1);
|
|
441
|
-
newColumnOrder.splice(result.destination.index, 0, removed);
|
|
442
|
-
setColumnOrder(newColumnOrder);
|
|
443
|
-
table.setColumnOrder(newColumnOrder);
|
|
444
|
-
};
|
|
445
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(reactBeautifulDnd.DragDropContext, { onDragEnd: handleDragEnd, children: jsxRuntime.jsx(reactBeautifulDnd.Droppable, { droppableId: "columns", children: (provided) => (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, i) => {
|
|
446
|
-
const displayName = column.columnDef.meta === undefined
|
|
447
|
-
? column.id
|
|
448
|
-
: column.columnDef.meta.displayName;
|
|
449
|
-
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxRuntime.jsxs(react$1.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react$1.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsxRuntime.jsx(react$1.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react$1.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsxs(react$1.Box, { children: [" ", displayName] }), jsxRuntime.jsx(react$1.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
|
|
450
|
-
}), provided.placeholder] })) }) }) }));
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
454
|
-
const viewModel = react$1.useDisclosure();
|
|
455
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsx(TableViewer, {}) })] })] })] }));
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const GlobalFilter = ({ icon = md.MdSearch }) => {
|
|
459
|
-
const { globalFilter, setGlobalFilter } = useDataTable();
|
|
460
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Box, { children: jsxRuntime.jsxs(react$1.InputGroup, { children: [jsxRuntime.jsx(react$1.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react$1.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react$1.Input, { value: globalFilter, onChange: (e) => {
|
|
461
|
-
setGlobalFilter(e.target.value);
|
|
462
|
-
} })] }) }) }));
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
466
|
-
const { table } = useDataTable();
|
|
467
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react$1.Menu, { children: [jsxRuntime.jsx(react$1.MenuButton, { as: react$1.Button, variant: "ghost", rightIcon: jsxRuntime.jsx(icons.ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsxRuntime.jsx(react$1.MenuList, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(react$1.MenuItem, { onClick: () => {
|
|
468
|
-
table.setPageSize(Number(pageSize));
|
|
469
|
-
}, children: pageSize }, crypto.randomUUID()))) })] }) }));
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
const RowCountText = () => {
|
|
473
|
-
const { table } = react.useContext(TableContext);
|
|
474
|
-
return jsxRuntime.jsx(react$1.Text, { children: table.getRowCount() });
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
const TableFilterTags = () => {
|
|
478
|
-
const { table } = useDataTable();
|
|
479
|
-
return (jsxRuntime.jsx(react$1.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }, index) => {
|
|
480
|
-
return (jsxRuntime.jsxs(react$1.Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react$1.Text, { children: `${id}: ${value}` }), jsxRuntime.jsx(react$1.IconButton, { size: "xs", variant: "ghost", icon: jsxRuntime.jsx(icons.CloseIcon, {}), onClick: () => {
|
|
481
|
-
table.setColumnFilters(table.getState().columnFilters.filter((value, curIndex) => {
|
|
482
|
-
return curIndex != index;
|
|
483
|
-
}));
|
|
484
|
-
}, "aria-label": "remove filter" })] }, `${id}-${value}`));
|
|
485
|
-
}) }));
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const TablePagination = ({}) => {
|
|
489
|
-
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTable().table;
|
|
490
|
-
return (jsxRuntime.jsxs(react$1.ButtonGroup, { isAttached: true, children: [jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsxRuntime.jsx(react$1.Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const FilterOptions = ({ column }) => {
|
|
494
|
-
const { table } = useDataTable();
|
|
495
|
-
const tableColumn = table.getColumn(column);
|
|
496
|
-
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
497
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
498
|
-
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
499
|
-
return (jsxRuntime.jsxs(react$1.Button, { size: "sm", onClick: () => {
|
|
500
|
-
if (selected) {
|
|
501
|
-
table.setColumnFilters((state) => {
|
|
502
|
-
return state.filter((filter) => {
|
|
503
|
-
return filter.id !== column;
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
table.getColumn(column)?.setFilterValue(option);
|
|
509
|
-
}, variant: selected ? "solid" : "outline", display: 'flex', gap: '0.25rem', children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
|
|
510
|
-
}) }));
|
|
511
|
-
};
|
|
512
|
-
|
|
513
364
|
const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showFilterName = false, showFilterTags = false, filterOptions = [], }) => {
|
|
514
|
-
return (jsxRuntime.jsxs(react$1.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react$1.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react$1.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsx(react$1.Flex, { gap: "1rem", justifySelf: "end", children: showFilter && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(GlobalFilter, {}), jsxRuntime.jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] })) })] }), jsxRuntime.jsx(react$1.Flex, { gridColumn: "1 / span 2", flexFlow:
|
|
365
|
+
return (jsxRuntime.jsxs(react$1.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react$1.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react$1.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsx(react$1.Flex, { gap: "1rem", justifySelf: "end", children: showFilter && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(GlobalFilter, {}), jsxRuntime.jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] })) })] }), jsxRuntime.jsx(react$1.Flex, { gridColumn: "1 / span 2", flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
|
|
515
366
|
return (jsxRuntime.jsxs(react$1.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react$1.Text, { children: [column, ":"] }), jsxRuntime.jsx(FilterOptions, { column: column })] }));
|
|
516
367
|
}) }), jsxRuntime.jsx(react$1.Flex, { gridColumn: "1 / span 2", children: showFilterTags && jsxRuntime.jsx(TableFilterTags, {}) }), jsxRuntime.jsx(react$1.Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: children }), jsxRuntime.jsxs(react$1.Flex, { gap: "1rem", alignItems: "center", children: [jsxRuntime.jsx(PageSizeControl, {}), jsxRuntime.jsxs(react$1.Flex, { children: [jsxRuntime.jsx(react$1.Text, { paddingRight: "0.5rem", children: totalText }), jsxRuntime.jsx(RowCountText, {})] })] }), jsxRuntime.jsx(react$1.Box, { justifySelf: "end", children: jsxRuntime.jsx(TablePagination, {}) })] }));
|
|
517
368
|
};
|
|
518
369
|
|
|
370
|
+
const useDataTable = () => {
|
|
371
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading } = react.useContext(TableContext);
|
|
372
|
+
return { table, refreshData, globalFilter, setGlobalFilter, loading };
|
|
373
|
+
};
|
|
374
|
+
|
|
519
375
|
const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
520
376
|
const table = useDataTable().table;
|
|
521
377
|
const SELECTION_BOX_WIDTH = 20;
|
|
@@ -618,9 +474,25 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
618
474
|
header.column.pin("left");
|
|
619
475
|
}, children: "Pin Column" })), header.column.getIsPinned() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(md.MdCancel, {}), onClick: () => {
|
|
620
476
|
header.column.pin(false);
|
|
621
|
-
}, children: "Cancel Pin" })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(
|
|
622
|
-
|
|
623
|
-
|
|
477
|
+
}, children: "Cancel Pin" })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(gr.GrAscend, {}), onClick: () => {
|
|
478
|
+
table.setSorting((state) => {
|
|
479
|
+
return [
|
|
480
|
+
...state.filter((column) => {
|
|
481
|
+
return column.id !== header.id;
|
|
482
|
+
}),
|
|
483
|
+
{ id: header.id, desc: false },
|
|
484
|
+
];
|
|
485
|
+
});
|
|
486
|
+
}, children: "Sort Ascending" }), jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(gr.GrDescend, {}), onClick: () => {
|
|
487
|
+
table.setSorting((state) => {
|
|
488
|
+
return [
|
|
489
|
+
...state.filter((column) => {
|
|
490
|
+
return column.id !== header.id;
|
|
491
|
+
}),
|
|
492
|
+
{ id: header.id, desc: true },
|
|
493
|
+
];
|
|
494
|
+
});
|
|
495
|
+
}, children: "Sort Descending" }), header.column.getIsSorted() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(md.MdClear, {}), onClick: () => {
|
|
624
496
|
header.column.clearSorting();
|
|
625
497
|
}, children: "Clear Sorting" }))] }))] }) })] }), canResize && (jsxRuntime.jsx(react$1.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing() ? "gray.700" : "transparent", position: "absolute", right: "0", top: "0", height: "100%", width: "5px", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
626
498
|
borderRightColor: header.column.getIsResizing()
|
|
@@ -643,57 +515,9 @@ const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWid
|
|
|
643
515
|
}, children: text }))] }));
|
|
644
516
|
};
|
|
645
517
|
|
|
646
|
-
const
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
const { table } = useDataTable();
|
|
650
|
-
const handleChangeOrder = (startIndex, endIndex) => {
|
|
651
|
-
const newOrder = Array.from(order);
|
|
652
|
-
const [removed] = newOrder.splice(startIndex, 1);
|
|
653
|
-
newOrder.splice(endIndex, 0, removed);
|
|
654
|
-
setOrder(newOrder);
|
|
655
|
-
};
|
|
656
|
-
react.useEffect(() => {
|
|
657
|
-
setOrder(columns);
|
|
658
|
-
}, [columns]);
|
|
659
|
-
react.useEffect(() => {
|
|
660
|
-
if (originalOrder.length > 0) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
if (columns.length <= 0) {
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
setOriginalOrder(columns);
|
|
667
|
-
}, [columns]);
|
|
668
|
-
return (jsxRuntime.jsxs(react$1.Flex, { gap: "0.5rem", flexFlow: "column", children: [jsxRuntime.jsx(react$1.Flex, { gap: "0.5rem", flexFlow: "column", children: order.map((columnId, index) => (jsxRuntime.jsxs(react$1.Flex, { gap: "0.5rem", alignItems: "center", justifyContent: "space-between", children: [jsxRuntime.jsx(react$1.IconButton, { onClick: () => {
|
|
669
|
-
const prevIndex = index - 1;
|
|
670
|
-
if (prevIndex >= 0) {
|
|
671
|
-
handleChangeOrder(index, prevIndex);
|
|
672
|
-
}
|
|
673
|
-
}, disabled: index === 0, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowUpward, {}) }), table
|
|
674
|
-
.getAllFlatColumns()
|
|
675
|
-
.filter((column) => {
|
|
676
|
-
return column.id === columnId;
|
|
677
|
-
})
|
|
678
|
-
.map((column) => {
|
|
679
|
-
const displayName = column.columnDef.meta === undefined
|
|
680
|
-
? column.id
|
|
681
|
-
: column.columnDef.meta.displayName;
|
|
682
|
-
return jsxRuntime.jsx("span", { children: displayName }, column.id);
|
|
683
|
-
}), jsxRuntime.jsx(react$1.IconButton, { onClick: () => {
|
|
684
|
-
const nextIndex = index + 1;
|
|
685
|
-
if (nextIndex < order.length) {
|
|
686
|
-
handleChangeOrder(index, nextIndex);
|
|
687
|
-
}
|
|
688
|
-
}, disabled: index === order.length - 1, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowDownward, {}) })] }, columnId))) }), jsxRuntime.jsxs(react$1.Flex, { gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
689
|
-
table.setColumnOrder(order);
|
|
690
|
-
}, children: "Apply" }), jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
691
|
-
table.setColumnOrder(originalOrder);
|
|
692
|
-
}, children: "Reset" })] })] }));
|
|
693
|
-
};
|
|
694
|
-
const TableOrderer = () => {
|
|
695
|
-
const { table } = useDataTable();
|
|
696
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
518
|
+
const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsxRuntime.jsx(md.MdFilterAlt, {}), ...props }) => {
|
|
519
|
+
const filterModal = react$1.useDisclosure();
|
|
520
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "1rem", children: [jsxRuntime.jsx(TableFilter, {}), jsxRuntime.jsx(ResetFilteringButton, { text: resetText })] }) }), jsxRuntime.jsx(react$1.ModalFooter, { children: jsxRuntime.jsx(react$1.Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
|
|
697
521
|
};
|
|
698
522
|
|
|
699
523
|
const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
@@ -701,13 +525,6 @@ const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {})
|
|
|
701
525
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: orderModal.onOpen, "aria-label": "change order" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: orderModal.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: orderModal.isOpen, onClose: orderModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsx(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) })] })] })] }));
|
|
702
526
|
};
|
|
703
527
|
|
|
704
|
-
const ResetSortingButton = ({ text = "Reset Sorting", }) => {
|
|
705
|
-
const { table } = useDataTable();
|
|
706
|
-
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
707
|
-
table.resetSorting();
|
|
708
|
-
}, children: text }));
|
|
709
|
-
};
|
|
710
|
-
|
|
711
528
|
const TableSorter = () => {
|
|
712
529
|
const { table } = useDataTable();
|
|
713
530
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
@@ -733,6 +550,52 @@ const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}),
|
|
|
733
550
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: sortingModal.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: sortingModal.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: sortingModal.isOpen, onClose: sortingModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(TableSorter, {}), jsxRuntime.jsx(ResetSortingButton, {})] }) })] })] })] }));
|
|
734
551
|
};
|
|
735
552
|
|
|
553
|
+
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
554
|
+
const viewModel = react$1.useDisclosure();
|
|
555
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react$1.IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxRuntime.jsxs(react$1.Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react$1.ModalOverlay, {}), jsxRuntime.jsxs(react$1.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react$1.ModalHeader, { children: title }), jsxRuntime.jsx(react$1.ModalCloseButton, {}), jsxRuntime.jsx(react$1.ModalBody, { children: jsxRuntime.jsx(TableViewer, {}) })] })] })] }));
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const FilterOptions = ({ column }) => {
|
|
559
|
+
const { table } = useDataTable();
|
|
560
|
+
const tableColumn = table.getColumn(column);
|
|
561
|
+
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
562
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
563
|
+
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
564
|
+
return (jsxRuntime.jsxs(react$1.Button, { size: "sm", onClick: () => {
|
|
565
|
+
if (selected) {
|
|
566
|
+
table.setColumnFilters((state) => {
|
|
567
|
+
return state.filter((filter) => {
|
|
568
|
+
return filter.id !== column;
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
table.getColumn(column)?.setFilterValue(option);
|
|
574
|
+
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsxRuntime.jsx(md.MdClose, {})] }, option));
|
|
575
|
+
}) }));
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const GlobalFilter = ({ icon = md.MdSearch }) => {
|
|
579
|
+
const { globalFilter, setGlobalFilter } = useDataTable();
|
|
580
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Box, { children: jsxRuntime.jsxs(react$1.InputGroup, { children: [jsxRuntime.jsx(react$1.InputLeftElement, { pointerEvents: "none", children: jsxRuntime.jsx(react$1.Icon, { as: icon, color: "gray.300" }) }), jsxRuntime.jsx(react$1.Input, { value: globalFilter, onChange: (e) => {
|
|
581
|
+
setGlobalFilter(e.target.value);
|
|
582
|
+
} })] }) }) }));
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
586
|
+
const { table } = useDataTable();
|
|
587
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react$1.Menu, { children: [jsxRuntime.jsx(react$1.MenuButton, { as: react$1.Button, variant: "ghost", rightIcon: jsxRuntime.jsx(icons.ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsxRuntime.jsx(react$1.MenuList, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(react$1.MenuItem, { onClick: () => {
|
|
588
|
+
table.setPageSize(Number(pageSize));
|
|
589
|
+
}, children: pageSize }, crypto.randomUUID()))) })] }) }));
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
593
|
+
const { table } = useDataTable();
|
|
594
|
+
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
595
|
+
table.resetColumnFilters();
|
|
596
|
+
}, children: text }));
|
|
597
|
+
};
|
|
598
|
+
|
|
736
599
|
const ResetSelectionButton = ({ text = "Reset Selection", }) => {
|
|
737
600
|
const { table } = useDataTable();
|
|
738
601
|
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
@@ -740,6 +603,26 @@ const ResetSelectionButton = ({ text = "Reset Selection", }) => {
|
|
|
740
603
|
}, children: text }));
|
|
741
604
|
};
|
|
742
605
|
|
|
606
|
+
const ResetSortingButton = ({ text = "Reset Sorting", }) => {
|
|
607
|
+
const { table } = useDataTable();
|
|
608
|
+
return (jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
609
|
+
table.resetSorting();
|
|
610
|
+
}, children: text }));
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
const RowCountText = () => {
|
|
614
|
+
const { table } = useDataTable();
|
|
615
|
+
return jsxRuntime.jsx(react$1.Text, { children: table.getRowCount() });
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
const Table = ({ children, showLoading = false, loadingComponent = jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading..." }), ...props }) => {
|
|
619
|
+
const { table, loading } = useDataTable();
|
|
620
|
+
if (showLoading) {
|
|
621
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
|
|
622
|
+
}
|
|
623
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflowX: "auto", ...props, children: children }) }));
|
|
624
|
+
};
|
|
625
|
+
|
|
743
626
|
const TableCardContainer = ({ children, ...props }) => {
|
|
744
627
|
return (jsxRuntime.jsx(react$1.Grid, { gridTemplateColumns: ["1fr", "1fr 1fr", "1fr 1fr 1fr"], gap: "0.5rem", ...props, children: children }));
|
|
745
628
|
};
|
|
@@ -763,11 +646,186 @@ const TableComponent = ({ render = () => {
|
|
|
763
646
|
return render(table);
|
|
764
647
|
};
|
|
765
648
|
|
|
649
|
+
const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
|
|
650
|
+
console.log(startDate, endDate, "dflp");
|
|
651
|
+
return (jsxRuntime.jsx(react$1.Box, { p: '1rem', children: jsxRuntime.jsxs(react$1.VStack, { spacing: 4, children: [jsxRuntime.jsxs(react$1.FormControl, { children: [jsxRuntime.jsx(react$1.FormLabel, { htmlFor: "start-date", children: "Start Date" }), jsxRuntime.jsx(react$1.Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxRuntime.jsxs(react$1.FormControl, { children: [jsxRuntime.jsx(react$1.FormLabel, { htmlFor: "end-date", children: "End Date" }), jsxRuntime.jsx(react$1.Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
const RangeFilter = ({ range, setRange, defaultValue, min, max, step, }) => {
|
|
655
|
+
return (jsxRuntime.jsx(react$1.Box, { p: 8, children: jsxRuntime.jsxs(react$1.VStack, { spacing: 4, children: [jsxRuntime.jsxs(react$1.Text, { children: ["Selected Range: ", range[0], " - ", range[1]] }), jsxRuntime.jsxs(react$1.RangeSlider, { "aria-label": ["min", "max"], defaultValue: defaultValue, min: min, max: max, step: step, onChangeEnd: (val) => setRange(val), children: [jsxRuntime.jsx(react$1.RangeSliderTrack, { children: jsxRuntime.jsx(react$1.RangeSliderFilledTrack, {}) }), jsxRuntime.jsx(react$1.RangeSliderThumb, { index: 0 }), jsxRuntime.jsx(react$1.RangeSliderThumb, { index: 1 })] })] }) }));
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
659
|
+
const toggleTag = (tag) => {
|
|
660
|
+
if (selectedTags.includes(tag)) {
|
|
661
|
+
onTagChange(selectedTags.filter((t) => t !== tag));
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
onTagChange([...selectedTags, tag]);
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
return (jsxRuntime.jsx(react$1.Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsxRuntime.jsx(react$1.WrapItem, { children: jsxRuntime.jsxs(react$1.Tag, { size: "lg", variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", onClick: () => toggleTag(tag), children: [jsxRuntime.jsx(react$1.TagLabel, { children: tag }), selectedTags.includes(tag) && jsxRuntime.jsx(react$1.TagCloseButton, {})] }) }, tag))) }));
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
function Filter({ column }) {
|
|
671
|
+
const { filterVariant } = column.columnDef.meta ?? {};
|
|
672
|
+
const displayName = column.columnDef.meta?.displayName ?? column.id;
|
|
673
|
+
const filterOptions = column.columnDef.meta?.filterOptions ?? [];
|
|
674
|
+
if (column.columns.length > 0) {
|
|
675
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), column.columns.map((column) => {
|
|
676
|
+
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
677
|
+
})] }, column.id));
|
|
678
|
+
}
|
|
679
|
+
if (!column.getCanFilter()) {
|
|
680
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
681
|
+
}
|
|
682
|
+
if (filterVariant === "select") {
|
|
683
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(react$1.Select, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", placeholder: "Select option", onChange: (e) => {
|
|
684
|
+
column.setFilterValue(e.target.value);
|
|
685
|
+
}, children: filterOptions.map((option) => {
|
|
686
|
+
return (jsxRuntime.jsx("option", { value: option, children: option }, `${option}`));
|
|
687
|
+
}) })] }, column.id));
|
|
688
|
+
}
|
|
689
|
+
if (filterVariant === "tag") {
|
|
690
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
691
|
+
if (tags.length === 0) {
|
|
692
|
+
return column.setFilterValue(undefined);
|
|
693
|
+
}
|
|
694
|
+
column.setFilterValue(tags);
|
|
695
|
+
} })] }, column.id));
|
|
696
|
+
}
|
|
697
|
+
if (filterVariant === "boolean") {
|
|
698
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: ["true", "false"], selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
699
|
+
if (tags.length === 0) {
|
|
700
|
+
return column.setFilterValue(undefined);
|
|
701
|
+
}
|
|
702
|
+
column.setFilterValue(tags);
|
|
703
|
+
} })] }, column.id));
|
|
704
|
+
}
|
|
705
|
+
if (filterVariant === "range") {
|
|
706
|
+
const filterValue = column.getFilterValue() ?? [
|
|
707
|
+
undefined,
|
|
708
|
+
undefined,
|
|
709
|
+
];
|
|
710
|
+
const { min, max, step, defaultValue } = column.columnDef.meta
|
|
711
|
+
?.filterRangeConfig ?? {
|
|
712
|
+
min: 0,
|
|
713
|
+
max: 100,
|
|
714
|
+
step: 1,
|
|
715
|
+
defaultValue: [4, 50],
|
|
716
|
+
};
|
|
717
|
+
return (jsxRuntime.jsx(RangeFilter, { range: filterValue, setRange: function (value) {
|
|
718
|
+
// throw new Error("Function not implemented.");
|
|
719
|
+
column.setFilterValue(value);
|
|
720
|
+
}, defaultValue: defaultValue, min: min, max: max, step: step }));
|
|
721
|
+
}
|
|
722
|
+
if (filterVariant === "dateRange") {
|
|
723
|
+
const [start, end] = column.getFilterValue() ?? [
|
|
724
|
+
"",
|
|
725
|
+
"",
|
|
726
|
+
];
|
|
727
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(DateRangeFilter, { startDate: start, endDate: end, setStartDate: function (value) {
|
|
728
|
+
column.setFilterValue((state) => {
|
|
729
|
+
return [value, (state ?? ["", ""])[1]];
|
|
730
|
+
});
|
|
731
|
+
}, setEndDate: function (value) {
|
|
732
|
+
column.setFilterValue((state) => {
|
|
733
|
+
return [(state ?? ["", ""])[0], value];
|
|
734
|
+
});
|
|
735
|
+
} })] }, column.id));
|
|
736
|
+
}
|
|
737
|
+
if (filterVariant === "custom") {
|
|
738
|
+
const renderFilter = column.columnDef.meta?.renderFilter;
|
|
739
|
+
if (renderFilter === undefined) {
|
|
740
|
+
throw new Error("renderFilter is undefined");
|
|
741
|
+
}
|
|
742
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderFilter(column) });
|
|
743
|
+
}
|
|
744
|
+
return (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Text, { children: displayName }), jsxRuntime.jsx(react$1.Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
|
|
745
|
+
column.setFilterValue(e.target.value);
|
|
746
|
+
} })] }, column.id));
|
|
747
|
+
}
|
|
748
|
+
const TableFilter = () => {
|
|
749
|
+
const { table } = useDataTable();
|
|
750
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getAllColumns().map((column) => {
|
|
751
|
+
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
752
|
+
}) }));
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
const TableFilterTags = () => {
|
|
756
|
+
const { table } = useDataTable();
|
|
757
|
+
return (jsxRuntime.jsx(react$1.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }, index) => {
|
|
758
|
+
return (jsxRuntime.jsxs(react$1.Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react$1.Text, { children: `${id}: ${value}` }), jsxRuntime.jsx(react$1.IconButton, { size: "xs", variant: "ghost", icon: jsxRuntime.jsx(icons.CloseIcon, {}), onClick: () => {
|
|
759
|
+
table.setColumnFilters(table.getState().columnFilters.filter((value, curIndex) => {
|
|
760
|
+
return curIndex != index;
|
|
761
|
+
}));
|
|
762
|
+
}, "aria-label": "remove filter" })] }, `${id}-${value}`));
|
|
763
|
+
}) }));
|
|
764
|
+
};
|
|
765
|
+
|
|
766
766
|
const TableLoadingComponent = ({ render, }) => {
|
|
767
767
|
const { loading } = useDataTable();
|
|
768
768
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(loading) });
|
|
769
769
|
};
|
|
770
770
|
|
|
771
|
+
const ColumnOrderChanger = ({ columns }) => {
|
|
772
|
+
const [order, setOrder] = react.useState([]);
|
|
773
|
+
const [originalOrder, setOriginalOrder] = react.useState([]);
|
|
774
|
+
const { table } = useDataTable();
|
|
775
|
+
const handleChangeOrder = (startIndex, endIndex) => {
|
|
776
|
+
const newOrder = Array.from(order);
|
|
777
|
+
const [removed] = newOrder.splice(startIndex, 1);
|
|
778
|
+
newOrder.splice(endIndex, 0, removed);
|
|
779
|
+
setOrder(newOrder);
|
|
780
|
+
};
|
|
781
|
+
react.useEffect(() => {
|
|
782
|
+
setOrder(columns);
|
|
783
|
+
}, [columns]);
|
|
784
|
+
react.useEffect(() => {
|
|
785
|
+
if (originalOrder.length > 0) {
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (columns.length <= 0) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
setOriginalOrder(columns);
|
|
792
|
+
}, [columns]);
|
|
793
|
+
return (jsxRuntime.jsxs(react$1.Flex, { gap: "0.5rem", flexFlow: "column", children: [jsxRuntime.jsx(react$1.Flex, { gap: "0.5rem", flexFlow: "column", children: order.map((columnId, index) => (jsxRuntime.jsxs(react$1.Flex, { gap: "0.5rem", alignItems: "center", justifyContent: "space-between", children: [jsxRuntime.jsx(react$1.IconButton, { onClick: () => {
|
|
794
|
+
const prevIndex = index - 1;
|
|
795
|
+
if (prevIndex >= 0) {
|
|
796
|
+
handleChangeOrder(index, prevIndex);
|
|
797
|
+
}
|
|
798
|
+
}, disabled: index === 0, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowUpward, {}) }), table
|
|
799
|
+
.getAllFlatColumns()
|
|
800
|
+
.filter((column) => {
|
|
801
|
+
return column.id === columnId;
|
|
802
|
+
})
|
|
803
|
+
.map((column) => {
|
|
804
|
+
const displayName = column.columnDef.meta === undefined
|
|
805
|
+
? column.id
|
|
806
|
+
: column.columnDef.meta.displayName;
|
|
807
|
+
return jsxRuntime.jsx("span", { children: displayName }, column.id);
|
|
808
|
+
}), jsxRuntime.jsx(react$1.IconButton, { onClick: () => {
|
|
809
|
+
const nextIndex = index + 1;
|
|
810
|
+
if (nextIndex < order.length) {
|
|
811
|
+
handleChangeOrder(index, nextIndex);
|
|
812
|
+
}
|
|
813
|
+
}, disabled: index === order.length - 1, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowDownward, {}) })] }, columnId))) }), jsxRuntime.jsxs(react$1.Flex, { gap: "0.25rem", children: [jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
814
|
+
table.setColumnOrder(order);
|
|
815
|
+
}, children: "Apply" }), jsxRuntime.jsx(react$1.Button, { onClick: () => {
|
|
816
|
+
table.setColumnOrder(originalOrder);
|
|
817
|
+
}, children: "Reset" })] })] }));
|
|
818
|
+
};
|
|
819
|
+
const TableOrderer = () => {
|
|
820
|
+
const { table } = useDataTable();
|
|
821
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
const TablePagination = ({}) => {
|
|
825
|
+
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTable().table;
|
|
826
|
+
return (jsxRuntime.jsxs(react$1.ButtonGroup, { isAttached: true, children: [jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsxRuntime.jsx(react$1.Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
827
|
+
};
|
|
828
|
+
|
|
771
829
|
const ReloadButton = ({ text = "Reload" }) => {
|
|
772
830
|
const { refreshData } = useDataTable();
|
|
773
831
|
return (jsxRuntime.jsx(react$1.Button, { leftIcon: jsxRuntime.jsx(io5.IoReload, {}), onClick: () => {
|
|
@@ -776,7 +834,7 @@ const ReloadButton = ({ text = "Reload" }) => {
|
|
|
776
834
|
};
|
|
777
835
|
|
|
778
836
|
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText, clearAllText, }) => {
|
|
779
|
-
const { table } =
|
|
837
|
+
const { table } = useDataTable();
|
|
780
838
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react$1.IconButton, { icon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
|
|
781
839
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
782
840
|
} })), !!selectAllText !== false && (jsxRuntime.jsx(react$1.Button, { leftIcon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", onClick: (event) => {
|
|
@@ -791,6 +849,29 @@ const TableSelector = () => {
|
|
|
791
849
|
}, "aria-label": "reset selection" }))] }));
|
|
792
850
|
};
|
|
793
851
|
|
|
852
|
+
const TableViewer = () => {
|
|
853
|
+
const { table } = useDataTable();
|
|
854
|
+
const columns = table.getAllLeafColumns();
|
|
855
|
+
const [columnOrder, setColumnOrder] = react.useState(columns.map((column, index) => {
|
|
856
|
+
return column.id;
|
|
857
|
+
}));
|
|
858
|
+
const handleDragEnd = (result) => {
|
|
859
|
+
if (!result.destination)
|
|
860
|
+
return;
|
|
861
|
+
const newColumnOrder = Array.from(columnOrder);
|
|
862
|
+
const [removed] = newColumnOrder.splice(result.source.index, 1);
|
|
863
|
+
newColumnOrder.splice(result.destination.index, 0, removed);
|
|
864
|
+
setColumnOrder(newColumnOrder);
|
|
865
|
+
table.setColumnOrder(newColumnOrder);
|
|
866
|
+
};
|
|
867
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(reactBeautifulDnd.DragDropContext, { onDragEnd: handleDragEnd, children: jsxRuntime.jsx(reactBeautifulDnd.Droppable, { droppableId: "columns", children: (provided) => (jsxRuntime.jsxs(react$1.Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, i) => {
|
|
868
|
+
const displayName = column.columnDef.meta === undefined
|
|
869
|
+
? column.id
|
|
870
|
+
: column.columnDef.meta.displayName;
|
|
871
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxRuntime.jsxs(react$1.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react$1.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsxRuntime.jsx(react$1.Icon, { as: fa.FaGripLinesVertical, color: "gray.400" }) }), jsxRuntime.jsxs(react$1.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsxs(react$1.Box, { children: [" ", displayName] }), jsxRuntime.jsx(react$1.Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
|
|
872
|
+
}), provided.placeholder] })) }) }) }));
|
|
873
|
+
};
|
|
874
|
+
|
|
794
875
|
const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipProps, ...props }) => {
|
|
795
876
|
if (label) {
|
|
796
877
|
return (jsxRuntime.jsx(react$1.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react$1.Tooltip, { label: jsxRuntime.jsx(react$1.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", noOfLines: [5], children: label }), placement: "auto", ...tooltipProps, children: jsxRuntime.jsx(react$1.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }) }));
|