@absreim/react-bootstrap-data-grid-pro 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +6 -0
- package/grid/Grid.d.ts +5 -0
- package/grid/Grid.js +56 -0
- package/grid/InternalGrid.d.ts +19 -0
- package/grid/InternalGrid.js +57 -0
- package/grid/editing/EditControlsCell.d.ts +17 -0
- package/grid/editing/EditControlsCell.js +19 -0
- package/grid/editing/EditableRow.d.ts +22 -0
- package/grid/editing/EditableRow.js +68 -0
- package/grid/editing/inputStrsToRowData.d.ts +3 -0
- package/grid/editing/inputStrsToRowData.js +18 -0
- package/grid/editing/types.d.ts +16 -0
- package/grid/editing/types.js +1 -0
- package/grid/export/ExportForm.d.ts +9 -0
- package/grid/export/ExportForm.js +97 -0
- package/grid/export/types.d.ts +5 -0
- package/grid/export/types.js +1 -0
- package/grid/export/useExportFn.d.ts +23 -0
- package/grid/export/useExportFn.js +115 -0
- package/grid/filtering/DateFilterRow.d.ts +16 -0
- package/grid/filtering/DateFilterRow.js +45 -0
- package/grid/filtering/FilterOptionsTable.d.ts +11 -0
- package/grid/filtering/FilterOptionsTable.js +117 -0
- package/grid/filtering/FilterRow.d.ts +19 -0
- package/grid/filtering/FilterRow.js +18 -0
- package/grid/filtering/NumberFilterRow.d.ts +14 -0
- package/grid/filtering/NumberFilterRow.js +35 -0
- package/grid/filtering/StringFilterRow.d.ts +14 -0
- package/grid/filtering/StringFilterRow.js +35 -0
- package/grid/filtering/types.d.ts +70 -0
- package/grid/filtering/types.js +30 -0
- package/grid/filtering/useFilterFormState.d.ts +3 -0
- package/grid/filtering/useFilterFormState.js +72 -0
- package/grid/index.d.ts +10 -0
- package/grid/index.js +10 -0
- package/grid/main/BodyRows.d.ts +19 -0
- package/grid/main/BodyRows.js +18 -0
- package/grid/main/ColHeaderCell/index.d.ts +4 -0
- package/grid/main/ColHeaderCell/index.js +16 -0
- package/grid/main/ColHeaderCell/useSortHeaderStates.d.ts +9 -0
- package/grid/main/ColHeaderCell/useSortHeaderStates.js +54 -0
- package/grid/main/ToggleButton.d.ts +9 -0
- package/grid/main/ToggleButton.js +14 -0
- package/grid/pagination/PageSelector.d.ts +24 -0
- package/grid/pagination/PageSelector.js +92 -0
- package/grid/pagination/PageSizeSelector.d.ts +10 -0
- package/grid/pagination/PageSizeSelector.js +15 -0
- package/grid/pagination/Pagination.d.ts +9 -0
- package/grid/pagination/Pagination.js +24 -0
- package/grid/pagination/types.d.ts +22 -0
- package/grid/pagination/types.js +1 -0
- package/grid/pipeline/types.d.ts +1 -0
- package/grid/pipeline/types.js +1 -0
- package/grid/pipeline/useAugFormattedRows.d.ts +4 -0
- package/grid/pipeline/useAugFormattedRows.js +22 -0
- package/grid/pipeline/useCombinedPipeline/index.d.ts +19 -0
- package/grid/pipeline/useCombinedPipeline/index.js +31 -0
- package/grid/pipeline/useCombinedPipeline/useCurrentPageRows.d.ts +8 -0
- package/grid/pipeline/useCombinedPipeline/useCurrentPageRows.js +52 -0
- package/grid/pipeline/useCombinedPipeline/useDisplayRows.d.ts +3 -0
- package/grid/pipeline/useCombinedPipeline/useDisplayRows.js +60 -0
- package/grid/pipeline/useCombinedPipeline/useFilter.d.ts +4 -0
- package/grid/pipeline/useCombinedPipeline/useFilter.js +84 -0
- package/grid/pipeline/useCombinedPipeline/useFilterStateFromEditable.d.ts +4 -0
- package/grid/pipeline/useCombinedPipeline/useFilterStateFromEditable.js +18 -0
- package/grid/pipeline/useCombinedPipeline/useFilterStateStore.d.ts +4 -0
- package/grid/pipeline/useCombinedPipeline/useFilterStateStore.js +57 -0
- package/grid/pipeline/useCombinedPipeline/useSortedRows.d.ts +10 -0
- package/grid/pipeline/useCombinedPipeline/useSortedRows.js +58 -0
- package/grid/pipeline/useGetInputStrSubmitCallback.d.ts +5 -0
- package/grid/pipeline/useGetInputStrSubmitCallback.js +13 -0
- package/grid/pipeline/useGridSelectionFns.d.ts +16 -0
- package/grid/pipeline/useGridSelectionFns.js +131 -0
- package/grid/pipeline/useUnwrappedGridStyles.d.ts +7 -0
- package/grid/pipeline/useUnwrappedGridStyles.js +17 -0
- package/grid/selection/SelectAllHeaderCell.d.ts +11 -0
- package/grid/selection/SelectAllHeaderCell.js +55 -0
- package/grid/selection/SelectionInput.d.ts +19 -0
- package/grid/selection/SelectionInput.js +23 -0
- package/grid/selection/types.d.ts +30 -0
- package/grid/selection/types.js +4 -0
- package/grid/sorting/arrowPlaceholder.d.ts +2 -0
- package/grid/sorting/arrowPlaceholder.js +7 -0
- package/grid/sorting/downArrow.d.ts +2 -0
- package/grid/sorting/downArrow.js +3 -0
- package/grid/sorting/types.d.ts +19 -0
- package/grid/sorting/types.js +1 -0
- package/grid/sorting/upArrow.d.ts +2 -0
- package/grid/sorting/upArrow.js +13 -0
- package/grid/styling/styleModelUnwrappers.d.ts +4 -0
- package/grid/styling/styleModelUnwrappers.js +58 -0
- package/grid/styling/types.d.ts +62 -0
- package/grid/styling/types.js +1 -0
- package/grid/toolbar/Toolbar.d.ts +12 -0
- package/grid/toolbar/Toolbar.js +26 -0
- package/grid/toolbar/ToolbarContainer.d.ts +9 -0
- package/grid/toolbar/ToolbarContainer.js +24 -0
- package/grid/toolbar/types.d.ts +3 -0
- package/grid/toolbar/types.js +1 -0
- package/grid/toolbar/useInterfaces.d.ts +9 -0
- package/grid/toolbar/useInterfaces.js +23 -0
- package/grid/types.d.ts +63 -0
- package/grid/types.js +1 -0
- package/grid/util/datetime.d.ts +2 -0
- package/grid/util/datetime.js +5 -0
- package/grid/util/getWidthStyle.d.ts +3 -0
- package/grid/util/getWidthStyle.js +9 -0
- package/grid/util/isSubset.d.ts +2 -0
- package/grid/util/isSubset.js +11 -0
- package/grid/util/useControlledHover.d.ts +9 -0
- package/grid/util/useControlledHover.js +13 -0
- package/grid-pro/ColHeaderCellPro.d.ts +4 -0
- package/grid-pro/ColHeaderCellPro.js +140 -0
- package/grid-pro/GridPro.d.ts +4 -0
- package/grid-pro/GridPro.js +56 -0
- package/grid-pro/index.d.ts +3 -0
- package/grid-pro/index.js +3 -0
- package/grid-pro/resize/types.d.ts +5 -0
- package/grid-pro/resize/types.js +1 -0
- package/grid-pro/resize/useResizeModel.d.ts +5 -0
- package/grid-pro/resize/useResizeModel.js +65 -0
- package/grid-pro/types.d.ts +18 -0
- package/grid-pro/types.js +1 -0
- package/package.json +34 -0
- package/style.css +1 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import useControlledHover from "../../util/useControlledHover";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import upArrow from "../../sorting/upArrow";
|
|
4
|
+
import arrowPlaceholder from "../../sorting/arrowPlaceholder";
|
|
5
|
+
import downArrow from "../../sorting/downArrow";
|
|
6
|
+
var useSortHeaderStates = function (sortModel) {
|
|
7
|
+
var _a = useControlledHover(), isHovering = _a.isHovering, setIsHovering = _a.setIsHovering, handleMouseOver = _a.handleMouseOver, handleMouseOut = _a.handleMouseOut;
|
|
8
|
+
var handleClick = function () {
|
|
9
|
+
if (!sortModel) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
switch (sortModel.sortOrder) {
|
|
13
|
+
case null: {
|
|
14
|
+
sortModel.setSortOrder("asc");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
case "asc": {
|
|
18
|
+
sortModel.setSortOrder("desc");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
case "desc": {
|
|
22
|
+
sortModel.setSortOrder(null);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var sortSymbol = useMemo(function () {
|
|
27
|
+
if (!sortModel) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
switch (sortModel.sortOrder) {
|
|
31
|
+
case null: {
|
|
32
|
+
if (isHovering) {
|
|
33
|
+
return upArrow(true);
|
|
34
|
+
}
|
|
35
|
+
return arrowPlaceholder;
|
|
36
|
+
}
|
|
37
|
+
case "asc": {
|
|
38
|
+
return upArrow(false);
|
|
39
|
+
}
|
|
40
|
+
case "desc": {
|
|
41
|
+
return downArrow;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, [isHovering, sortModel]);
|
|
45
|
+
return {
|
|
46
|
+
isHovering: isHovering,
|
|
47
|
+
setIsHovering: setIsHovering,
|
|
48
|
+
handleMouseOver: handleMouseOver,
|
|
49
|
+
handleMouseOut: handleMouseOut,
|
|
50
|
+
handleClick: handleClick,
|
|
51
|
+
sortSymbol: sortSymbol,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export default useSortHeaderStates;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
var ToggleButton = function (_a) {
|
|
5
|
+
var isActive = _a.isActive, label = _a.label, onClick = _a.onClick, classes = _a.classes;
|
|
6
|
+
var baseClasses = ["btn"];
|
|
7
|
+
var variableClasses = {
|
|
8
|
+
active: isActive,
|
|
9
|
+
};
|
|
10
|
+
return (_jsx("button", { type: "button", className: classNames(baseClasses, variableClasses, classes, {
|
|
11
|
+
"btn-primary": !(classes && classes.length > 0),
|
|
12
|
+
}), "aria-pressed": isActive, onClick: onClick, children: label }));
|
|
13
|
+
};
|
|
14
|
+
export default ToggleButton;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JustifyContentSetting, Size } from "../types";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
export interface PageSelectorProps {
|
|
4
|
+
numPages: number;
|
|
5
|
+
pageNum: number;
|
|
6
|
+
numButtons: number;
|
|
7
|
+
setPageNum: (pageNum: number) => void;
|
|
8
|
+
ariaLabel?: string;
|
|
9
|
+
alignment?: JustifyContentSetting;
|
|
10
|
+
size?: Size;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An interactive pagination component that parameterizes Bootstrap styling
|
|
14
|
+
* options as props.
|
|
15
|
+
* @param numPages - Total number of pages
|
|
16
|
+
* @param numButtons - Number of buttons of numerical indices to show at once
|
|
17
|
+
* @param pageNum - The currently selected page
|
|
18
|
+
* @param setPageNum - Callback function to set the selected page
|
|
19
|
+
* @param ariaLabel - Aria label of the <nav> element
|
|
20
|
+
* @param alignment - Flexbox justify-content setting on the <ul> element
|
|
21
|
+
* @param size - Size variant of the <ul> element
|
|
22
|
+
*/
|
|
23
|
+
declare const PageSelector: FC<PageSelectorProps>;
|
|
24
|
+
export default PageSelector;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
/**
|
|
6
|
+
* An interactive pagination component that parameterizes Bootstrap styling
|
|
7
|
+
* options as props.
|
|
8
|
+
* @param numPages - Total number of pages
|
|
9
|
+
* @param numButtons - Number of buttons of numerical indices to show at once
|
|
10
|
+
* @param pageNum - The currently selected page
|
|
11
|
+
* @param setPageNum - Callback function to set the selected page
|
|
12
|
+
* @param ariaLabel - Aria label of the <nav> element
|
|
13
|
+
* @param alignment - Flexbox justify-content setting on the <ul> element
|
|
14
|
+
* @param size - Size variant of the <ul> element
|
|
15
|
+
*/
|
|
16
|
+
var PageSelector = function (_a) {
|
|
17
|
+
var numPages = _a.numPages, numButtons = _a.numButtons, pageNum = _a.pageNum, setPageNum = _a.setPageNum, ariaLabel = _a.ariaLabel, alignment = _a.alignment, size = _a.size;
|
|
18
|
+
var ulClasses = ["pagination"];
|
|
19
|
+
if (size === "small") {
|
|
20
|
+
ulClasses.push("pagination-sm");
|
|
21
|
+
}
|
|
22
|
+
else if (size === "large") {
|
|
23
|
+
ulClasses.push("pagination-lg");
|
|
24
|
+
}
|
|
25
|
+
if (alignment) {
|
|
26
|
+
ulClasses.push("justify-content-".concat(alignment));
|
|
27
|
+
}
|
|
28
|
+
var lowerBound = pageNum - Math.floor((numButtons - 1) / 2);
|
|
29
|
+
var upperBound = pageNum + Math.ceil((numButtons - 1) / 2);
|
|
30
|
+
if (upperBound > numPages) {
|
|
31
|
+
var diff = upperBound - numPages;
|
|
32
|
+
lowerBound = Math.max(lowerBound - diff, 1);
|
|
33
|
+
upperBound -= diff;
|
|
34
|
+
}
|
|
35
|
+
else if (lowerBound < 1) {
|
|
36
|
+
var diff = 1 - lowerBound;
|
|
37
|
+
lowerBound = 1;
|
|
38
|
+
upperBound = Math.min(numPages, upperBound + diff);
|
|
39
|
+
}
|
|
40
|
+
var buttonIndices = useMemo(function () {
|
|
41
|
+
var indices = [];
|
|
42
|
+
for (var i = lowerBound; i <= upperBound; i++) {
|
|
43
|
+
indices.push(i);
|
|
44
|
+
}
|
|
45
|
+
return indices;
|
|
46
|
+
}, [lowerBound, upperBound]);
|
|
47
|
+
function getFirstArrowButton() {
|
|
48
|
+
if (lowerBound === 1) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "First", onClick: function (event) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
setPageNum(1);
|
|
54
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: "<<" }) }) }));
|
|
55
|
+
}
|
|
56
|
+
function getPrevArrowButton() {
|
|
57
|
+
if (pageNum === 1) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Previous", onClick: function (event) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
setPageNum(pageNum - 1);
|
|
63
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: "<" }) }) }));
|
|
64
|
+
}
|
|
65
|
+
function getNextArrowButton() {
|
|
66
|
+
if (pageNum === numPages) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Next", onClick: function (event) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
setPageNum(pageNum + 1);
|
|
72
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: ">" }) }) }));
|
|
73
|
+
}
|
|
74
|
+
function getLastArrowButton() {
|
|
75
|
+
if (upperBound === numPages) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return (_jsx("li", { className: "page-item", children: _jsx("a", { className: "page-link", href: "#", "aria-label": "Last", onClick: function (event) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
setPageNum(numPages);
|
|
81
|
+
}, children: _jsx("span", { "aria-hidden": "true", children: ">>" }) }) }));
|
|
82
|
+
}
|
|
83
|
+
var indexButtons = buttonIndices.map(function (buttonIndex) { return (_jsx("li", { className: classNames({
|
|
84
|
+
"page-item": true,
|
|
85
|
+
active: pageNum === buttonIndex,
|
|
86
|
+
}), "aria-current": pageNum === buttonIndex ? "page" : undefined, children: _jsx("a", { className: "page-link", href: "#", onClick: function (event) {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
setPageNum(buttonIndex);
|
|
89
|
+
}, children: buttonIndex }) }, buttonIndex)); });
|
|
90
|
+
return (_jsx("nav", { "aria-label": ariaLabel, children: _jsxs("ul", { className: classNames(ulClasses), children: [getFirstArrowButton(), getPrevArrowButton(), indexButtons, getNextArrowButton(), getLastArrowButton()] }) }));
|
|
91
|
+
};
|
|
92
|
+
export default PageSelector;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { Size } from "../types";
|
|
3
|
+
export interface PageSizeSelectorProps {
|
|
4
|
+
componentSize: Size;
|
|
5
|
+
pageSizeOptions: number[];
|
|
6
|
+
pageSizeIndex: number;
|
|
7
|
+
handleSetPageSize: (index: number) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const PageSizeSelector: FC<PageSizeSelectorProps>;
|
|
10
|
+
export default PageSizeSelector;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
var PageSizeSelector = function (_a) {
|
|
4
|
+
var componentSize = _a.componentSize, pageSizeOptions = _a.pageSizeOptions, pageSizeIndex = _a.pageSizeIndex, handleSetPageSize = _a.handleSetPageSize;
|
|
5
|
+
var onChange = function (event) {
|
|
6
|
+
var pageSizeIndex = Number(event.target.value);
|
|
7
|
+
handleSetPageSize(pageSizeIndex);
|
|
8
|
+
};
|
|
9
|
+
return (_jsx("div", { children: _jsx("select", { className: classNames({
|
|
10
|
+
"form-select": true,
|
|
11
|
+
"form-select-lg": componentSize === "large",
|
|
12
|
+
"form-select-sm": componentSize === "small",
|
|
13
|
+
}), value: pageSizeIndex, "aria-label": "Number of Rows per Page", onChange: onChange, children: pageSizeOptions.map(function (numRows, index) { return (_jsx("option", { value: index, children: numRows }, index)); }) }) }));
|
|
14
|
+
};
|
|
15
|
+
export default PageSizeSelector;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { NormalizedPaginationModel } from "./types";
|
|
3
|
+
export interface PaginationProps {
|
|
4
|
+
normalizedModel: NormalizedPaginationModel;
|
|
5
|
+
prePagingNumRows: number;
|
|
6
|
+
containerDivClasses: string[];
|
|
7
|
+
}
|
|
8
|
+
declare const Pagination: FC<PaginationProps>;
|
|
9
|
+
export default Pagination;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import PageSizeSelector from "./PageSizeSelector";
|
|
3
|
+
import PageSelector from "./PageSelector";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
var Pagination = function (_a) {
|
|
6
|
+
var normalizedModel = _a.normalizedModel, prePagingNumRows = _a.prePagingNumRows, containerDivClasses = _a.containerDivClasses;
|
|
7
|
+
var pageSizeOptions = normalizedModel.pageSizeOptions, pageSizeIndex = normalizedModel.pageSizeIndex, currentPage = normalizedModel.currentPage, setCurrentPage = normalizedModel.setCurrentPage, setPageSizeIndex = normalizedModel.setPageSizeIndex, componentSize = normalizedModel.componentSize, maxPageButtons = normalizedModel.maxPageButtons, pageSelectorAriaLabel = normalizedModel.pageSelectorAriaLabel, pageSelectorJustifyContent = normalizedModel.pageSelectorJustifyContent;
|
|
8
|
+
var numPages = Math.ceil(prePagingNumRows / pageSizeOptions[pageSizeIndex]);
|
|
9
|
+
var pageIndexAwarePageSizeSetter = function (newPageSizeIndex) {
|
|
10
|
+
var newPageSize = pageSizeOptions[newPageSizeIndex];
|
|
11
|
+
var maxPages = Math.ceil(prePagingNumRows / newPageSize);
|
|
12
|
+
setPageSizeIndex(newPageSizeIndex);
|
|
13
|
+
// The new page size can cause the current page number to be out of bounds.
|
|
14
|
+
// In that case, set the page num to the maximum possible with new page
|
|
15
|
+
// size.
|
|
16
|
+
if (currentPage > maxPages) {
|
|
17
|
+
setCurrentPage(maxPages);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return (_jsxs("div", { "data-testid": "pagination ui container div", className: classNames(containerDivClasses.length > 0
|
|
21
|
+
? containerDivClasses
|
|
22
|
+
: ["d-flex", "justify-content-end", "gap-2", "px-2"]), children: [_jsx(PageSizeSelector, { componentSize: componentSize, pageSizeOptions: pageSizeOptions, pageSizeIndex: pageSizeIndex, handleSetPageSize: pageIndexAwarePageSizeSetter }), _jsx(PageSelector, { numPages: numPages, pageNum: currentPage, numButtons: maxPageButtons, setPageNum: setCurrentPage, size: componentSize, ariaLabel: pageSelectorAriaLabel, alignment: pageSelectorJustifyContent })] }));
|
|
23
|
+
};
|
|
24
|
+
export default Pagination;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { JustifyContentSetting, Size } from "../types";
|
|
2
|
+
export interface PaginationOptions {
|
|
3
|
+
pageSizeOptions?: number[];
|
|
4
|
+
maxPageButtons?: number;
|
|
5
|
+
componentSize?: Size;
|
|
6
|
+
pageSelectorAriaLabel?: string;
|
|
7
|
+
pageSelectorJustifyContent?: JustifyContentSetting;
|
|
8
|
+
}
|
|
9
|
+
export type ControlledPaginationModel = PaginationOptions & {
|
|
10
|
+
type?: "controlled";
|
|
11
|
+
pageSizeIndex: number;
|
|
12
|
+
setPageSizeIndex: (pageSizeIndex: number) => void;
|
|
13
|
+
currentPage: number;
|
|
14
|
+
setCurrentPage: (pageNum: number) => void;
|
|
15
|
+
};
|
|
16
|
+
export type UncontrolledPaginationModel = PaginationOptions & {
|
|
17
|
+
type: "uncontrolled";
|
|
18
|
+
startingPageSizeIndex?: number;
|
|
19
|
+
startingCurrentPage?: number;
|
|
20
|
+
};
|
|
21
|
+
export type GridPaginationState = ControlledPaginationModel | UncontrolledPaginationModel;
|
|
22
|
+
export type NormalizedPaginationModel = Required<Omit<ControlledPaginationModel, "type" | "pageSelectorAriaLabel" | "pageSelectorJustifyContent">> & Pick<ControlledPaginationModel, "pageSelectorAriaLabel" | "pageSelectorJustifyContent">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ColNameToWidth<ColName extends string = string> = Record<ColName, number | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useMemo } from "react";
|
|
13
|
+
var useAugFormattedRows = function (colNameToWidth, rows) {
|
|
14
|
+
return useMemo(function () {
|
|
15
|
+
return rows.map(function (row) {
|
|
16
|
+
return __assign(__assign({}, row), { contents: row.contents.map(function (cell) {
|
|
17
|
+
return __assign(__assign({}, cell), { width: colNameToWidth[cell.fieldName] });
|
|
18
|
+
}) });
|
|
19
|
+
});
|
|
20
|
+
}, [colNameToWidth, rows]);
|
|
21
|
+
};
|
|
22
|
+
export default useAugFormattedRows;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SortedRowsOutput } from "./useSortedRows";
|
|
2
|
+
import { CurrentPageRowsOutput } from "./useCurrentPageRows";
|
|
3
|
+
import { ColDefBase, FormattedRow, GridProps, RowDef } from "../../types";
|
|
4
|
+
import { NormalizedTableFilterModel, TableFilterState } from "../../filtering/types";
|
|
5
|
+
export type CombinedPipelineParams = Pick<GridProps, "rows" | "filterModel" | "sortModel" | "pagination" | "selectModel"> & {
|
|
6
|
+
cols: ColDefBase[];
|
|
7
|
+
};
|
|
8
|
+
export interface UseCombinedPipelineHook {
|
|
9
|
+
normalizedTableFilterModel: NormalizedTableFilterModel | null;
|
|
10
|
+
filteredRows: RowDef[];
|
|
11
|
+
filterState: TableFilterState | null;
|
|
12
|
+
sortedRowsOutput: SortedRowsOutput;
|
|
13
|
+
currentPageRowsOutput: CurrentPageRowsOutput;
|
|
14
|
+
showSelectCol: boolean;
|
|
15
|
+
ariaColIndexOffset: number;
|
|
16
|
+
displayRows: FormattedRow[];
|
|
17
|
+
}
|
|
18
|
+
declare const UseCombinedPipeline: (params: CombinedPipelineParams) => UseCombinedPipelineHook;
|
|
19
|
+
export default UseCombinedPipeline;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import useFilterStateStore from "./useFilterStateStore";
|
|
2
|
+
import useFilter from "./useFilter";
|
|
3
|
+
import useFilterStateFromEditable from "./useFilterStateFromEditable";
|
|
4
|
+
import useSortedRows from "./useSortedRows";
|
|
5
|
+
import useCurrentPageRows from "./useCurrentPageRows";
|
|
6
|
+
import useDisplayRows from "./useDisplayRows";
|
|
7
|
+
var UseCombinedPipeline = function (_a) {
|
|
8
|
+
var filterModel = _a.filterModel, cols = _a.cols, rows = _a.rows, sortModel = _a.sortModel, pagination = _a.pagination, selectModel = _a.selectModel;
|
|
9
|
+
var normalizedTableFilterModel = useFilterStateStore(filterModel, cols);
|
|
10
|
+
var editableFilterState = (normalizedTableFilterModel === null || normalizedTableFilterModel === void 0 ? void 0 : normalizedTableFilterModel.tableFilterState) || null;
|
|
11
|
+
var filteredRows = useFilter(rows, editableFilterState);
|
|
12
|
+
var filterState = useFilterStateFromEditable(cols, editableFilterState);
|
|
13
|
+
var sortedRowsOutput = useSortedRows(filteredRows, cols, sortModel);
|
|
14
|
+
var sortedRows = sortedRowsOutput.sortedRows;
|
|
15
|
+
var currentPageRowsOutput = useCurrentPageRows(sortedRows, pagination);
|
|
16
|
+
var showSelectCol = !!(selectModel && selectModel.mode !== "row");
|
|
17
|
+
var ariaColIndexOffset = showSelectCol ? 1 : 0;
|
|
18
|
+
var paginatedRows = currentPageRowsOutput.paginatedRows;
|
|
19
|
+
var displayRows = useDisplayRows(paginatedRows, cols, ariaColIndexOffset);
|
|
20
|
+
return {
|
|
21
|
+
normalizedTableFilterModel: normalizedTableFilterModel,
|
|
22
|
+
filteredRows: filteredRows,
|
|
23
|
+
filterState: filterState,
|
|
24
|
+
sortedRowsOutput: sortedRowsOutput,
|
|
25
|
+
currentPageRowsOutput: currentPageRowsOutput,
|
|
26
|
+
showSelectCol: showSelectCol,
|
|
27
|
+
ariaColIndexOffset: ariaColIndexOffset,
|
|
28
|
+
displayRows: displayRows,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default UseCombinedPipeline;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RowDef } from "../../types";
|
|
2
|
+
import { NormalizedPaginationModel, GridPaginationState } from "../../pagination/types";
|
|
3
|
+
export interface CurrentPageRowsOutput {
|
|
4
|
+
paginatedRows: RowDef[];
|
|
5
|
+
normalizedModel: NormalizedPaginationModel | null;
|
|
6
|
+
}
|
|
7
|
+
declare const useCurrentPageRows: (sortedRows: RowDef[], paginationModel: GridPaginationState | undefined) => CurrentPageRowsOutput;
|
|
8
|
+
export default useCurrentPageRows;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
var useCurrentPageRows = function (sortedRows, paginationModel) {
|
|
3
|
+
var componentSize = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.componentSize) || "medium";
|
|
4
|
+
var isControlled = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.type) !== "uncontrolled";
|
|
5
|
+
var _a = useState(isControlled ? 0 : paginationModel.startingPageSizeIndex || 0), internalPageSizeIndex = _a[0], setInternalPageSizeIndex = _a[1];
|
|
6
|
+
var pageSizeIndex = isControlled
|
|
7
|
+
? (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSizeIndex) || 0
|
|
8
|
+
: internalPageSizeIndex;
|
|
9
|
+
var setPageSizeIndex = isControlled
|
|
10
|
+
? paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.setPageSizeIndex
|
|
11
|
+
: setInternalPageSizeIndex;
|
|
12
|
+
var _b = useState(isControlled ? 1 : paginationModel.startingCurrentPage || 1), internalPageNum = _b[0], setInternalPageNum = _b[1];
|
|
13
|
+
var currentPage = isControlled
|
|
14
|
+
? (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.currentPage) || 1
|
|
15
|
+
: internalPageNum;
|
|
16
|
+
var setCurrentPage = isControlled
|
|
17
|
+
? paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.setCurrentPage
|
|
18
|
+
: setInternalPageNum;
|
|
19
|
+
var maxPageButtons = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.maxPageButtons) || 5;
|
|
20
|
+
return useMemo(function () {
|
|
21
|
+
if (paginationModel === undefined) {
|
|
22
|
+
return { paginatedRows: sortedRows, normalizedModel: null };
|
|
23
|
+
}
|
|
24
|
+
var pageSizeOptions = (paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSizeOptions) || [10, 25, 100];
|
|
25
|
+
var normalizedModel = {
|
|
26
|
+
pageSizeIndex: pageSizeIndex,
|
|
27
|
+
setPageSizeIndex: setPageSizeIndex,
|
|
28
|
+
currentPage: currentPage,
|
|
29
|
+
setCurrentPage: setCurrentPage,
|
|
30
|
+
pageSizeOptions: pageSizeOptions,
|
|
31
|
+
maxPageButtons: maxPageButtons,
|
|
32
|
+
componentSize: componentSize,
|
|
33
|
+
pageSelectorAriaLabel: paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSelectorAriaLabel,
|
|
34
|
+
pageSelectorJustifyContent: paginationModel === null || paginationModel === void 0 ? void 0 : paginationModel.pageSelectorJustifyContent,
|
|
35
|
+
};
|
|
36
|
+
var pageSize = pageSizeOptions[pageSizeIndex];
|
|
37
|
+
var lowerIndex = pageSize * (currentPage - 1);
|
|
38
|
+
var upperIndex = lowerIndex + pageSize;
|
|
39
|
+
var paginatedRows = sortedRows.slice(lowerIndex, upperIndex);
|
|
40
|
+
return { paginatedRows: paginatedRows, normalizedModel: normalizedModel };
|
|
41
|
+
}, [
|
|
42
|
+
paginationModel,
|
|
43
|
+
pageSizeIndex,
|
|
44
|
+
setPageSizeIndex,
|
|
45
|
+
currentPage,
|
|
46
|
+
setCurrentPage,
|
|
47
|
+
maxPageButtons,
|
|
48
|
+
componentSize,
|
|
49
|
+
sortedRows,
|
|
50
|
+
]);
|
|
51
|
+
};
|
|
52
|
+
export default useCurrentPageRows;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { dateToDatetimeInputStr, dateToInputStr } from "../../util/datetime";
|
|
3
|
+
var getFormattedValue = function (value, formatter, typeString) {
|
|
4
|
+
if (formatter) {
|
|
5
|
+
return formatter(value);
|
|
6
|
+
}
|
|
7
|
+
if (typeString === "date") {
|
|
8
|
+
return dateToInputStr(value);
|
|
9
|
+
}
|
|
10
|
+
if (typeString === "datetime") {
|
|
11
|
+
return dateToDatetimeInputStr(value);
|
|
12
|
+
}
|
|
13
|
+
if (typeString === "number") {
|
|
14
|
+
return value.toString();
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
var useDisplayRows = function (currentPageRows, cols, ariaColIndexOffset) {
|
|
19
|
+
return useMemo(function () {
|
|
20
|
+
var nameToIndex = new Map();
|
|
21
|
+
cols.forEach(function (_a, index) {
|
|
22
|
+
var name = _a.name;
|
|
23
|
+
nameToIndex.set(name, index);
|
|
24
|
+
});
|
|
25
|
+
return currentPageRows.map(function (row, index) {
|
|
26
|
+
cols
|
|
27
|
+
.map(function (_a) {
|
|
28
|
+
var name = _a.name;
|
|
29
|
+
return name;
|
|
30
|
+
})
|
|
31
|
+
.forEach(function (name) {
|
|
32
|
+
if (!(name in row.data)) {
|
|
33
|
+
throw new Error("Column definition specifies a property named \"".concat(name, "\", but it was not found in the row data object at index ").concat(index, "."));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var displayRow = [];
|
|
37
|
+
Object.keys(row.data).forEach(function (name) {
|
|
38
|
+
if (!nameToIndex.has(name)) {
|
|
39
|
+
console.error("Warning: row data contains a property named \"".concat(name, "\", but it was not found among the column definitions."));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var index = nameToIndex.get(name);
|
|
43
|
+
var col = cols[index];
|
|
44
|
+
var formatter = col.formatter;
|
|
45
|
+
var typeString = col.type;
|
|
46
|
+
var value = row.data[name];
|
|
47
|
+
displayRow[index] = {
|
|
48
|
+
fieldName: cols[index].name,
|
|
49
|
+
value: value,
|
|
50
|
+
type: typeString,
|
|
51
|
+
ariaColIndex: index + 1 + ariaColIndexOffset,
|
|
52
|
+
formattedValue: getFormattedValue(value, formatter, typeString),
|
|
53
|
+
label: cols[index].label,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
return { contents: displayRow, id: row.id };
|
|
57
|
+
});
|
|
58
|
+
}, [currentPageRows, cols, ariaColIndexOffset]);
|
|
59
|
+
};
|
|
60
|
+
export default useDisplayRows;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
var useFilter = function (rows, filterState) {
|
|
3
|
+
return useMemo(function () {
|
|
4
|
+
if (filterState === null) {
|
|
5
|
+
return rows;
|
|
6
|
+
}
|
|
7
|
+
return rows.filter(function (row) {
|
|
8
|
+
function checkIfPassesStringFilter(value, state) {
|
|
9
|
+
switch (state.scheme) {
|
|
10
|
+
case "contains": {
|
|
11
|
+
return value.includes(state.searchString);
|
|
12
|
+
}
|
|
13
|
+
case "startsWith": {
|
|
14
|
+
return value.startsWith(state.searchString);
|
|
15
|
+
}
|
|
16
|
+
default: {
|
|
17
|
+
return value.endsWith(state.searchString);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function checkIfPassesNumberFilter(value, state) {
|
|
22
|
+
// Note that a blank string becomes 0. This situation should usually be
|
|
23
|
+
// prevented by form validation.
|
|
24
|
+
var numValue = Number(state.numValue);
|
|
25
|
+
switch (state.scheme) {
|
|
26
|
+
case "equals":
|
|
27
|
+
return value === numValue;
|
|
28
|
+
case "greaterThan":
|
|
29
|
+
return value > numValue;
|
|
30
|
+
case "lessThan":
|
|
31
|
+
return value < numValue;
|
|
32
|
+
case "greaterOrEqual":
|
|
33
|
+
return value >= numValue;
|
|
34
|
+
default:
|
|
35
|
+
return value <= numValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function checkIfPassesDateFilter(value, state) {
|
|
39
|
+
switch (state.scheme) {
|
|
40
|
+
case "startFrom":
|
|
41
|
+
return state.startDate === null || value >= state.startDate;
|
|
42
|
+
case "endAt":
|
|
43
|
+
return state.endDate === null || value <= state.endDate;
|
|
44
|
+
case "between":
|
|
45
|
+
return (state.startDate === null ||
|
|
46
|
+
state.endDate === null ||
|
|
47
|
+
(value >= state.startDate && value <= state.endDate));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var columnNames = Object.keys(row.data);
|
|
51
|
+
for (var _i = 0, columnNames_1 = columnNames; _i < columnNames_1.length; _i++) {
|
|
52
|
+
var columnName = columnNames_1[_i];
|
|
53
|
+
if (!(columnName in filterState)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!filterState[columnName].enabled) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
var columnFilterState = filterState[columnName];
|
|
60
|
+
switch (columnFilterState.type) {
|
|
61
|
+
case "string": {
|
|
62
|
+
if (!checkIfPassesStringFilter(row.data[columnName], columnFilterState)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "number": {
|
|
68
|
+
if (!checkIfPassesNumberFilter(row.data[columnName], columnFilterState)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
default: {
|
|
74
|
+
if (!checkIfPassesDateFilter(row.data[columnName], columnFilterState)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
}, [rows, filterState]);
|
|
83
|
+
};
|
|
84
|
+
export default useFilter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ColDef } from "../../types";
|
|
2
|
+
import { EditableTableFilterState, TableFilterState } from "../../filtering/types";
|
|
3
|
+
declare const useFilterStateFromEditable: (colDefs: ColDef[], editableFilterState: EditableTableFilterState | null) => TableFilterState | null;
|
|
4
|
+
export default useFilterStateFromEditable;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
var useFilterStateFromEditable = function (colDefs, editableFilterState) {
|
|
3
|
+
return useMemo(function () {
|
|
4
|
+
if (editableFilterState === null) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
var filterState = {};
|
|
8
|
+
colDefs.forEach(function (_a) {
|
|
9
|
+
var name = _a.name, label = _a.label;
|
|
10
|
+
filterState[name] = {
|
|
11
|
+
editableState: editableFilterState[name],
|
|
12
|
+
label: label,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
return filterState;
|
|
16
|
+
}, [colDefs, editableFilterState]);
|
|
17
|
+
};
|
|
18
|
+
export default useFilterStateFromEditable;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FilterModel, NormalizedTableFilterModel } from "../../filtering/types";
|
|
2
|
+
import { ColDefBase } from "../../types";
|
|
3
|
+
declare const useFilterStateStore: (filterModel: FilterModel | undefined, cols: ColDefBase[]) => NormalizedTableFilterModel | null;
|
|
4
|
+
export default useFilterStateStore;
|