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