@patternfly/react-data-view 6.5.0-prerelease.1 → 6.5.0-prerelease.2
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/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +2 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +3 -2
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -1
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +8 -2
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +3 -2
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +5 -0
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.d.ts +2 -0
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.js +3 -2
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.js +5 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +2 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +3 -2
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -1
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +9 -3
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +3 -2
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +6 -1
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.d.ts +2 -0
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.js +3 -2
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.js +5 -0
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +1 -1
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +16 -7
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +5 -1
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +11 -1
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +7 -2
- package/src/DataViewTreeFilter/DataViewTreeFilter.test.tsx +11 -0
- package/src/DataViewTreeFilter/DataViewTreeFilter.tsx +5 -1
|
@@ -10,6 +10,8 @@ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect'
|
|
|
10
10
|
value?: string[];
|
|
11
11
|
/** Filter title displayed in the toolbar */
|
|
12
12
|
title: string;
|
|
13
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
14
|
+
chipTitle?: string;
|
|
13
15
|
/** Placeholder text of the menu */
|
|
14
16
|
placeholder?: string;
|
|
15
17
|
/** Filter options displayed */
|
|
@@ -24,11 +24,12 @@ const isDataViewFilterOption = (obj) => !!obj &&
|
|
|
24
24
|
typeof obj.value === 'string';
|
|
25
25
|
exports.isDataViewFilterOption = isDataViewFilterOption;
|
|
26
26
|
const DataViewCheckboxFilter = (_a) => {
|
|
27
|
-
var { filterId, title, value = [], onChange, placeholder, options = [], showToolbarItem, showIcon = !placeholder, showBadge = !placeholder, ouiaId = 'DataViewCheckboxFilter' } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "placeholder", "options", "showToolbarItem", "showIcon", "showBadge", "ouiaId"]);
|
|
27
|
+
var { filterId, title, chipTitle, value = [], onChange, placeholder, options = [], showToolbarItem, showIcon = !placeholder, showBadge = !placeholder, ouiaId = 'DataViewCheckboxFilter' } = _a, props = __rest(_a, ["filterId", "title", "chipTitle", "value", "onChange", "placeholder", "options", "showToolbarItem", "showIcon", "showBadge", "ouiaId"]);
|
|
28
28
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
29
29
|
const toggleRef = (0, react_1.useRef)(null);
|
|
30
30
|
const menuRef = (0, react_1.useRef)(null);
|
|
31
31
|
const containerRef = (0, react_1.useRef)(null);
|
|
32
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
32
33
|
const normalizeOptions = (0, react_1.useMemo)(() => options.map(option => typeof option === 'string'
|
|
33
34
|
? { label: option, value: option }
|
|
34
35
|
: option), [options]);
|
|
@@ -59,7 +60,7 @@ const DataViewCheckboxFilter = (_a) => {
|
|
|
59
60
|
return ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.map(item => {
|
|
60
61
|
const activeOption = normalizeOptions.find(option => option.value === item);
|
|
61
62
|
return ({ key: activeOption === null || activeOption === void 0 ? void 0 : activeOption.value, node: activeOption === null || activeOption === void 0 ? void 0 : activeOption.label });
|
|
62
|
-
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName:
|
|
63
|
+
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName: categoryName, showToolbarItem: showToolbarItem, children: (0, jsx_runtime_1.jsx)(react_core_1.Popper, { trigger: (0, jsx_runtime_1.jsx)(react_core_1.MenuToggle, { ouiaId: `${ouiaId}-toggle`, ref: toggleRef, onClick: handleToggleClick, isExpanded: isOpen, icon: showIcon ? (0, jsx_runtime_1.jsx)(react_icons_1.FilterIcon, {}) : undefined, badge: value.length > 0 && showBadge ? (0, jsx_runtime_1.jsx)(react_core_1.Badge, { "data-ouia-component-id": `${ouiaId}-badge`, isRead: true, children: value.length }) : undefined, style: { width: '200px' }, children: placeholder !== null && placeholder !== void 0 ? placeholder : title }), triggerRef: toggleRef, popper: (0, jsx_runtime_1.jsx)(react_core_1.Menu, Object.assign({ ref: menuRef, ouiaId: `${ouiaId}-menu`, onSelect: handleSelect, selected: value }, props, { children: (0, jsx_runtime_1.jsx)(react_core_1.MenuContent, { children: (0, jsx_runtime_1.jsx)(react_core_1.MenuList, { children: normalizeOptions.map(option => ((0, jsx_runtime_1.jsx)(react_core_1.MenuItem, { "data-ouia-component-id": `${ouiaId}-filter-item-${option.value}`, itemId: option.value, isSelected: value.includes(option.value), hasCheckbox: true, children: option.label }, option.value))) }) }) })), popperRef: menuRef, appendTo: containerRef.current || undefined, "aria-label": `${title !== null && title !== void 0 ? title : filterId} filter`, isVisible: isOpen }) }, ouiaId));
|
|
63
64
|
};
|
|
64
65
|
exports.DataViewCheckboxFilter = DataViewCheckboxFilter;
|
|
65
66
|
exports.default = exports.DataViewCheckboxFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -7,6 +7,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
const react_1 = require("@testing-library/react");
|
|
8
8
|
const DataViewCheckboxFilter_1 = __importDefault(require("./DataViewCheckboxFilter"));
|
|
9
9
|
const DataViewToolbar_1 = __importDefault(require("../DataViewToolbar"));
|
|
10
|
+
require("@testing-library/jest-dom");
|
|
10
11
|
describe('DataViewCheckboxFilter component', () => {
|
|
11
12
|
const defaultProps = {
|
|
12
13
|
filterId: 'test-checkbox-filter',
|
|
@@ -15,11 +16,16 @@ describe('DataViewCheckboxFilter component', () => {
|
|
|
15
16
|
options: [
|
|
16
17
|
{ label: 'Workspace one', value: 'workspace-one' },
|
|
17
18
|
{ label: 'Workspace two', value: 'workspace-two' },
|
|
18
|
-
{ label: 'Workspace three', value: 'workspace-three' }
|
|
19
|
-
]
|
|
19
|
+
{ label: 'Workspace three', value: 'workspace-three' }
|
|
20
|
+
]
|
|
20
21
|
};
|
|
21
22
|
it('should render correctly', () => {
|
|
22
23
|
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewCheckboxFilter_1.default, Object.assign({}, defaultProps)) }));
|
|
23
24
|
expect(container).toMatchSnapshot();
|
|
24
25
|
});
|
|
26
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
27
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewCheckboxFilter_1.default, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
28
|
+
expect(react_1.screen.getByText('Short name')).toBeInTheDocument();
|
|
29
|
+
expect(react_1.screen.getByText('Test Checkbox Filter')).toBeInTheDocument();
|
|
30
|
+
});
|
|
25
31
|
});
|
|
@@ -8,6 +8,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
|
|
|
8
8
|
value?: string;
|
|
9
9
|
/** Filter title displayed in the toolbar */
|
|
10
10
|
title: string;
|
|
11
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
12
|
+
chipTitle?: string;
|
|
11
13
|
/** Callback for when the input value changes */
|
|
12
14
|
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
|
|
13
15
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -16,7 +16,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
16
16
|
const react_1 = require("react");
|
|
17
17
|
const react_core_1 = require("@patternfly/react-core");
|
|
18
18
|
const DataViewTextFilter = (_a) => {
|
|
19
|
-
var { filterId, title, value = '', onChange, onClear = () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), showToolbarItem, trimValue = true, ouiaId = 'DataViewTextFilter', enableShortcut = true } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "onClear", "showToolbarItem", "trimValue", "ouiaId", "enableShortcut"]);
|
|
19
|
+
var { filterId, title, chipTitle, value = '', onChange, onClear = () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), showToolbarItem, trimValue = true, ouiaId = 'DataViewTextFilter', enableShortcut = true } = _a, props = __rest(_a, ["filterId", "title", "chipTitle", "value", "onChange", "onClear", "showToolbarItem", "trimValue", "ouiaId", "enableShortcut"]);
|
|
20
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
20
21
|
(0, react_1.useEffect)(() => {
|
|
21
22
|
if (!enableShortcut) {
|
|
22
23
|
return;
|
|
@@ -44,7 +45,7 @@ const DataViewTextFilter = (_a) => {
|
|
|
44
45
|
window.removeEventListener('keydown', handleKeyDown);
|
|
45
46
|
};
|
|
46
47
|
}, [showToolbarItem, filterId, enableShortcut]);
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.length > 0 ? [{ key:
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.length > 0 ? [{ key: categoryName, node: value }] : [], deleteLabel: () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), categoryName: categoryName, showToolbarItem: showToolbarItem, children: (0, jsx_runtime_1.jsx)(react_core_1.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)) }, ouiaId));
|
|
48
49
|
};
|
|
49
50
|
exports.DataViewTextFilter = DataViewTextFilter;
|
|
50
51
|
exports.default = exports.DataViewTextFilter;
|
|
@@ -20,6 +20,11 @@ describe('DataViewTextFilter component', () => {
|
|
|
20
20
|
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTextFilter_1.default, Object.assign({}, defaultProps)) }));
|
|
21
21
|
expect(container).toMatchSnapshot();
|
|
22
22
|
});
|
|
23
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
24
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTextFilter_1.default, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
25
|
+
expect(react_1.screen.getByText('Short name')).toBeInTheDocument();
|
|
26
|
+
expect(react_1.screen.getByPlaceholderText('Filter by Test Filter')).toBeInTheDocument();
|
|
27
|
+
});
|
|
23
28
|
it('should focus the search input when "/" key is pressed and filter is visible', () => {
|
|
24
29
|
(0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTextFilter_1.default, Object.assign({}, defaultProps, { showToolbarItem: true })) }));
|
|
25
30
|
const input = document.getElementById('test-filter');
|
|
@@ -7,6 +7,8 @@ export interface DataViewTreeFilterProps {
|
|
|
7
7
|
value?: string[];
|
|
8
8
|
/** Filter title displayed in the toolbar */
|
|
9
9
|
title: string;
|
|
10
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
11
|
+
chipTitle?: string;
|
|
10
12
|
/** Callback for when the selection changes */
|
|
11
13
|
onChange?: (event?: React.MouseEvent, values?: string[]) => void;
|
|
12
14
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -47,7 +47,8 @@ const setPreSelectedItems = (items, selectedIds) => items.map(item => {
|
|
|
47
47
|
});
|
|
48
48
|
// Helper function to uncheck all items recursively
|
|
49
49
|
const uncheckRecursive = (items) => items.map(item => (Object.assign(Object.assign({}, item), { checkProps: item.checkProps ? Object.assign(Object.assign({}, item.checkProps), { checked: false }) : undefined, children: item.children ? uncheckRecursive(item.children) : undefined })));
|
|
50
|
-
const DataViewTreeFilter = ({ filterId, title, value = [], onChange, showToolbarItem, ouiaId = 'DataViewTreeFilter', items, defaultExpanded = false, onSelect, defaultSelected = [] }) => {
|
|
50
|
+
const DataViewTreeFilter = ({ filterId, title, chipTitle, value = [], onChange, showToolbarItem, ouiaId = 'DataViewTreeFilter', items, defaultExpanded = false, onSelect, defaultSelected = [] }) => {
|
|
51
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
51
52
|
const classes = useStyles();
|
|
52
53
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
53
54
|
const [treeData, setTreeData] = (0, react_1.useState)(items || []);
|
|
@@ -223,7 +224,7 @@ const DataViewTreeFilter = ({ filterId, title, value = [], onChange, showToolbar
|
|
|
223
224
|
const labelKey = typeof label === 'string' ? label : label.key;
|
|
224
225
|
onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== labelKey));
|
|
225
226
|
onFilterSelectorClear(labelKey);
|
|
226
|
-
}, deleteLabelGroup: uncheckAllItems, categoryName:
|
|
227
|
+
}, deleteLabelGroup: uncheckAllItems, categoryName: categoryName, showToolbarItem: showToolbarItem, children: dropdown }, filterId));
|
|
227
228
|
};
|
|
228
229
|
exports.DataViewTreeFilter = DataViewTreeFilter;
|
|
229
230
|
exports.default = exports.DataViewTreeFilter;
|
|
@@ -96,6 +96,11 @@ describe('DataViewTreeFilter component', () => {
|
|
|
96
96
|
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTreeFilter_1.default, Object.assign({}, defaultProps)) }));
|
|
97
97
|
expect(container).toMatchSnapshot();
|
|
98
98
|
});
|
|
99
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
100
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTreeFilter_1.default, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
101
|
+
expect(react_1.screen.getByText('Short name')).toBeInTheDocument();
|
|
102
|
+
expect(react_1.screen.getByText('Test Tree Filter')).toBeInTheDocument();
|
|
103
|
+
});
|
|
99
104
|
describe('defaultExpanded', () => {
|
|
100
105
|
it('should have expanded items by default', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
106
|
(0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTreeFilter_1.default, { filterId: "os", title: "Operating System", items: treeItems, defaultExpanded: true }) }));
|
|
@@ -10,6 +10,8 @@ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect'
|
|
|
10
10
|
value?: string[];
|
|
11
11
|
/** Filter title displayed in the toolbar */
|
|
12
12
|
title: string;
|
|
13
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
14
|
+
chipTitle?: string;
|
|
13
15
|
/** Placeholder text of the menu */
|
|
14
16
|
placeholder?: string;
|
|
15
17
|
/** Filter options displayed */
|
|
@@ -20,11 +20,12 @@ export const isDataViewFilterOption = (obj) => !!obj &&
|
|
|
20
20
|
'value' in obj &&
|
|
21
21
|
typeof obj.value === 'string';
|
|
22
22
|
export const DataViewCheckboxFilter = (_a) => {
|
|
23
|
-
var { filterId, title, value = [], onChange, placeholder, options = [], showToolbarItem, showIcon = !placeholder, showBadge = !placeholder, ouiaId = 'DataViewCheckboxFilter' } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "placeholder", "options", "showToolbarItem", "showIcon", "showBadge", "ouiaId"]);
|
|
23
|
+
var { filterId, title, chipTitle, value = [], onChange, placeholder, options = [], showToolbarItem, showIcon = !placeholder, showBadge = !placeholder, ouiaId = 'DataViewCheckboxFilter' } = _a, props = __rest(_a, ["filterId", "title", "chipTitle", "value", "onChange", "placeholder", "options", "showToolbarItem", "showIcon", "showBadge", "ouiaId"]);
|
|
24
24
|
const [isOpen, setIsOpen] = useState(false);
|
|
25
25
|
const toggleRef = useRef(null);
|
|
26
26
|
const menuRef = useRef(null);
|
|
27
27
|
const containerRef = useRef(null);
|
|
28
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
28
29
|
const normalizeOptions = useMemo(() => options.map(option => typeof option === 'string'
|
|
29
30
|
? { label: option, value: option }
|
|
30
31
|
: option), [options]);
|
|
@@ -55,6 +56,6 @@ export const DataViewCheckboxFilter = (_a) => {
|
|
|
55
56
|
return (_jsx(ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.map(item => {
|
|
56
57
|
const activeOption = normalizeOptions.find(option => option.value === item);
|
|
57
58
|
return ({ key: activeOption === null || activeOption === void 0 ? void 0 : activeOption.value, node: activeOption === null || activeOption === void 0 ? void 0 : activeOption.label });
|
|
58
|
-
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName:
|
|
59
|
+
}), deleteLabel: (_, label) => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label))), categoryName: categoryName, showToolbarItem: showToolbarItem, children: _jsx(Popper, { trigger: _jsx(MenuToggle, { ouiaId: `${ouiaId}-toggle`, ref: toggleRef, onClick: handleToggleClick, isExpanded: isOpen, icon: showIcon ? _jsx(FilterIcon, {}) : undefined, badge: value.length > 0 && showBadge ? _jsx(Badge, { "data-ouia-component-id": `${ouiaId}-badge`, isRead: true, children: value.length }) : undefined, style: { width: '200px' }, children: placeholder !== null && placeholder !== void 0 ? placeholder : title }), triggerRef: toggleRef, popper: _jsx(Menu, Object.assign({ ref: menuRef, ouiaId: `${ouiaId}-menu`, onSelect: handleSelect, selected: value }, props, { children: _jsx(MenuContent, { children: _jsx(MenuList, { children: normalizeOptions.map(option => (_jsx(MenuItem, { "data-ouia-component-id": `${ouiaId}-filter-item-${option.value}`, itemId: option.value, isSelected: value.includes(option.value), hasCheckbox: true, children: option.label }, option.value))) }) }) })), popperRef: menuRef, appendTo: containerRef.current || undefined, "aria-label": `${title !== null && title !== void 0 ? title : filterId} filter`, isVisible: isOpen }) }, ouiaId));
|
|
59
60
|
};
|
|
60
61
|
export default DataViewCheckboxFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import DataViewCheckboxFilter from './DataViewCheckboxFilter';
|
|
4
4
|
import DataViewToolbar from '../DataViewToolbar';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
5
6
|
describe('DataViewCheckboxFilter component', () => {
|
|
6
7
|
const defaultProps = {
|
|
7
8
|
filterId: 'test-checkbox-filter',
|
|
@@ -10,11 +11,16 @@ describe('DataViewCheckboxFilter component', () => {
|
|
|
10
11
|
options: [
|
|
11
12
|
{ label: 'Workspace one', value: 'workspace-one' },
|
|
12
13
|
{ label: 'Workspace two', value: 'workspace-two' },
|
|
13
|
-
{ label: 'Workspace three', value: 'workspace-three' }
|
|
14
|
-
]
|
|
14
|
+
{ label: 'Workspace three', value: 'workspace-three' }
|
|
15
|
+
]
|
|
15
16
|
};
|
|
16
17
|
it('should render correctly', () => {
|
|
17
18
|
const { container } = render(_jsx(DataViewToolbar, { filters: _jsx(DataViewCheckboxFilter, Object.assign({}, defaultProps)) }));
|
|
18
19
|
expect(container).toMatchSnapshot();
|
|
19
20
|
});
|
|
21
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
22
|
+
render(_jsx(DataViewToolbar, { filters: _jsx(DataViewCheckboxFilter, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
23
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText('Test Checkbox Filter')).toBeInTheDocument();
|
|
25
|
+
});
|
|
20
26
|
});
|
|
@@ -8,6 +8,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
|
|
|
8
8
|
value?: string;
|
|
9
9
|
/** Filter title displayed in the toolbar */
|
|
10
10
|
title: string;
|
|
11
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
12
|
+
chipTitle?: string;
|
|
11
13
|
/** Callback for when the input value changes */
|
|
12
14
|
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
|
|
13
15
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -13,7 +13,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { useEffect } from 'react';
|
|
14
14
|
import { SearchInput, ToolbarFilter } from '@patternfly/react-core';
|
|
15
15
|
export const DataViewTextFilter = (_a) => {
|
|
16
|
-
var { filterId, title, value = '', onChange, onClear = () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), showToolbarItem, trimValue = true, ouiaId = 'DataViewTextFilter', enableShortcut = true } = _a, props = __rest(_a, ["filterId", "title", "value", "onChange", "onClear", "showToolbarItem", "trimValue", "ouiaId", "enableShortcut"]);
|
|
16
|
+
var { filterId, title, chipTitle, value = '', onChange, onClear = () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), showToolbarItem, trimValue = true, ouiaId = 'DataViewTextFilter', enableShortcut = true } = _a, props = __rest(_a, ["filterId", "title", "chipTitle", "value", "onChange", "onClear", "showToolbarItem", "trimValue", "ouiaId", "enableShortcut"]);
|
|
17
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
17
18
|
useEffect(() => {
|
|
18
19
|
if (!enableShortcut) {
|
|
19
20
|
return;
|
|
@@ -41,6 +42,6 @@ export const DataViewTextFilter = (_a) => {
|
|
|
41
42
|
window.removeEventListener('keydown', handleKeyDown);
|
|
42
43
|
};
|
|
43
44
|
}, [showToolbarItem, filterId, enableShortcut]);
|
|
44
|
-
return (_jsx(ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.length > 0 ? [{ key:
|
|
45
|
+
return (_jsx(ToolbarFilter, { "data-ouia-component-id": ouiaId, labels: value.length > 0 ? [{ key: categoryName, node: value }] : [], deleteLabel: () => onChange === null || onChange === void 0 ? void 0 : onChange(undefined, ''), categoryName: categoryName, showToolbarItem: showToolbarItem, children: _jsx(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)) }, ouiaId));
|
|
45
46
|
};
|
|
46
47
|
export default DataViewTextFilter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import '@testing-library/jest-dom';
|
|
4
4
|
import DataViewTextFilter from './DataViewTextFilter';
|
|
5
5
|
import DataViewToolbar from '../DataViewToolbar';
|
|
@@ -15,6 +15,11 @@ describe('DataViewTextFilter component', () => {
|
|
|
15
15
|
const { container } = render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTextFilter, Object.assign({}, defaultProps)) }));
|
|
16
16
|
expect(container).toMatchSnapshot();
|
|
17
17
|
});
|
|
18
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
19
|
+
render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTextFilter, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
20
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
21
|
+
expect(screen.getByPlaceholderText('Filter by Test Filter')).toBeInTheDocument();
|
|
22
|
+
});
|
|
18
23
|
it('should focus the search input when "/" key is pressed and filter is visible', () => {
|
|
19
24
|
render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTextFilter, Object.assign({}, defaultProps, { showToolbarItem: true })) }));
|
|
20
25
|
const input = document.getElementById('test-filter');
|
|
@@ -7,6 +7,8 @@ export interface DataViewTreeFilterProps {
|
|
|
7
7
|
value?: string[];
|
|
8
8
|
/** Filter title displayed in the toolbar */
|
|
9
9
|
title: string;
|
|
10
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
11
|
+
chipTitle?: string;
|
|
10
12
|
/** Callback for when the selection changes */
|
|
11
13
|
onChange?: (event?: React.MouseEvent, values?: string[]) => void;
|
|
12
14
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -44,7 +44,8 @@ const setPreSelectedItems = (items, selectedIds) => items.map(item => {
|
|
|
44
44
|
});
|
|
45
45
|
// Helper function to uncheck all items recursively
|
|
46
46
|
const uncheckRecursive = (items) => items.map(item => (Object.assign(Object.assign({}, item), { checkProps: item.checkProps ? Object.assign(Object.assign({}, item.checkProps), { checked: false }) : undefined, children: item.children ? uncheckRecursive(item.children) : undefined })));
|
|
47
|
-
export const DataViewTreeFilter = ({ filterId, title, value = [], onChange, showToolbarItem, ouiaId = 'DataViewTreeFilter', items, defaultExpanded = false, onSelect, defaultSelected = [] }) => {
|
|
47
|
+
export const DataViewTreeFilter = ({ filterId, title, chipTitle, value = [], onChange, showToolbarItem, ouiaId = 'DataViewTreeFilter', items, defaultExpanded = false, onSelect, defaultSelected = [] }) => {
|
|
48
|
+
const categoryName = chipTitle !== null && chipTitle !== void 0 ? chipTitle : title;
|
|
48
49
|
const classes = useStyles();
|
|
49
50
|
const [isOpen, setIsOpen] = useState(false);
|
|
50
51
|
const [treeData, setTreeData] = useState(items || []);
|
|
@@ -220,6 +221,6 @@ export const DataViewTreeFilter = ({ filterId, title, value = [], onChange, show
|
|
|
220
221
|
const labelKey = typeof label === 'string' ? label : label.key;
|
|
221
222
|
onChange === null || onChange === void 0 ? void 0 : onChange(undefined, value.filter(item => item !== labelKey));
|
|
222
223
|
onFilterSelectorClear(labelKey);
|
|
223
|
-
}, deleteLabelGroup: uncheckAllItems, categoryName:
|
|
224
|
+
}, deleteLabelGroup: uncheckAllItems, categoryName: categoryName, showToolbarItem: showToolbarItem, children: dropdown }, filterId));
|
|
224
225
|
};
|
|
225
226
|
export default DataViewTreeFilter;
|
|
@@ -91,6 +91,11 @@ describe('DataViewTreeFilter component', () => {
|
|
|
91
91
|
const { container } = render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTreeFilter, Object.assign({}, defaultProps)) }));
|
|
92
92
|
expect(container).toMatchSnapshot();
|
|
93
93
|
});
|
|
94
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
95
|
+
render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTreeFilter, Object.assign({}, defaultProps, { chipTitle: "Short name" })) }));
|
|
96
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
97
|
+
expect(screen.getByText('Test Tree Filter')).toBeInTheDocument();
|
|
98
|
+
});
|
|
94
99
|
describe('defaultExpanded', () => {
|
|
95
100
|
it('should have expanded items by default', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
101
|
render(_jsx(DataViewToolbar, { filters: _jsx(DataViewTreeFilter, { filterId: "os", title: "Operating System", items: treeItems, defaultExpanded: true }) }));
|
package/package.json
CHANGED
|
@@ -78,7 +78,7 @@ const MyTable: React.FunctionComponent = () => {
|
|
|
78
78
|
}
|
|
79
79
|
filters={
|
|
80
80
|
<DataViewFilters onChange={(_e, values) => onSetFilters(values)} values={filters}>
|
|
81
|
-
<DataViewTextFilter filterId="name" title='Name' placeholder='Filter by name' />
|
|
81
|
+
<DataViewTextFilter filterId="name" title='Name' chipTitle='Repo' placeholder='Filter by name' />
|
|
82
82
|
<DataViewTextFilter filterId="branch" title='Branch' placeholder='Filter by branch' />
|
|
83
83
|
<DataViewCheckboxFilter filterId="workspace" title='Workspace' placeholder='Filter by workspace' options={filterOptions} />
|
|
84
84
|
</DataViewFilters>
|
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import DataViewCheckboxFilter, { DataViewCheckboxFilterProps } from './DataViewCheckboxFilter';
|
|
3
3
|
import DataViewToolbar from '../DataViewToolbar';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
4
5
|
|
|
5
6
|
describe('DataViewCheckboxFilter component', () => {
|
|
6
7
|
const defaultProps: DataViewCheckboxFilterProps = {
|
|
7
8
|
filterId: 'test-checkbox-filter',
|
|
8
9
|
title: 'Test Checkbox Filter',
|
|
9
|
-
value: [
|
|
10
|
+
value: ['workspace-one'],
|
|
10
11
|
options: [
|
|
11
12
|
{ label: 'Workspace one', value: 'workspace-one' },
|
|
12
13
|
{ label: 'Workspace two', value: 'workspace-two' },
|
|
13
|
-
{ label: 'Workspace three', value: 'workspace-three' }
|
|
14
|
-
]
|
|
14
|
+
{ label: 'Workspace three', value: 'workspace-three' }
|
|
15
|
+
]
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
it('should render correctly', () => {
|
|
18
|
-
const { container } = render(
|
|
19
|
-
<DataViewToolbar filters={<DataViewCheckboxFilter {...defaultProps} />} />
|
|
20
|
-
);
|
|
19
|
+
const { container } = render(<DataViewToolbar filters={<DataViewCheckboxFilter {...defaultProps} />} />);
|
|
21
20
|
expect(container).toMatchSnapshot();
|
|
22
21
|
});
|
|
22
|
+
|
|
23
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
24
|
+
render(
|
|
25
|
+
<DataViewToolbar
|
|
26
|
+
filters={<DataViewCheckboxFilter {...defaultProps} chipTitle="Short name" />}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText('Test Checkbox Filter')).toBeInTheDocument();
|
|
31
|
+
});
|
|
23
32
|
});
|
|
@@ -32,6 +32,8 @@ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect'
|
|
|
32
32
|
value?: string[];
|
|
33
33
|
/** Filter title displayed in the toolbar */
|
|
34
34
|
title: string;
|
|
35
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
36
|
+
chipTitle?: string;
|
|
35
37
|
/** Placeholder text of the menu */
|
|
36
38
|
placeholder?: string;
|
|
37
39
|
/** Filter options displayed */
|
|
@@ -51,6 +53,7 @@ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect'
|
|
|
51
53
|
export const DataViewCheckboxFilter: FC<DataViewCheckboxFilterProps> = ({
|
|
52
54
|
filterId,
|
|
53
55
|
title,
|
|
56
|
+
chipTitle,
|
|
54
57
|
value = [],
|
|
55
58
|
onChange,
|
|
56
59
|
placeholder,
|
|
@@ -65,6 +68,7 @@ export const DataViewCheckboxFilter: FC<DataViewCheckboxFilterProps> = ({
|
|
|
65
68
|
const toggleRef = useRef<HTMLButtonElement>(null);
|
|
66
69
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
67
70
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
71
|
+
const categoryName = chipTitle ?? title;
|
|
68
72
|
|
|
69
73
|
const normalizeOptions = useMemo(
|
|
70
74
|
() =>
|
|
@@ -120,7 +124,7 @@ export const DataViewCheckboxFilter: FC<DataViewCheckboxFilterProps> = ({
|
|
|
120
124
|
deleteLabel={(_, label) =>
|
|
121
125
|
onChange?.(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label)))
|
|
122
126
|
}
|
|
123
|
-
categoryName={
|
|
127
|
+
categoryName={categoryName}
|
|
124
128
|
showToolbarItem={showToolbarItem}
|
|
125
129
|
>
|
|
126
130
|
<Popper
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import '@testing-library/jest-dom';
|
|
3
3
|
import DataViewTextFilter, { DataViewTextFilterProps } from './DataViewTextFilter';
|
|
4
4
|
import DataViewToolbar from '../DataViewToolbar';
|
|
@@ -22,6 +22,16 @@ describe('DataViewTextFilter component', () => {
|
|
|
22
22
|
expect(container).toMatchSnapshot();
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
26
|
+
render(<DataViewToolbar
|
|
27
|
+
filters={
|
|
28
|
+
<DataViewTextFilter {...defaultProps} chipTitle="Short name" />
|
|
29
|
+
}
|
|
30
|
+
/>);
|
|
31
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
32
|
+
expect(screen.getByPlaceholderText('Filter by Test Filter')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
25
35
|
it('should focus the search input when "/" key is pressed and filter is visible', () => {
|
|
26
36
|
render(<DataViewToolbar
|
|
27
37
|
filters={
|
|
@@ -9,6 +9,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
|
|
|
9
9
|
value?: string;
|
|
10
10
|
/** Filter title displayed in the toolbar */
|
|
11
11
|
title: string;
|
|
12
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
13
|
+
chipTitle?: string;
|
|
12
14
|
/** Callback for when the input value changes */
|
|
13
15
|
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
|
|
14
16
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -24,6 +26,7 @@ export interface DataViewTextFilterProps extends SearchInputProps {
|
|
|
24
26
|
export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
|
|
25
27
|
filterId,
|
|
26
28
|
title,
|
|
29
|
+
chipTitle,
|
|
27
30
|
value = '',
|
|
28
31
|
onChange,
|
|
29
32
|
onClear = () => onChange?.(undefined, ''),
|
|
@@ -33,6 +36,8 @@ export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
|
|
|
33
36
|
enableShortcut = true,
|
|
34
37
|
...props
|
|
35
38
|
}: DataViewTextFilterProps) => {
|
|
39
|
+
const categoryName = chipTitle ?? title;
|
|
40
|
+
|
|
36
41
|
useEffect(() => {
|
|
37
42
|
if (!enableShortcut) {
|
|
38
43
|
return;
|
|
@@ -68,9 +73,9 @@ export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
|
|
|
68
73
|
<ToolbarFilter
|
|
69
74
|
key={ouiaId}
|
|
70
75
|
data-ouia-component-id={ouiaId}
|
|
71
|
-
labels={value.length > 0 ? [ { key:
|
|
76
|
+
labels={value.length > 0 ? [ { key: categoryName, node: value } ] : []}
|
|
72
77
|
deleteLabel={() => onChange?.(undefined, '')}
|
|
73
|
-
categoryName={
|
|
78
|
+
categoryName={categoryName}
|
|
74
79
|
showToolbarItem={showToolbarItem}
|
|
75
80
|
>
|
|
76
81
|
<SearchInput
|
|
@@ -87,6 +87,17 @@ describe('DataViewTreeFilter component', () => {
|
|
|
87
87
|
);
|
|
88
88
|
expect(container).toMatchSnapshot();
|
|
89
89
|
});
|
|
90
|
+
|
|
91
|
+
it('should use chipTitle for the filter chip category when provided', () => {
|
|
92
|
+
render(
|
|
93
|
+
<DataViewToolbar
|
|
94
|
+
filters={<DataViewTreeFilter {...defaultProps} chipTitle="Short name" />}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
expect(screen.getByText('Short name')).toBeInTheDocument();
|
|
98
|
+
expect(screen.getByText('Test Tree Filter')).toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
|
|
90
101
|
describe('defaultExpanded', () => {
|
|
91
102
|
it('should have expanded items by default', async () => {
|
|
92
103
|
render(
|
|
@@ -89,6 +89,8 @@ export interface DataViewTreeFilterProps {
|
|
|
89
89
|
value?: string[];
|
|
90
90
|
/** Filter title displayed in the toolbar */
|
|
91
91
|
title: string;
|
|
92
|
+
/** Label for the applied filter chip / category; defaults to title */
|
|
93
|
+
chipTitle?: string;
|
|
92
94
|
/** Callback for when the selection changes */
|
|
93
95
|
onChange?: (event?: React.MouseEvent, values?: string[]) => void;
|
|
94
96
|
/** Controls visibility of the filter in the toolbar */
|
|
@@ -108,6 +110,7 @@ export interface DataViewTreeFilterProps {
|
|
|
108
110
|
export const DataViewTreeFilter: FC<DataViewTreeFilterProps> = ({
|
|
109
111
|
filterId,
|
|
110
112
|
title,
|
|
113
|
+
chipTitle,
|
|
111
114
|
value = [],
|
|
112
115
|
onChange,
|
|
113
116
|
showToolbarItem,
|
|
@@ -117,6 +120,7 @@ export const DataViewTreeFilter: FC<DataViewTreeFilterProps> = ({
|
|
|
117
120
|
onSelect,
|
|
118
121
|
defaultSelected = []
|
|
119
122
|
}: DataViewTreeFilterProps) => {
|
|
123
|
+
const categoryName = chipTitle ?? title;
|
|
120
124
|
const classes = useStyles();
|
|
121
125
|
const [isOpen, setIsOpen] = useState(false);
|
|
122
126
|
const [treeData, setTreeData] = useState<TreeViewDataItem[]>(items || []);
|
|
@@ -351,7 +355,7 @@ export const DataViewTreeFilter: FC<DataViewTreeFilterProps> = ({
|
|
|
351
355
|
onFilterSelectorClear(labelKey);
|
|
352
356
|
}}
|
|
353
357
|
deleteLabelGroup={uncheckAllItems}
|
|
354
|
-
categoryName={
|
|
358
|
+
categoryName={categoryName}
|
|
355
359
|
showToolbarItem={showToolbarItem}>
|
|
356
360
|
{dropdown}
|
|
357
361
|
</ToolbarFilter>
|