@patternfly/react-data-view 6.1.0-prerelease.1 → 6.2.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/dist/cjs/DataView/DataView.d.ts +15 -1
- package/dist/cjs/DataView/DataView.js +14 -3
- 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/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
- package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
- package/dist/cjs/DataViewEventsContext/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 +49 -0
- package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
- package/dist/cjs/DataViewTable/index.d.ts +2 -0
- package/dist/cjs/DataViewTable/index.js +23 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +14 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHead/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +25 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +144 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- 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 +13 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +31 -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 +75 -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 +14 -1
- package/dist/cjs/Hooks/pagination.js +36 -4
- package/dist/cjs/Hooks/pagination.test.js +1 -1
- package/dist/cjs/Hooks/selection.d.ts +3 -3
- package/dist/cjs/Hooks/selection.js +4 -4
- package/dist/cjs/Hooks/selection.test.js +4 -4
- 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 +26 -0
- package/dist/cjs/InternalContext/InternalContext.js +40 -0
- package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
- package/dist/cjs/InternalContext/index.d.ts +2 -0
- package/dist/cjs/InternalContext/index.js +23 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +26 -2
- package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewFilters/package.json +1 -0
- package/dist/dynamic/DataViewTable/package.json +1 -0
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHead/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/dynamic/DataViewTextFilter/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +15 -1
- package/dist/esm/DataView/DataView.js +13 -2
- 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/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
- package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
- package/dist/esm/DataViewEventsContext/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 +49 -0
- package/dist/esm/DataViewTable/DataViewTable.js +8 -0
- package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
- package/dist/esm/DataViewTable/index.d.ts +2 -0
- package/dist/esm/DataViewTable/index.js +2 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +14 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +25 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +117 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- 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 +13 -3
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +9 -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 +73 -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 +14 -1
- package/dist/esm/Hooks/pagination.js +36 -4
- package/dist/esm/Hooks/pagination.test.js +1 -1
- package/dist/esm/Hooks/selection.d.ts +3 -3
- package/dist/esm/Hooks/selection.js +4 -4
- package/dist/esm/Hooks/selection.test.js +4 -4
- 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 +26 -0
- package/dist/esm/InternalContext/InternalContext.js +12 -0
- package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/esm/InternalContext/InternalContext.test.js +51 -0
- package/dist/esm/InternalContext/index.d.ts +2 -0
- package/dist/esm/InternalContext/index.js +2 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +16 -15
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +87 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/AllSelectedExample.tsx +116 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +107 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +56 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +154 -0
- package/patternfly-docs/pages/index.js +1 -1
- package/release.config.js +1 -1
- package/src/DataView/DataView.tsx +28 -5
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -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/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/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.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +57 -0
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +83 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +54 -0
- package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +186 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- 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 +55 -22
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +52 -8
- package/src/Hooks/filters.test.tsx +89 -0
- package/src/Hooks/filters.ts +97 -0
- package/src/Hooks/index.ts +2 -0
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +69 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +7 -7
- package/src/Hooks/sort.test.tsx +84 -0
- package/src/Hooks/sort.ts +87 -0
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +52 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +24 -0
- package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -31
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -77
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +0 -65
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +0 -88
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -39
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -120
- /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import DataViewTextFilter, { DataViewTextFilterProps } from './DataViewTextFilter';
|
|
4
|
+
import DataViewToolbar from '../DataViewToolbar';
|
|
5
|
+
|
|
6
|
+
describe('DataViewTextFilter component', () => {
|
|
7
|
+
const mockOnChange = jest.fn();
|
|
8
|
+
|
|
9
|
+
const defaultProps: DataViewTextFilterProps = {
|
|
10
|
+
filterId: 'test-filter',
|
|
11
|
+
title: 'Test Filter',
|
|
12
|
+
value: 'initial value',
|
|
13
|
+
onChange: mockOnChange,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
it('should render correctly', () => {
|
|
17
|
+
const { container } = render(<DataViewToolbar
|
|
18
|
+
filters={
|
|
19
|
+
<DataViewTextFilter {...defaultProps} />
|
|
20
|
+
}
|
|
21
|
+
/>);
|
|
22
|
+
expect(container).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SearchInput, SearchInputProps, ToolbarFilter, ToolbarFilterProps } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
/** extends SearchInputProps */
|
|
5
|
+
export interface DataViewTextFilterProps extends SearchInputProps {
|
|
6
|
+
/** Unique key for the filter attribute */
|
|
7
|
+
filterId: string;
|
|
8
|
+
/** Current filter value */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** Filter title displayed in the toolbar */
|
|
11
|
+
title: string;
|
|
12
|
+
/** Callback for when the input value changes */
|
|
13
|
+
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
|
|
14
|
+
/** Controls visibility of the filter in the toolbar */
|
|
15
|
+
showToolbarItem?: ToolbarFilterProps['showToolbarItem'];
|
|
16
|
+
/** Trims input value on change */
|
|
17
|
+
trimValue?: boolean;
|
|
18
|
+
/** Custom OUIA ID */
|
|
19
|
+
ouiaId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DataViewTextFilter: React.FC<DataViewTextFilterProps> = ({
|
|
23
|
+
filterId,
|
|
24
|
+
title,
|
|
25
|
+
value = '',
|
|
26
|
+
onChange,
|
|
27
|
+
onClear = () => onChange?.(undefined, ''),
|
|
28
|
+
showToolbarItem,
|
|
29
|
+
trimValue = true,
|
|
30
|
+
ouiaId = 'DataViewTextFilter',
|
|
31
|
+
...props
|
|
32
|
+
}: DataViewTextFilterProps) => (
|
|
33
|
+
<ToolbarFilter
|
|
34
|
+
key={ouiaId}
|
|
35
|
+
data-ouia-component-id={ouiaId}
|
|
36
|
+
labels={value.length > 0 ? [ { key: title, node: value } ] : []}
|
|
37
|
+
deleteLabel={() => onChange?.(undefined, '')}
|
|
38
|
+
categoryName={title}
|
|
39
|
+
showToolbarItem={showToolbarItem}
|
|
40
|
+
>
|
|
41
|
+
<SearchInput
|
|
42
|
+
searchInputId={filterId}
|
|
43
|
+
value={value}
|
|
44
|
+
onChange={(e, inputValue) => onChange?.(e, trimValue ? inputValue.trim() : inputValue)}
|
|
45
|
+
onClear={onClear}
|
|
46
|
+
placeholder={`Filter by ${title}`}
|
|
47
|
+
aria-label={`${title ?? filterId} filter`}
|
|
48
|
+
data-ouia-component-id={`${ouiaId}-input`}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
</ToolbarFilter>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export default DataViewTextFilter;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataViewTextFilter component should render correctly 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<div
|
|
6
|
+
class="pf-v6-c-toolbar"
|
|
7
|
+
data-ouia-component-id="DataViewToolbar"
|
|
8
|
+
data-ouia-component-type="PF6/Toolbar"
|
|
9
|
+
data-ouia-safe="true"
|
|
10
|
+
id="pf-random-id-0"
|
|
11
|
+
>
|
|
12
|
+
<div
|
|
13
|
+
class="pf-v6-c-toolbar__content"
|
|
14
|
+
>
|
|
15
|
+
<div
|
|
16
|
+
class="pf-v6-c-toolbar__content-section"
|
|
17
|
+
>
|
|
18
|
+
<div
|
|
19
|
+
class="pf-v6-c-toolbar__item"
|
|
20
|
+
>
|
|
21
|
+
<div
|
|
22
|
+
class="pf-v6-c-toolbar__item"
|
|
23
|
+
data-ouia-component-id="DataViewTextFilter"
|
|
24
|
+
>
|
|
25
|
+
<div
|
|
26
|
+
class="pf-v6-c-text-input-group"
|
|
27
|
+
data-ouia-component-id="DataViewTextFilter-input"
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
class="pf-v6-c-text-input-group__main pf-m-icon"
|
|
31
|
+
>
|
|
32
|
+
<span
|
|
33
|
+
class="pf-v6-c-text-input-group__text"
|
|
34
|
+
>
|
|
35
|
+
<span
|
|
36
|
+
class="pf-v6-c-text-input-group__icon"
|
|
37
|
+
>
|
|
38
|
+
<svg
|
|
39
|
+
aria-hidden="true"
|
|
40
|
+
class="pf-v6-svg"
|
|
41
|
+
fill="currentColor"
|
|
42
|
+
height="1em"
|
|
43
|
+
role="img"
|
|
44
|
+
viewBox="0 0 512 512"
|
|
45
|
+
width="1em"
|
|
46
|
+
>
|
|
47
|
+
<path
|
|
48
|
+
d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"
|
|
49
|
+
/>
|
|
50
|
+
</svg>
|
|
51
|
+
</span>
|
|
52
|
+
<input
|
|
53
|
+
aria-label="Test Filter filter"
|
|
54
|
+
class="pf-v6-c-text-input-group__text-input"
|
|
55
|
+
id="test-filter"
|
|
56
|
+
placeholder="Filter by Test Filter"
|
|
57
|
+
type="text"
|
|
58
|
+
value="initial value"
|
|
59
|
+
/>
|
|
60
|
+
</span>
|
|
61
|
+
</div>
|
|
62
|
+
<div
|
|
63
|
+
class="pf-v6-c-text-input-group__utilities"
|
|
64
|
+
>
|
|
65
|
+
<button
|
|
66
|
+
aria-disabled="false"
|
|
67
|
+
aria-label="Reset"
|
|
68
|
+
class="pf-v6-c-button pf-m-plain"
|
|
69
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-2"
|
|
70
|
+
data-ouia-component-type="PF6/Button"
|
|
71
|
+
data-ouia-safe="true"
|
|
72
|
+
type="button"
|
|
73
|
+
>
|
|
74
|
+
<span
|
|
75
|
+
class="pf-v6-c-button__icon"
|
|
76
|
+
>
|
|
77
|
+
<svg
|
|
78
|
+
aria-hidden="true"
|
|
79
|
+
class="pf-v6-svg"
|
|
80
|
+
fill="currentColor"
|
|
81
|
+
height="1em"
|
|
82
|
+
role="img"
|
|
83
|
+
viewBox="0 0 352 512"
|
|
84
|
+
width="1em"
|
|
85
|
+
>
|
|
86
|
+
<path
|
|
87
|
+
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
|
|
88
|
+
/>
|
|
89
|
+
</svg>
|
|
90
|
+
</span>
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
<div
|
|
99
|
+
class="pf-v6-c-toolbar__content"
|
|
100
|
+
>
|
|
101
|
+
<div
|
|
102
|
+
class="pf-v6-c-toolbar__group"
|
|
103
|
+
>
|
|
104
|
+
<div
|
|
105
|
+
class="pf-v6-c-toolbar__item pf-m-label-group pf-m-label-group"
|
|
106
|
+
>
|
|
107
|
+
<div
|
|
108
|
+
class="pf-v6-c-label-group pf-m-category"
|
|
109
|
+
>
|
|
110
|
+
<div
|
|
111
|
+
class="pf-v6-c-label-group__main"
|
|
112
|
+
>
|
|
113
|
+
<span
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
class="pf-v6-c-label-group__label"
|
|
116
|
+
id="pf-random-id-1"
|
|
117
|
+
>
|
|
118
|
+
Test Filter
|
|
119
|
+
</span>
|
|
120
|
+
<ul
|
|
121
|
+
aria-labelledby="pf-random-id-1"
|
|
122
|
+
class="pf-v6-c-label-group__list"
|
|
123
|
+
role="list"
|
|
124
|
+
>
|
|
125
|
+
<li
|
|
126
|
+
class="pf-v6-c-label-group__list-item"
|
|
127
|
+
>
|
|
128
|
+
<span
|
|
129
|
+
class="pf-v6-c-label pf-m-filled"
|
|
130
|
+
>
|
|
131
|
+
<span
|
|
132
|
+
class="pf-v6-c-label__content"
|
|
133
|
+
>
|
|
134
|
+
<span
|
|
135
|
+
class="pf-v6-c-label__text"
|
|
136
|
+
>
|
|
137
|
+
initial value
|
|
138
|
+
</span>
|
|
139
|
+
</span>
|
|
140
|
+
<span
|
|
141
|
+
class="pf-v6-c-label__actions"
|
|
142
|
+
>
|
|
143
|
+
<button
|
|
144
|
+
aria-disabled="false"
|
|
145
|
+
aria-label="Close initial value"
|
|
146
|
+
class="pf-v6-c-button pf-m-plain pf-m-no-padding"
|
|
147
|
+
data-ouia-component-id="OUIA-Generated-Button-plain-3"
|
|
148
|
+
data-ouia-component-type="PF6/Button"
|
|
149
|
+
data-ouia-safe="true"
|
|
150
|
+
type="button"
|
|
151
|
+
>
|
|
152
|
+
<span
|
|
153
|
+
class="pf-v6-c-button__icon"
|
|
154
|
+
>
|
|
155
|
+
<svg
|
|
156
|
+
aria-hidden="true"
|
|
157
|
+
class="pf-v6-svg"
|
|
158
|
+
fill="currentColor"
|
|
159
|
+
height="1em"
|
|
160
|
+
role="img"
|
|
161
|
+
viewBox="0 0 352 512"
|
|
162
|
+
width="1em"
|
|
163
|
+
>
|
|
164
|
+
<path
|
|
165
|
+
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
|
|
166
|
+
/>
|
|
167
|
+
</svg>
|
|
168
|
+
</span>
|
|
169
|
+
</button>
|
|
170
|
+
</span>
|
|
171
|
+
</span>
|
|
172
|
+
</li>
|
|
173
|
+
</ul>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
<div
|
|
179
|
+
class="pf-v6-c-toolbar__group pf-m-action-group-inline"
|
|
180
|
+
>
|
|
181
|
+
<div
|
|
182
|
+
class="pf-v6-c-toolbar__item"
|
|
183
|
+
>
|
|
184
|
+
<button
|
|
185
|
+
aria-disabled="false"
|
|
186
|
+
class="pf-v6-c-button pf-m-link pf-m-inline"
|
|
187
|
+
data-ouia-component-id="DataViewToolbar-clear-all-filters"
|
|
188
|
+
data-ouia-component-type="PF6/Button"
|
|
189
|
+
data-ouia-safe="true"
|
|
190
|
+
type="button"
|
|
191
|
+
>
|
|
192
|
+
<span
|
|
193
|
+
class="pf-v6-c-button__text"
|
|
194
|
+
>
|
|
195
|
+
Clear filters
|
|
196
|
+
</span>
|
|
197
|
+
</button>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
`;
|
|
@@ -1,34 +1,67 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
1
|
+
import React, { PropsWithChildren, useRef } from 'react';
|
|
2
|
+
import { Button, Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant, ToolbarProps } from '@patternfly/react-core';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** extends ToolbarProps */
|
|
5
|
+
export interface DataViewToolbarProps extends Omit<PropsWithChildren<ToolbarProps>, 'ref'> {
|
|
5
6
|
/** Toolbar className */
|
|
6
7
|
className?: string;
|
|
7
8
|
/** Custom OUIA ID */
|
|
8
9
|
ouiaId?: string;
|
|
9
|
-
/** React
|
|
10
|
+
/** React node to display bulk select */
|
|
10
11
|
bulkSelect?: React.ReactNode;
|
|
11
|
-
/** React
|
|
12
|
+
/** React node to display pagination */
|
|
12
13
|
pagination?: React.ReactNode;
|
|
14
|
+
/** React node to display actions */
|
|
15
|
+
actions?: React.ReactNode;
|
|
16
|
+
/** React node to display toggle group */
|
|
17
|
+
toggleGroup?: React.ReactNode;
|
|
18
|
+
/** React node to display filters */
|
|
19
|
+
filters?: React.ReactNode;
|
|
20
|
+
/** React node to display custom filter labels */
|
|
21
|
+
customLabelGroupContent?: React.ReactNode;
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children, ...props }: DataViewToolbarProps) =>
|
|
16
|
-
|
|
17
|
-
<
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, actions, toggleGroup, pagination, filters, customLabelGroupContent, clearAllFilters, children, ...props }: DataViewToolbarProps) => {
|
|
25
|
+
const defaultClearFilters = useRef(
|
|
26
|
+
<ToolbarItem>
|
|
27
|
+
<Button ouiaId={`${ouiaId}-clear-all-filters`} variant="link" onClick={clearAllFilters} isInline>
|
|
28
|
+
Clear filters
|
|
29
|
+
</Button>
|
|
30
|
+
</ToolbarItem>
|
|
31
|
+
);
|
|
32
|
+
return (
|
|
33
|
+
<Toolbar ouiaId={ouiaId} className={className} customLabelGroupContent={customLabelGroupContent ?? defaultClearFilters.current} {...props}>
|
|
34
|
+
<ToolbarContent>
|
|
35
|
+
{bulkSelect && (
|
|
36
|
+
<ToolbarItem data-ouia-component-id={`${ouiaId}-bulk-select`}>
|
|
37
|
+
{bulkSelect}
|
|
38
|
+
</ToolbarItem>
|
|
39
|
+
)}
|
|
40
|
+
{filters && (
|
|
41
|
+
<ToolbarItem>
|
|
42
|
+
{filters}
|
|
43
|
+
</ToolbarItem>
|
|
44
|
+
)}
|
|
45
|
+
{actions && (
|
|
46
|
+
<ToolbarItem>
|
|
47
|
+
{actions}
|
|
48
|
+
</ToolbarItem>
|
|
49
|
+
)}
|
|
50
|
+
{toggleGroup && (
|
|
51
|
+
<ToolbarItem>
|
|
52
|
+
{toggleGroup}
|
|
53
|
+
</ToolbarItem>
|
|
54
|
+
)}
|
|
55
|
+
{pagination && (
|
|
56
|
+
<ToolbarItem variant={ToolbarItemVariant.pagination} data-ouia-component-id={`${ouiaId}-pagination`}>
|
|
57
|
+
{pagination}
|
|
58
|
+
</ToolbarItem>
|
|
59
|
+
)}
|
|
60
|
+
{children}
|
|
61
|
+
</ToolbarContent>
|
|
62
|
+
</Toolbar>
|
|
63
|
+
)
|
|
64
|
+
};
|
|
32
65
|
|
|
33
66
|
export default DataViewToolbar;
|
|
34
67
|
|
|
@@ -117,7 +117,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
117
117
|
type="button"
|
|
118
118
|
>
|
|
119
119
|
<span
|
|
120
|
-
class="pf-v6-c-button__icon
|
|
120
|
+
class="pf-v6-c-button__icon"
|
|
121
121
|
>
|
|
122
122
|
<svg
|
|
123
123
|
aria-hidden="true"
|
|
@@ -150,7 +150,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
150
150
|
type="button"
|
|
151
151
|
>
|
|
152
152
|
<span
|
|
153
|
-
class="pf-v6-c-button__icon
|
|
153
|
+
class="pf-v6-c-button__icon"
|
|
154
154
|
>
|
|
155
155
|
<svg
|
|
156
156
|
aria-hidden="true"
|
|
@@ -201,7 +201,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
201
201
|
type="button"
|
|
202
202
|
>
|
|
203
203
|
<span
|
|
204
|
-
class="pf-v6-c-button__icon
|
|
204
|
+
class="pf-v6-c-button__icon"
|
|
205
205
|
>
|
|
206
206
|
<svg
|
|
207
207
|
aria-hidden="true"
|
|
@@ -233,7 +233,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
233
233
|
type="button"
|
|
234
234
|
>
|
|
235
235
|
<span
|
|
236
|
-
class="pf-v6-c-button__icon
|
|
236
|
+
class="pf-v6-c-button__icon"
|
|
237
237
|
>
|
|
238
238
|
<svg
|
|
239
239
|
aria-hidden="true"
|
|
@@ -263,6 +263,28 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
263
263
|
<div
|
|
264
264
|
class="pf-v6-c-toolbar__group"
|
|
265
265
|
/>
|
|
266
|
+
<div
|
|
267
|
+
class="pf-v6-c-toolbar__group pf-m-action-group-inline"
|
|
268
|
+
>
|
|
269
|
+
<div
|
|
270
|
+
class="pf-v6-c-toolbar__item"
|
|
271
|
+
>
|
|
272
|
+
<button
|
|
273
|
+
aria-disabled="false"
|
|
274
|
+
class="pf-v6-c-button pf-m-link pf-m-inline"
|
|
275
|
+
data-ouia-component-id="DataViewToolbar-clear-all-filters"
|
|
276
|
+
data-ouia-component-type="PF6/Button"
|
|
277
|
+
data-ouia-safe="true"
|
|
278
|
+
type="button"
|
|
279
|
+
>
|
|
280
|
+
<span
|
|
281
|
+
class="pf-v6-c-button__text"
|
|
282
|
+
>
|
|
283
|
+
Clear filters
|
|
284
|
+
</span>
|
|
285
|
+
</button>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
266
288
|
</div>
|
|
267
289
|
</div>
|
|
268
290
|
</div>
|
|
@@ -380,7 +402,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
380
402
|
type="button"
|
|
381
403
|
>
|
|
382
404
|
<span
|
|
383
|
-
class="pf-v6-c-button__icon
|
|
405
|
+
class="pf-v6-c-button__icon"
|
|
384
406
|
>
|
|
385
407
|
<svg
|
|
386
408
|
aria-hidden="true"
|
|
@@ -413,7 +435,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
413
435
|
type="button"
|
|
414
436
|
>
|
|
415
437
|
<span
|
|
416
|
-
class="pf-v6-c-button__icon
|
|
438
|
+
class="pf-v6-c-button__icon"
|
|
417
439
|
>
|
|
418
440
|
<svg
|
|
419
441
|
aria-hidden="true"
|
|
@@ -464,7 +486,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
464
486
|
type="button"
|
|
465
487
|
>
|
|
466
488
|
<span
|
|
467
|
-
class="pf-v6-c-button__icon
|
|
489
|
+
class="pf-v6-c-button__icon"
|
|
468
490
|
>
|
|
469
491
|
<svg
|
|
470
492
|
aria-hidden="true"
|
|
@@ -496,7 +518,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
496
518
|
type="button"
|
|
497
519
|
>
|
|
498
520
|
<span
|
|
499
|
-
class="pf-v6-c-button__icon
|
|
521
|
+
class="pf-v6-c-button__icon"
|
|
500
522
|
>
|
|
501
523
|
<svg
|
|
502
524
|
aria-hidden="true"
|
|
@@ -526,6 +548,28 @@ exports[`DataViewToolbar component should render correctly 1`] = `
|
|
|
526
548
|
<div
|
|
527
549
|
class="pf-v6-c-toolbar__group"
|
|
528
550
|
/>
|
|
551
|
+
<div
|
|
552
|
+
class="pf-v6-c-toolbar__group pf-m-action-group-inline"
|
|
553
|
+
>
|
|
554
|
+
<div
|
|
555
|
+
class="pf-v6-c-toolbar__item"
|
|
556
|
+
>
|
|
557
|
+
<button
|
|
558
|
+
aria-disabled="false"
|
|
559
|
+
class="pf-v6-c-button pf-m-link pf-m-inline"
|
|
560
|
+
data-ouia-component-id="DataViewToolbar-clear-all-filters"
|
|
561
|
+
data-ouia-component-type="PF6/Button"
|
|
562
|
+
data-ouia-safe="true"
|
|
563
|
+
type="button"
|
|
564
|
+
>
|
|
565
|
+
<span
|
|
566
|
+
class="pf-v6-c-button__text"
|
|
567
|
+
>
|
|
568
|
+
Clear filters
|
|
569
|
+
</span>
|
|
570
|
+
</button>
|
|
571
|
+
</div>
|
|
572
|
+
</div>
|
|
529
573
|
</div>
|
|
530
574
|
</div>
|
|
531
575
|
</div>,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { renderHook, act } from '@testing-library/react';
|
|
3
|
+
import { useDataViewFilters, UseDataViewFiltersProps } from './filters';
|
|
4
|
+
|
|
5
|
+
describe('useDataViewFilters', () => {
|
|
6
|
+
const initialFilters = { search: 'test', tags: [ 'tag1', 'tag2' ] };
|
|
7
|
+
|
|
8
|
+
it('should initialize with provided initial filters', () => {
|
|
9
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
10
|
+
expect(result.current.filters).toEqual(initialFilters);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should initialize with empty filters if no initialFilters provided', () => {
|
|
14
|
+
const { result } = renderHook(() => useDataViewFilters({}));
|
|
15
|
+
expect(result.current.filters).toEqual({});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should set filters correctly', () => {
|
|
19
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
20
|
+
const newFilters = { search: 'new search' };
|
|
21
|
+
act(() => result.current.onSetFilters(newFilters));
|
|
22
|
+
|
|
23
|
+
expect(result.current.filters).toEqual({ ...initialFilters, ...newFilters });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should delete specific filters without removing keys', () => {
|
|
27
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
28
|
+
const filtersToDelete = { search: 'test' };
|
|
29
|
+
act(() => result.current.onDeleteFilters(filtersToDelete));
|
|
30
|
+
|
|
31
|
+
expect(result.current.filters).toEqual({ search: '', tags: [ 'tag1', 'tag2' ] });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should clear all filters', () => {
|
|
35
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
36
|
+
act(() => result.current.clearAllFilters());
|
|
37
|
+
|
|
38
|
+
expect(result.current.filters).toEqual({ search: '', tags: [] });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should sync with URL search params if isUrlSyncEnabled', () => {
|
|
42
|
+
const searchParams = new URLSearchParams();
|
|
43
|
+
const setSearchParams = jest.fn();
|
|
44
|
+
const props: UseDataViewFiltersProps<typeof initialFilters> = {
|
|
45
|
+
initialFilters,
|
|
46
|
+
searchParams,
|
|
47
|
+
setSearchParams,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const { result } = renderHook(() => useDataViewFilters(props));
|
|
51
|
+
act(() => result.current.onSetFilters({ search: 'new search' }));
|
|
52
|
+
|
|
53
|
+
expect(setSearchParams).toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should sync with URL search params with non array value', () => {
|
|
57
|
+
const searchParams = new URLSearchParams();
|
|
58
|
+
searchParams.set('test', 'foo');
|
|
59
|
+
const setSearchParams = jest.fn();
|
|
60
|
+
const props: UseDataViewFiltersProps<{ test: string }> = {
|
|
61
|
+
initialFilters: { test: '' },
|
|
62
|
+
searchParams,
|
|
63
|
+
setSearchParams,
|
|
64
|
+
};
|
|
65
|
+
const { result } = renderHook(() => useDataViewFilters(props));
|
|
66
|
+
expect(result.current.filters).toEqual({ test: 'foo' });
|
|
67
|
+
})
|
|
68
|
+
it('should sync with URL search params with array value', () => {
|
|
69
|
+
|
|
70
|
+
const searchParams = new URLSearchParams();
|
|
71
|
+
searchParams.append('test', 'foo');
|
|
72
|
+
searchParams.append('test', 'bar');
|
|
73
|
+
const setSearchParams = jest.fn();
|
|
74
|
+
const props: UseDataViewFiltersProps<{ test: string[] }> = {
|
|
75
|
+
initialFilters: { test: [] },
|
|
76
|
+
searchParams,
|
|
77
|
+
setSearchParams,
|
|
78
|
+
};
|
|
79
|
+
const { result } = renderHook(() => useDataViewFilters(props));
|
|
80
|
+
expect(result.current.filters).toEqual({ test: [ 'foo', 'bar' ] });
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should reset filters to default values when clearAllFilters is called', () => {
|
|
84
|
+
const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
|
|
85
|
+
act(() => result.current.clearAllFilters());
|
|
86
|
+
|
|
87
|
+
expect(result.current.filters).toEqual({ search: '', tags: [] });
|
|
88
|
+
});
|
|
89
|
+
});
|