@patternfly/react-data-view 7.0.0-prerelease.2 → 7.0.0-prerelease.4
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/cjs/DataView/DataView.d.ts +3 -1
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +70 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +25 -0
- package/dist/cjs/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewCheckboxFilter/index.js +23 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.js +85 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.js +19 -0
- package/dist/cjs/DataViewFilters/index.d.ts +2 -0
- package/dist/cjs/DataViewFilters/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +8 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +26 -14
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +26 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +22 -0
- package/dist/cjs/DataViewTextFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewTextFilter/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +10 -4
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +29 -6
- package/dist/cjs/Hooks/filters.d.ts +14 -0
- package/dist/cjs/Hooks/filters.js +69 -0
- package/dist/cjs/Hooks/filters.test.d.ts +1 -0
- package/dist/cjs/Hooks/filters.test.js +50 -0
- package/dist/cjs/Hooks/index.d.ts +2 -0
- package/dist/cjs/Hooks/index.js +2 -0
- package/dist/cjs/Hooks/pagination.d.ts +1 -0
- package/dist/cjs/Hooks/selection.d.ts +1 -1
- package/dist/cjs/Hooks/selection.js +4 -2
- package/dist/cjs/Hooks/sort.d.ts +32 -0
- package/dist/cjs/Hooks/sort.js +47 -0
- package/dist/cjs/Hooks/sort.test.d.ts +1 -0
- package/dist/cjs/Hooks/sort.test.js +68 -0
- package/dist/cjs/InternalContext/InternalContext.d.ts +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +7 -1
- package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
- package/dist/dynamic/DataViewFilters/package.json +1 -0
- package/dist/dynamic/DataViewTextFilter/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +3 -1
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +62 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +20 -0
- package/dist/esm/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/esm/DataViewCheckboxFilter/index.js +2 -0
- package/dist/esm/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/esm/DataViewFilters/DataViewFilters.js +58 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.js +14 -0
- package/dist/esm/DataViewFilters/index.d.ts +2 -0
- package/dist/esm/DataViewFilters/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +8 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +26 -14
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +19 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +17 -0
- package/dist/esm/DataViewTextFilter/index.d.ts +2 -0
- package/dist/esm/DataViewTextFilter/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +10 -4
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +7 -4
- package/dist/esm/Hooks/filters.d.ts +14 -0
- package/dist/esm/Hooks/filters.js +65 -0
- package/dist/esm/Hooks/filters.test.d.ts +1 -0
- package/dist/esm/Hooks/filters.test.js +48 -0
- package/dist/esm/Hooks/index.d.ts +2 -0
- package/dist/esm/Hooks/index.js +2 -0
- package/dist/esm/Hooks/pagination.d.ts +1 -0
- package/dist/esm/Hooks/selection.d.ts +1 -1
- package/dist/esm/Hooks/selection.js +4 -2
- package/dist/esm/Hooks/sort.d.ts +32 -0
- package/dist/esm/Hooks/sort.js +43 -0
- package/dist/esm/Hooks/sort.test.d.ts +1 -0
- package/dist/esm/Hooks/sort.test.js +66 -0
- package/dist/esm/InternalContext/InternalContext.d.ts +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +5 -3
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +1 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +28 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/FiltersExample.tsx +107 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +67 -2
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SortingExample.tsx +87 -0
- package/src/DataView/DataView.tsx +3 -2
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +24 -0
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +175 -0
- package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +197 -0
- package/src/DataViewCheckboxFilter/index.ts +2 -0
- package/src/DataViewFilters/DataViewFilters.test.tsx +21 -0
- package/src/DataViewFilters/DataViewFilters.tsx +144 -0
- package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +194 -0
- package/src/DataViewFilters/index.tsx +2 -0
- package/src/DataViewTable/DataViewTable.tsx +23 -3
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +1 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +1 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +40 -18
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +24 -0
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +54 -0
- package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +203 -0
- package/src/DataViewTextFilter/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +47 -28
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +44 -0
- package/src/Hooks/filters.test.tsx +62 -0
- package/src/Hooks/filters.ts +97 -0
- package/src/Hooks/index.ts +2 -0
- package/src/Hooks/pagination.ts +1 -0
- package/src/Hooks/selection.ts +3 -2
- package/src/Hooks/sort.test.tsx +84 -0
- package/src/Hooks/sort.ts +87 -0
- package/src/InternalContext/InternalContext.tsx +1 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React, { useMemo, useState, useRef, useEffect } from 'react';
|
|
13
|
+
import { Menu, MenuContent, MenuItem, MenuList, MenuToggle, Popper, ToolbarGroup, ToolbarToggleGroup, } from '@patternfly/react-core';
|
|
14
|
+
import { FilterIcon } from '@patternfly/react-icons';
|
|
15
|
+
;
|
|
16
|
+
export const DataViewFilters = (_a) => {
|
|
17
|
+
var { children, ouiaId = 'DataViewFilters', toggleIcon = React.createElement(FilterIcon, null), breakpoint = 'xl', onChange, values } = _a, props = __rest(_a, ["children", "ouiaId", "toggleIcon", "breakpoint", "onChange", "values"]);
|
|
18
|
+
const [activeAttributeMenu, setActiveAttributeMenu] = useState('');
|
|
19
|
+
const [isAttributeMenuOpen, setIsAttributeMenuOpen] = useState(false);
|
|
20
|
+
const attributeToggleRef = useRef(null);
|
|
21
|
+
const attributeMenuRef = useRef(null);
|
|
22
|
+
const attributeContainerRef = useRef(null);
|
|
23
|
+
const childrenHash = useMemo(() => JSON.stringify(React.Children.map(children, (child) => React.isValidElement(child) ? { type: child.type, key: child.key, props: child.props } : child)), [children]);
|
|
24
|
+
const filterItems = useMemo(() => React.Children.toArray(children)
|
|
25
|
+
.map(child => React.isValidElement(child) ? { filterId: String(child.props.filterId), title: String(child.props.title) } : undefined).filter((item) => !!item), [childrenHash]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
filterItems.length > 0 && setActiveAttributeMenu(filterItems[0].title);
|
|
28
|
+
}, [filterItems]);
|
|
29
|
+
const handleClickOutside = (event) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return isAttributeMenuOpen &&
|
|
32
|
+
!((_a = attributeMenuRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target)) &&
|
|
33
|
+
!((_b = attributeToggleRef.current) === null || _b === void 0 ? void 0 : _b.contains(event.target))
|
|
34
|
+
&& setIsAttributeMenuOpen(false);
|
|
35
|
+
};
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
window.addEventListener('click', handleClickOutside);
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener('click', handleClickOutside);
|
|
40
|
+
};
|
|
41
|
+
}, [isAttributeMenuOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
42
|
+
const attributeToggle = (React.createElement(MenuToggle, { ref: attributeToggleRef, onClick: () => setIsAttributeMenuOpen(!isAttributeMenuOpen), isExpanded: isAttributeMenuOpen, icon: toggleIcon }, activeAttributeMenu));
|
|
43
|
+
const attributeMenu = (React.createElement(Menu, { ref: attributeMenuRef, onSelect: (_ev, itemId) => {
|
|
44
|
+
const selectedItem = filterItems.find(item => item.filterId === itemId);
|
|
45
|
+
selectedItem && setActiveAttributeMenu(selectedItem.title);
|
|
46
|
+
setIsAttributeMenuOpen(false);
|
|
47
|
+
} },
|
|
48
|
+
React.createElement(MenuContent, null,
|
|
49
|
+
React.createElement(MenuList, null, filterItems.map(item => (React.createElement(MenuItem, { key: item.filterId, itemId: item.filterId }, item.title)))))));
|
|
50
|
+
return (React.createElement(ToolbarToggleGroup, Object.assign({ "data-ouia-component-id": ouiaId, toggleIcon: toggleIcon, breakpoint: breakpoint }, props),
|
|
51
|
+
React.createElement(ToolbarGroup, { variant: "filter-group" },
|
|
52
|
+
React.createElement("div", { ref: attributeContainerRef },
|
|
53
|
+
React.createElement(Popper, { trigger: attributeToggle, triggerRef: attributeToggleRef, popper: attributeMenu, popperRef: attributeMenuRef, appendTo: attributeContainerRef.current || undefined, isVisible: isAttributeMenuOpen })),
|
|
54
|
+
React.Children.map(children, (child) => React.isValidElement(child)
|
|
55
|
+
? React.cloneElement(child, Object.assign({ showToolbarItem: activeAttributeMenu === child.props.title, onChange: (event, value) => onChange === null || onChange === void 0 ? void 0 : onChange(event, { [child.props.filterId]: value }), value: values === null || values === void 0 ? void 0 : values[child.props.filterId] }, child.props))
|
|
56
|
+
: child))));
|
|
57
|
+
};
|
|
58
|
+
export default DataViewFilters;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import DataViewFilters from './DataViewFilters';
|
|
4
|
+
import DataViewToolbar from '../DataViewToolbar';
|
|
5
|
+
import DataViewTextFilter from '../DataViewTextFilter';
|
|
6
|
+
describe('DataViewFilters component', () => {
|
|
7
|
+
const mockOnChange = jest.fn();
|
|
8
|
+
it('should render correctly', () => {
|
|
9
|
+
const { container } = render(React.createElement(DataViewToolbar, { filters: React.createElement(DataViewFilters, { onChange: mockOnChange, values: {} },
|
|
10
|
+
React.createElement(DataViewTextFilter, { filterId: "one", title: "One" }),
|
|
11
|
+
React.createElement(DataViewTextFilter, { filterId: "two", title: "Two" })) }));
|
|
12
|
+
expect(container).toMatchSnapshot();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -3,7 +3,9 @@ import { TdProps, ThProps, TrProps } from '@patternfly/react-table';
|
|
|
3
3
|
import { DataViewTableTreeProps } from '../DataViewTableTree';
|
|
4
4
|
import { DataViewTableBasicProps } from '../DataViewTableBasic';
|
|
5
5
|
export type DataViewTh = ReactNode | {
|
|
6
|
+
/** Table head cell node */
|
|
6
7
|
cell: ReactNode;
|
|
8
|
+
/** Props passed to Th */
|
|
7
9
|
props?: ThProps;
|
|
8
10
|
};
|
|
9
11
|
export declare const isDataViewThObject: (value: DataViewTh) => value is {
|
|
@@ -11,12 +13,17 @@ export declare const isDataViewThObject: (value: DataViewTh) => value is {
|
|
|
11
13
|
props?: ThProps;
|
|
12
14
|
};
|
|
13
15
|
export interface DataViewTrObject {
|
|
16
|
+
/** Array of rows */
|
|
14
17
|
row: DataViewTd[];
|
|
18
|
+
/** Unique identifier of a row */
|
|
15
19
|
id?: string;
|
|
20
|
+
/** Props passed to Tr */
|
|
16
21
|
props?: TrProps;
|
|
17
22
|
}
|
|
18
23
|
export type DataViewTd = ReactNode | {
|
|
24
|
+
/** Table body cell node */
|
|
19
25
|
cell: ReactNode;
|
|
26
|
+
/** Props passed to Td */
|
|
20
27
|
props?: TdProps;
|
|
21
28
|
};
|
|
22
29
|
export type DataViewTr = DataViewTd[] | DataViewTrObject;
|
|
@@ -28,6 +35,7 @@ export declare const isDataViewTrObject: (value: DataViewTr) => value is {
|
|
|
28
35
|
row: DataViewTd[];
|
|
29
36
|
id?: string;
|
|
30
37
|
};
|
|
38
|
+
/** extends DataViewTrObject */
|
|
31
39
|
export interface DataViewTrTree extends DataViewTrObject {
|
|
32
40
|
id: string;
|
|
33
41
|
children?: DataViewTrTree[];
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTr } from '../DataViewTable';
|
|
4
4
|
import { DataViewState } from '../DataView/DataView';
|
|
5
|
+
/** extends TableProps */
|
|
5
6
|
export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
6
7
|
/** Columns definition */
|
|
7
8
|
columns: DataViewTh[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TheadProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh } from '../DataViewTable';
|
|
4
|
+
/** extends TheadProps */
|
|
4
5
|
export interface DataViewTableHeadProps extends TheadProps {
|
|
5
6
|
/** Indicates whether table is a tree */
|
|
6
7
|
isTreeTable?: boolean;
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTrTree } from '../DataViewTable';
|
|
4
4
|
import { DataViewState } from '../DataView/DataView';
|
|
5
|
+
/** extends TableProps */
|
|
5
6
|
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
6
7
|
/** Columns definition */
|
|
7
8
|
columns: DataViewTh[];
|
|
@@ -14,19 +14,31 @@ import { Table, Tbody, Td, TreeRowWrapper, } from '@patternfly/react-table';
|
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
15
|
import { DataViewTableHead } from '../DataViewTableHead';
|
|
16
16
|
import { isDataViewTdObject } from '../DataViewTable';
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const getNodesAffectedBySelection = (allRows, node, isChecking, isSelected) => {
|
|
18
|
+
const getDescendants = (node) => node.children ? node.children.flatMap(getDescendants).concat(node) : [node];
|
|
19
|
+
const findParent = (child, rows) => {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = rows.find(row => { var _a; return (_a = row.children) === null || _a === void 0 ? void 0 : _a.some(c => c === child); })) !== null && _a !== void 0 ? _a : rows.flatMap(row => { var _a; return (_a = row.children) !== null && _a !== void 0 ? _a : []; }).map(c => findParent(child, [c])).find(p => p);
|
|
22
|
+
};
|
|
23
|
+
const getAncestors = (node) => {
|
|
24
|
+
const ancestors = [];
|
|
25
|
+
let parent = findParent(node, allRows);
|
|
26
|
+
while (parent) {
|
|
27
|
+
ancestors.push(parent);
|
|
28
|
+
parent = findParent(parent, allRows);
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
return ancestors;
|
|
31
|
+
};
|
|
32
|
+
const affectedNodes = new Set([node, ...getDescendants(node)]);
|
|
33
|
+
getAncestors(node).forEach(ancestor => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const allChildrenSelected = (_a = ancestor.children) === null || _a === void 0 ? void 0 : _a.every(child => (isSelected === null || isSelected === void 0 ? void 0 : isSelected(child)) || affectedNodes.has(child));
|
|
36
|
+
const anyChildAffected = (_b = ancestor.children) === null || _b === void 0 ? void 0 : _b.some(child => affectedNodes.has(child) || child.id === node.id);
|
|
37
|
+
if (isChecking ? !(isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && allChildrenSelected : (isSelected === null || isSelected === void 0 ? void 0 : isSelected(ancestor)) && anyChildAffected) {
|
|
38
|
+
affectedNodes.add(ancestor);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return Array.from(affectedNodes);
|
|
30
42
|
};
|
|
31
43
|
export const DataViewTableTree = (_a) => {
|
|
32
44
|
var { columns, rows, headStates, bodyStates, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "headStates", "bodyStates", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
@@ -44,7 +56,7 @@ export const DataViewTableTree = (_a) => {
|
|
|
44
56
|
}
|
|
45
57
|
const isExpanded = expandedNodeIds.includes(node.id);
|
|
46
58
|
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
47
|
-
const isChecked = isSelected
|
|
59
|
+
const isChecked = isSelected === null || isSelected === void 0 ? void 0 : isSelected(node);
|
|
48
60
|
let icon = leafIcon;
|
|
49
61
|
if (node.children) {
|
|
50
62
|
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
@@ -58,7 +70,7 @@ export const DataViewTableTree = (_a) => {
|
|
|
58
70
|
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
59
71
|
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [...otherDetailsExpandedNodeIds, node.id];
|
|
60
72
|
}),
|
|
61
|
-
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking,
|
|
73
|
+
onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking, getNodesAffectedBySelection(rows, node, isChecking, isSelected)),
|
|
62
74
|
rowIndex,
|
|
63
75
|
props: {
|
|
64
76
|
isExpanded,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SearchInputProps, ToolbarFilterProps } from '@patternfly/react-core';
|
|
3
|
+
/** extends SearchInputProps */
|
|
4
|
+
export interface DataViewTextFilterProps extends SearchInputProps {
|
|
5
|
+
/** Unique key for the filter attribute */
|
|
6
|
+
filterId: string;
|
|
7
|
+
/** Current filter value */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** Filter title displayed in the toolbar */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Callback for when the input value changes */
|
|
12
|
+
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
|
|
13
|
+
/** Controls visibility of the filter in the toolbar */
|
|
14
|
+
showToolbarItem?: ToolbarFilterProps['showToolbarItem'];
|
|
15
|
+
/** Trims input value on change */
|
|
16
|
+
trimValue?: boolean;
|
|
17
|
+
/** Custom OUIA ID */
|
|
18
|
+
ouiaId?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const DataViewTextFilter: React.FC<DataViewTextFilterProps>;
|
|
21
|
+
export default DataViewTextFilter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { SearchInput, ToolbarFilter } from '@patternfly/react-core';
|
|
14
|
+
export const DataViewTextFilter = (_a) => {
|
|
15
|
+
var { filterId, title, value = '', onChange, onClear = () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), showToolbarItem, trimValue = true, ouiaId = 'DataViewTextFilter' } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "onClear", "showToolbarItem", "trimValue", "ouiaId"]);
|
|
16
|
+
return (React.createElement(ToolbarFilter, { key: ouiaId, "data-ouia-component-id": ouiaId, labels: value.length > 0 ? [{ key: title, node: value }] : [], deleteLabel: () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), categoryName: title, showToolbarItem: showToolbarItem },
|
|
17
|
+
React.createElement(SearchInput, Object.assign({ searchInputId: filterId, value: value, onChange: (e, inputValue) => onChange === null || onChange === void 0 ? void 0 : onChange(e, trimValue ? inputValue.trim() : inputValue), onClear: onClear, placeholder: `Filter by ${title}`, "aria-label": `${title !== null && title !== void 0 ? title : filterId} filter`, "data-ouia-component-id": `${ouiaId}-input` }, props))));
|
|
18
|
+
};
|
|
19
|
+
export default DataViewTextFilter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import DataViewTextFilter from './DataViewTextFilter';
|
|
4
|
+
import DataViewToolbar from '../DataViewToolbar';
|
|
5
|
+
describe('DataViewTextFilter component', () => {
|
|
6
|
+
const mockOnChange = jest.fn();
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
filterId: 'test-filter',
|
|
9
|
+
title: 'Test Filter',
|
|
10
|
+
value: 'initial value',
|
|
11
|
+
onChange: mockOnChange,
|
|
12
|
+
};
|
|
13
|
+
it('should render correctly', () => {
|
|
14
|
+
const { container } = render(React.createElement(DataViewToolbar, { filters: React.createElement(DataViewTextFilter, Object.assign({}, defaultProps)) }));
|
|
15
|
+
expect(container).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
|
|
2
|
+
import { ToolbarProps } from '@patternfly/react-core';
|
|
3
|
+
/** extends ToolbarProps */
|
|
4
|
+
export interface DataViewToolbarProps extends Omit<PropsWithChildren<ToolbarProps>, 'ref'> {
|
|
3
5
|
/** Toolbar className */
|
|
4
6
|
className?: string;
|
|
5
7
|
/** Custom OUIA ID */
|
|
6
8
|
ouiaId?: string;
|
|
7
|
-
/** React
|
|
9
|
+
/** React node to display bulk select */
|
|
8
10
|
bulkSelect?: React.ReactNode;
|
|
9
|
-
/** React
|
|
11
|
+
/** React node to display pagination */
|
|
10
12
|
pagination?: React.ReactNode;
|
|
11
|
-
/** React
|
|
13
|
+
/** React node to display actions */
|
|
12
14
|
actions?: React.ReactNode;
|
|
15
|
+
/** React node to display filters */
|
|
16
|
+
filters?: React.ReactNode;
|
|
17
|
+
/** React node to display custom filter labels */
|
|
18
|
+
customLabelGroupContent?: React.ReactNode;
|
|
13
19
|
}
|
|
14
20
|
export declare const DataViewToolbar: React.FC<DataViewToolbarProps>;
|
|
15
21
|
export default DataViewToolbar;
|
|
@@ -9,14 +9,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
12
|
+
import React, { useRef } from 'react';
|
|
13
|
+
import { Button, Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
14
14
|
export const DataViewToolbar = (_a) => {
|
|
15
|
-
var { className, ouiaId = 'DataViewToolbar', bulkSelect, actions, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "actions", "pagination", "children"]);
|
|
16
|
-
|
|
15
|
+
var { className, ouiaId = 'DataViewToolbar', bulkSelect, actions, pagination, filters, customLabelGroupContent, clearAllFilters, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "actions", "pagination", "filters", "customLabelGroupContent", "clearAllFilters", "children"]);
|
|
16
|
+
const defaultClearFilters = useRef(React.createElement(ToolbarItem, null,
|
|
17
|
+
React.createElement(Button, { ouiaId: `${ouiaId}-clear-all-filters`, variant: "link", onClick: clearAllFilters, isInline: true }, "Clear filters")));
|
|
18
|
+
return (React.createElement(Toolbar, Object.assign({ ouiaId: ouiaId, className: className, customLabelGroupContent: customLabelGroupContent !== null && customLabelGroupContent !== void 0 ? customLabelGroupContent : defaultClearFilters.current }, props),
|
|
17
19
|
React.createElement(ToolbarContent, null,
|
|
18
20
|
bulkSelect && (React.createElement(ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
|
|
19
21
|
actions && (React.createElement(ToolbarItem, null, actions)),
|
|
22
|
+
filters && (React.createElement(ToolbarItem, null, filters)),
|
|
20
23
|
pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
|
|
21
24
|
children)));
|
|
22
25
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface UseDataViewFiltersProps<T extends object> {
|
|
2
|
+
/** Initial filters object */
|
|
3
|
+
initialFilters?: T;
|
|
4
|
+
/** Current search parameters as a string */
|
|
5
|
+
searchParams?: URLSearchParams;
|
|
6
|
+
/** Function to set search parameters */
|
|
7
|
+
setSearchParams?: (params: URLSearchParams) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useDataViewFilters: <T extends object>({ initialFilters, searchParams, setSearchParams, }: UseDataViewFiltersProps<T>) => {
|
|
10
|
+
filters: T;
|
|
11
|
+
onSetFilters: (newFilters: Partial<T>) => void;
|
|
12
|
+
onDeleteFilters: (filtersToDelete: Partial<T>) => void;
|
|
13
|
+
clearAllFilters: () => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect, useMemo } from "react";
|
|
2
|
+
;
|
|
3
|
+
export const useDataViewFilters = ({ initialFilters = {}, searchParams, setSearchParams, }) => {
|
|
4
|
+
const isUrlSyncEnabled = useMemo(() => searchParams && !!setSearchParams, [searchParams, setSearchParams]);
|
|
5
|
+
const getInitialFilters = useCallback(() => isUrlSyncEnabled
|
|
6
|
+
? Object.keys(initialFilters).reduce((loadedFilters, key) => {
|
|
7
|
+
const urlValue = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get(key);
|
|
8
|
+
const isArrayFilter = Array.isArray(initialFilters[key]);
|
|
9
|
+
// eslint-disable-next-line no-nested-ternary
|
|
10
|
+
loadedFilters[key] = urlValue
|
|
11
|
+
? (isArrayFilter && !Array.isArray(urlValue) ? [urlValue] : urlValue)
|
|
12
|
+
: initialFilters[key];
|
|
13
|
+
return loadedFilters;
|
|
14
|
+
}, Object.assign({}, initialFilters))
|
|
15
|
+
: initialFilters, [isUrlSyncEnabled, initialFilters, searchParams]);
|
|
16
|
+
const [filters, setFilters] = useState(getInitialFilters());
|
|
17
|
+
const updateSearchParams = useCallback((newFilters) => {
|
|
18
|
+
if (isUrlSyncEnabled) {
|
|
19
|
+
const params = new URLSearchParams(searchParams);
|
|
20
|
+
Object.entries(newFilters).forEach(([key, value]) => {
|
|
21
|
+
params.delete(key);
|
|
22
|
+
(Array.isArray(value) ? value : [value]).forEach((val) => value && params.append(key, val));
|
|
23
|
+
});
|
|
24
|
+
setSearchParams === null || setSearchParams === void 0 ? void 0 : setSearchParams(params);
|
|
25
|
+
}
|
|
26
|
+
}, [isUrlSyncEnabled, searchParams, setSearchParams]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
isUrlSyncEnabled && setFilters(getInitialFilters());
|
|
29
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
30
|
+
const onSetFilters = useCallback((newFilters) => {
|
|
31
|
+
setFilters(prevFilters => {
|
|
32
|
+
const updatedFilters = Object.assign(Object.assign({}, prevFilters), newFilters);
|
|
33
|
+
isUrlSyncEnabled && updateSearchParams(updatedFilters);
|
|
34
|
+
return updatedFilters;
|
|
35
|
+
});
|
|
36
|
+
}, [isUrlSyncEnabled, updateSearchParams]);
|
|
37
|
+
// helper function to reset filters
|
|
38
|
+
const resetFilterValues = useCallback((filters) => Object.entries(filters).reduce((acc, [key, value]) => {
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
acc[key] = [];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
acc[key] = '';
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, {}), []);
|
|
47
|
+
const onDeleteFilters = useCallback((filtersToDelete) => {
|
|
48
|
+
setFilters(prevFilters => {
|
|
49
|
+
const updatedFilters = Object.assign(Object.assign({}, prevFilters), resetFilterValues(filtersToDelete));
|
|
50
|
+
isUrlSyncEnabled && updateSearchParams(updatedFilters);
|
|
51
|
+
return updatedFilters;
|
|
52
|
+
});
|
|
53
|
+
}, [isUrlSyncEnabled, updateSearchParams, resetFilterValues]);
|
|
54
|
+
const clearAllFilters = useCallback(() => {
|
|
55
|
+
const clearedFilters = resetFilterValues(filters);
|
|
56
|
+
setFilters(clearedFilters);
|
|
57
|
+
isUrlSyncEnabled && updateSearchParams(clearedFilters);
|
|
58
|
+
}, [filters, isUrlSyncEnabled, updateSearchParams, resetFilterValues]);
|
|
59
|
+
return {
|
|
60
|
+
filters,
|
|
61
|
+
onSetFilters,
|
|
62
|
+
onDeleteFilters,
|
|
63
|
+
clearAllFilters,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { renderHook, act } from '@testing-library/react';
|
|
3
|
+
import { useDataViewFilters } from './filters';
|
|
4
|
+
describe('useDataViewFilters', () => {
|
|
5
|
+
const initialFilters = { search: 'test', tags: ['tag1', 'tag2'] };
|
|
6
|
+
it('should initialize with provided initial filters', () => {
|
|
7
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
8
|
+
expect(result.current.filters).toEqual(initialFilters);
|
|
9
|
+
});
|
|
10
|
+
it('should initialize with empty filters if no initialFilters provided', () => {
|
|
11
|
+
const { result } = renderHook(() => useDataViewFilters({}));
|
|
12
|
+
expect(result.current.filters).toEqual({});
|
|
13
|
+
});
|
|
14
|
+
it('should set filters correctly', () => {
|
|
15
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
16
|
+
const newFilters = { search: 'new search' };
|
|
17
|
+
act(() => result.current.onSetFilters(newFilters));
|
|
18
|
+
expect(result.current.filters).toEqual(Object.assign(Object.assign({}, initialFilters), newFilters));
|
|
19
|
+
});
|
|
20
|
+
it('should delete specific filters without removing keys', () => {
|
|
21
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
22
|
+
const filtersToDelete = { search: 'test' };
|
|
23
|
+
act(() => result.current.onDeleteFilters(filtersToDelete));
|
|
24
|
+
expect(result.current.filters).toEqual({ search: '', tags: ['tag1', 'tag2'] });
|
|
25
|
+
});
|
|
26
|
+
it('should clear all filters', () => {
|
|
27
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
28
|
+
act(() => result.current.clearAllFilters());
|
|
29
|
+
expect(result.current.filters).toEqual({ search: '', tags: [] });
|
|
30
|
+
});
|
|
31
|
+
it('should sync with URL search params if isUrlSyncEnabled', () => {
|
|
32
|
+
const searchParams = new URLSearchParams();
|
|
33
|
+
const setSearchParams = jest.fn();
|
|
34
|
+
const props = {
|
|
35
|
+
initialFilters,
|
|
36
|
+
searchParams,
|
|
37
|
+
setSearchParams,
|
|
38
|
+
};
|
|
39
|
+
const { result } = renderHook(() => useDataViewFilters(props));
|
|
40
|
+
act(() => result.current.onSetFilters({ search: 'new search' }));
|
|
41
|
+
expect(setSearchParams).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
it('should reset filters to default values when clearAllFilters is called', () => {
|
|
44
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
45
|
+
act(() => result.current.clearAllFilters());
|
|
46
|
+
expect(result.current.filters).toEqual({ search: '', tags: [] });
|
|
47
|
+
});
|
|
48
|
+
});
|
package/dist/esm/Hooks/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export interface UseDataViewPaginationProps {
|
|
|
12
12
|
/** Custom URL parameter name for per page */
|
|
13
13
|
perPageParam?: string;
|
|
14
14
|
}
|
|
15
|
+
/** extends UseDataViewPaginationProps */
|
|
15
16
|
export interface DataViewPaginationProps extends UseDataViewPaginationProps {
|
|
16
17
|
/** Current page number */
|
|
17
18
|
page: number;
|
|
@@ -4,7 +4,7 @@ export interface UseDataViewSelectionProps {
|
|
|
4
4
|
/** Array of initially selected entries */
|
|
5
5
|
initialSelected?: (any)[];
|
|
6
6
|
}
|
|
7
|
-
export declare const useDataViewSelection: (
|
|
7
|
+
export declare const useDataViewSelection: (props?: UseDataViewSelectionProps) => {
|
|
8
8
|
selected: any[];
|
|
9
9
|
onSelect: (isSelecting: boolean, items?: any[] | any) => void;
|
|
10
10
|
isSelected: (item: any) => boolean;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
export const useDataViewSelection = (
|
|
4
|
-
|
|
3
|
+
export const useDataViewSelection = (props) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const [selected, setSelected] = useState((_a = props === null || props === void 0 ? void 0 : props.initialSelected) !== null && _a !== void 0 ? _a : []);
|
|
6
|
+
const matchOption = (props === null || props === void 0 ? void 0 : props.matchOption) ? props.matchOption : (option, another) => (option === another);
|
|
5
7
|
const onSelect = (isSelecting, items) => {
|
|
6
8
|
isSelecting && items ?
|
|
7
9
|
setSelected(prev => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ISortBy } from "@patternfly/react-table";
|
|
2
|
+
export declare enum DataViewSortParams {
|
|
3
|
+
SORT_BY = "sortBy",
|
|
4
|
+
DIRECTION = "direction"
|
|
5
|
+
}
|
|
6
|
+
export interface DataViewSortConfig {
|
|
7
|
+
/** Attribute to sort the entries by */
|
|
8
|
+
sortBy: string | undefined;
|
|
9
|
+
/** Sort direction */
|
|
10
|
+
direction: ISortBy['direction'];
|
|
11
|
+
}
|
|
12
|
+
export interface UseDataViewSortProps {
|
|
13
|
+
/** Initial sort config */
|
|
14
|
+
initialSort?: DataViewSortConfig;
|
|
15
|
+
/** Current search parameters as a string */
|
|
16
|
+
searchParams?: URLSearchParams;
|
|
17
|
+
/** Function to set search parameters */
|
|
18
|
+
setSearchParams?: (params: URLSearchParams) => void;
|
|
19
|
+
/** Default direction */
|
|
20
|
+
defaultDirection?: ISortBy['direction'];
|
|
21
|
+
/** Sort by URL param name */
|
|
22
|
+
sortByParam?: string;
|
|
23
|
+
/** Direction URL param name */
|
|
24
|
+
directionParam?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const useDataViewSort: (props?: UseDataViewSortProps) => {
|
|
27
|
+
onSort: (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent | undefined, newSortBy: string, newSortDirection: ISortBy["direction"]) => void;
|
|
28
|
+
/** Attribute to sort the entries by */
|
|
29
|
+
sortBy: string | undefined;
|
|
30
|
+
/** Sort direction */
|
|
31
|
+
direction: ISortBy["direction"];
|
|
32
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from "react";
|
|
2
|
+
export var DataViewSortParams;
|
|
3
|
+
(function (DataViewSortParams) {
|
|
4
|
+
DataViewSortParams["SORT_BY"] = "sortBy";
|
|
5
|
+
DataViewSortParams["DIRECTION"] = "direction";
|
|
6
|
+
})(DataViewSortParams || (DataViewSortParams = {}));
|
|
7
|
+
;
|
|
8
|
+
const validateDirection = (direction, defaultDirection) => (direction === 'asc' || direction === 'desc' ? direction : defaultDirection);
|
|
9
|
+
;
|
|
10
|
+
;
|
|
11
|
+
export const useDataViewSort = (props) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const { initialSort, searchParams, setSearchParams, defaultDirection = 'asc', sortByParam = DataViewSortParams.SORT_BY, directionParam = DataViewSortParams.DIRECTION } = props !== null && props !== void 0 ? props : {};
|
|
14
|
+
const isUrlSyncEnabled = useMemo(() => searchParams && !!setSearchParams, [searchParams, setSearchParams]);
|
|
15
|
+
const [state, setState] = useState({
|
|
16
|
+
sortBy: (_a = searchParams === null || searchParams === void 0 ? void 0 : searchParams.get(sortByParam)) !== null && _a !== void 0 ? _a : initialSort === null || initialSort === void 0 ? void 0 : initialSort.sortBy,
|
|
17
|
+
direction: validateDirection(searchParams === null || searchParams === void 0 ? void 0 : searchParams.get(directionParam), initialSort === null || initialSort === void 0 ? void 0 : initialSort.direction),
|
|
18
|
+
});
|
|
19
|
+
const updateSearchParams = (sortBy, direction) => {
|
|
20
|
+
if (isUrlSyncEnabled && sortBy) {
|
|
21
|
+
const params = new URLSearchParams(searchParams);
|
|
22
|
+
params.set(sortByParam, `${sortBy}`);
|
|
23
|
+
params.set(directionParam, `${direction}`);
|
|
24
|
+
setSearchParams === null || setSearchParams === void 0 ? void 0 : setSearchParams(params);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
state.sortBy && state.direction && updateSearchParams(state.sortBy, state.direction);
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, []);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const currentSortBy = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get(sortByParam)) || state.sortBy;
|
|
33
|
+
const currentDirection = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get(directionParam)) || state.direction;
|
|
34
|
+
const validDirection = validateDirection(currentDirection, defaultDirection);
|
|
35
|
+
currentSortBy !== state.sortBy || validDirection !== state.direction && setState({ sortBy: currentSortBy, direction: validDirection });
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
}, [searchParams === null || searchParams === void 0 ? void 0 : searchParams.toString()]);
|
|
38
|
+
const onSort = (_event, newSortBy, newSortDirection) => {
|
|
39
|
+
setState({ sortBy: newSortBy, direction: newSortDirection });
|
|
40
|
+
updateSearchParams(newSortBy, newSortDirection);
|
|
41
|
+
};
|
|
42
|
+
return Object.assign(Object.assign({}, state), { onSort });
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|