@patternfly/react-data-view 6.4.0 → 6.5.0-prerelease.1

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.
Files changed (79) hide show
  1. package/dist/cjs/DataViewTable/DataViewTable.d.ts +2 -1
  2. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +11 -0
  3. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +46 -6
  4. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +47 -9
  5. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
  6. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +29 -1
  7. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -1
  8. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +83 -0
  9. package/dist/cjs/DataViewTh/DataViewTh.d.ts +4 -4
  10. package/dist/cjs/DataViewTh/DataViewTh.js +8 -1
  11. package/dist/cjs/DataViewTh/index.d.ts +2 -0
  12. package/dist/cjs/DataViewTh/index.js +23 -0
  13. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +13 -1
  14. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
  15. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.js +229 -0
  16. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
  17. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.js +171 -0
  18. package/dist/cjs/DataViewTreeFilter/index.d.ts +2 -0
  19. package/dist/cjs/DataViewTreeFilter/index.js +23 -0
  20. package/dist/cjs/Hooks/selection.d.ts +8 -8
  21. package/dist/cjs/index.d.ts +6 -0
  22. package/dist/cjs/index.js +10 -1
  23. package/dist/dynamic/DataViewTh/package.json +1 -0
  24. package/dist/dynamic/DataViewTreeFilter/package.json +1 -0
  25. package/dist/dynamic-modules.json +62 -0
  26. package/dist/esm/DataViewTable/DataViewTable.d.ts +2 -1
  27. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +11 -0
  28. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +48 -8
  29. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +45 -10
  30. package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
  31. package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +29 -1
  32. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -1
  33. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +84 -1
  34. package/dist/esm/DataViewTh/DataViewTh.d.ts +4 -4
  35. package/dist/esm/DataViewTh/DataViewTh.js +8 -1
  36. package/dist/esm/DataViewTh/index.d.ts +2 -0
  37. package/dist/esm/DataViewTh/index.js +2 -0
  38. package/dist/esm/DataViewToolbar/DataViewToolbar.js +13 -1
  39. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
  40. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.js +225 -0
  41. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
  42. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.js +166 -0
  43. package/dist/esm/DataViewTreeFilter/index.d.ts +2 -0
  44. package/dist/esm/DataViewTreeFilter/index.js +2 -0
  45. package/dist/esm/Hooks/selection.d.ts +8 -8
  46. package/dist/esm/index.d.ts +6 -0
  47. package/dist/esm/index.js +6 -0
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/generate-fed-package-json.js +18 -0
  50. package/generate-index.js +2 -2
  51. package/package.json +6 -6
  52. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +10 -4
  53. package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +2 -1
  54. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExpandableExample.tsx +108 -0
  55. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableInteractiveExample.tsx +148 -0
  56. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableStickyExample.tsx +90 -0
  57. package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +63 -2
  58. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +2 -1
  59. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +1 -1
  60. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +9 -2
  61. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/TreeFilterExample.tsx +248 -0
  62. package/patternfly-docs/patternfly-docs.config.js +4 -1
  63. package/src/DataViewTable/DataViewTable.tsx +3 -1
  64. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +7 -7
  65. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +54 -12
  66. package/src/DataViewTableBasic/DataViewTableBasic.tsx +101 -10
  67. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +10 -10
  68. package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +129 -0
  69. package/src/DataViewTextFilter/DataViewTextFilter.tsx +58 -22
  70. package/src/DataViewTh/DataViewTh.tsx +15 -7
  71. package/src/DataViewTh/index.ts +2 -0
  72. package/src/DataViewToolbar/DataViewToolbar.tsx +17 -2
  73. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +288 -280
  74. package/src/DataViewTreeFilter/DataViewTreeFilter.test.tsx +222 -0
  75. package/src/DataViewTreeFilter/DataViewTreeFilter.tsx +361 -0
  76. package/src/DataViewTreeFilter/__snapshots__/DataViewTreeFilter.test.tsx.snap +199 -0
  77. package/src/DataViewTreeFilter/index.ts +2 -0
  78. package/src/Hooks/selection.ts +8 -8
  79. package/src/index.ts +9 -0
@@ -1,8 +1,9 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
  import { TdProps, ThProps, TrProps } from '@patternfly/react-table';
3
3
  import { DataViewTableTreeProps } from '../DataViewTableTree';
4
- import { DataViewTableBasicProps } from '../DataViewTableBasic';
4
+ import { DataViewTableBasicProps, ExpandableContent } from '../DataViewTableBasic';
5
5
  import { DataViewThResizableProps } from '../DataViewTh/DataViewTh';
6
+ export type { ExpandableContent };
6
7
  export type DataViewTh = ReactNode | {
7
8
  /** Table head cell node */
8
9
  cell: ReactNode;
@@ -2,12 +2,19 @@ import { FC } 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
+ export interface ExpandableContent {
6
+ rowId: number;
7
+ columnId: number;
8
+ content: React.ReactNode;
9
+ }
5
10
  /** extends TableProps */
6
11
  export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
7
12
  /** Columns definition */
8
13
  columns: DataViewTh[];
9
14
  /** Current page rows */
10
15
  rows: DataViewTr[];
16
+ /** Expanded rows content */
17
+ expandedRows?: ExpandableContent[];
11
18
  /** Table head states to be displayed when active */
12
19
  headStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
13
20
  /** Table body states to be displayed when active */
@@ -16,6 +23,10 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
16
23
  ouiaId?: string;
17
24
  /** @hide Indicates if the table is resizable */
18
25
  hasResizableColumns?: boolean;
26
+ /** Toggles expandable */
27
+ isExpandable?: boolean;
28
+ /** Toggles sticky columns and header */
29
+ isSticky?: boolean;
19
30
  }
20
31
  export declare const DataViewTableBasic: FC<DataViewTableBasicProps>;
21
32
  export default DataViewTableBasic;
@@ -19,14 +19,26 @@ const InternalContext_1 = require("../InternalContext");
19
19
  const DataViewTableHead_1 = require("../DataViewTableHead");
20
20
  const DataViewTable_1 = require("../DataViewTable");
21
21
  const DataViewTableBasic = (_a) => {
22
- var { columns, rows, ouiaId = 'DataViewTableBasic', headStates, bodyStates, hasResizableColumns } = _a, props = __rest(_a, ["columns", "rows", "ouiaId", "headStates", "bodyStates", "hasResizableColumns"]);
22
+ var { columns, rows, expandedRows, ouiaId = 'DataViewTableBasic', headStates, bodyStates, hasResizableColumns, isExpandable = false, isSticky = false } = _a, props = __rest(_a, ["columns", "rows", "expandedRows", "ouiaId", "headStates", "bodyStates", "hasResizableColumns", "isExpandable", "isSticky"]);
23
23
  const { selection, activeState, isSelectable } = (0, InternalContext_1.useInternalContext)();
24
24
  const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
25
25
  const activeHeadState = (0, react_1.useMemo)(() => activeState ? headStates === null || headStates === void 0 ? void 0 : headStates[activeState] : undefined, [activeState, headStates]);
26
26
  const activeBodyState = (0, react_1.useMemo)(() => activeState ? bodyStates === null || bodyStates === void 0 ? void 0 : bodyStates[activeState] : undefined, [activeState, bodyStates]);
27
+ const [expandedRowsState, setExpandedRowsState] = (0, react_1.useState)({});
28
+ const [expandedColumnIndex, setExpandedColumnIndex] = (0, react_1.useState)({});
29
+ const tableRef = (0, react_1.useRef)(null);
30
+ const needsSeparateTbody = isExpandable;
27
31
  const renderedRows = (0, react_1.useMemo)(() => rows.map((row, rowIndex) => {
28
32
  const rowIsObject = (0, DataViewTable_1.isDataViewTrObject)(row);
29
- return ((0, jsx_runtime_1.jsxs)(react_table_1.Tr, Object.assign({ ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props)), { children: [isSelectable && ((0, jsx_runtime_1.jsx)(react_table_1.Td, { select: {
33
+ const isRowExpanded = expandedRowsState[rowIndex] || false;
34
+ const expandedColIndex = expandedColumnIndex[rowIndex];
35
+ // Get the first cell to extract the row ID
36
+ const rowData = rowIsObject ? row.row : row;
37
+ const firstCell = rowData[0];
38
+ const rowId = (0, DataViewTable_1.isDataViewTdObject)(firstCell) ? firstCell.id : undefined;
39
+ // Find all expandable contents for this row
40
+ const rowExpandableContents = isExpandable ? expandedRows === null || expandedRows === void 0 ? void 0 : expandedRows.filter((content) => content.rowId === rowId) : [];
41
+ const rowContent = ((0, jsx_runtime_1.jsxs)(react_table_1.Tr, Object.assign({ ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props)), { isContentExpanded: isRowExpanded, isControlRow: true, children: [isSelectable && ((0, jsx_runtime_1.jsx)(react_table_1.Td, { select: {
30
42
  rowIndex,
31
43
  onSelect: (_event, isSelecting) => {
32
44
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
@@ -36,10 +48,38 @@ const DataViewTableBasic = (_a) => {
36
48
  } }, `select-${rowIndex}`)), (rowIsObject ? row.row : row).map((cell, colIndex) => {
37
49
  var _a;
38
50
  const cellIsObject = (0, DataViewTable_1.isDataViewTdObject)(cell);
39
- return ((0, jsx_runtime_1.jsx)(react_table_1.Td, Object.assign({}, (cellIsObject && ((_a = cell === null || cell === void 0 ? void 0 : cell.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-td-${rowIndex}-${colIndex}`, children: cellIsObject ? cell.cell : cell }), colIndex));
40
- })] }), rowIndex));
41
- }), [rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId]);
42
- return ((0, jsx_runtime_1.jsxs)(react_table_1.Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props, { children: [activeHeadState || (0, jsx_runtime_1.jsx)(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId, hasResizableColumns: hasResizableColumns }), activeBodyState || (0, jsx_runtime_1.jsx)(react_table_1.Tbody, { children: renderedRows })] })));
51
+ const cellExpandableContent = isExpandable ? expandedRows === null || expandedRows === void 0 ? void 0 : expandedRows.find((content) => content.rowId === rowId && content.columnId === colIndex) : undefined;
52
+ return ((0, jsx_runtime_1.jsx)(react_table_1.Td, Object.assign({}, (cellIsObject && ((_a = cell === null || cell === void 0 ? void 0 : cell.props) !== null && _a !== void 0 ? _a : {})), (cellExpandableContent != null && {
53
+ compoundExpand: {
54
+ isExpanded: isRowExpanded && expandedColIndex === colIndex,
55
+ expandId: `expandable-${rowIndex}`,
56
+ onToggle: () => {
57
+ setExpandedRowsState(prev => {
58
+ const isSameColumn = expandedColIndex === colIndex;
59
+ const wasExpanded = prev[rowIndex];
60
+ return Object.assign(Object.assign({}, prev), { [rowIndex]: isSameColumn ? !wasExpanded : true });
61
+ });
62
+ setExpandedColumnIndex(prev => (Object.assign(Object.assign({}, prev), { [rowIndex]: colIndex })));
63
+ },
64
+ rowIndex,
65
+ columnIndex: colIndex
66
+ }
67
+ }), { "data-ouia-component-id": `${ouiaId}-td-${rowIndex}-${colIndex}`, children: cellIsObject ? cell.cell : cell }), colIndex));
68
+ })] }), needsSeparateTbody ? undefined : rowIndex));
69
+ if (needsSeparateTbody) {
70
+ return ((0, jsx_runtime_1.jsxs)(react_table_1.Tbody, { isExpanded: isRowExpanded, children: [rowContent, rowExpandableContents === null || rowExpandableContents === void 0 ? void 0 : rowExpandableContents.map((expandableContent) => ((0, jsx_runtime_1.jsx)(react_table_1.Tr, { isExpanded: isRowExpanded && expandedColIndex === expandableContent.columnId, children: (0, jsx_runtime_1.jsx)(react_table_1.Td, { colSpan: rowData.length + (isSelectable ? 1 : 0), "data-expanded-column-index": expandableContent.columnId, children: (0, jsx_runtime_1.jsx)(react_table_1.ExpandableRowContent, { children: expandableContent.content }) }) }, `expand-${rowIndex}-${expandableContent.columnId}`)))] }, rowIndex));
71
+ }
72
+ else {
73
+ return rowContent;
74
+ }
75
+ }), [rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId, expandedRowsState, expandedColumnIndex, expandedRows, isExpandable, needsSeparateTbody]);
76
+ const bodyContent = activeBodyState || (needsSeparateTbody ? renderedRows : (0, jsx_runtime_1.jsx)(react_table_1.Tbody, { children: renderedRows }));
77
+ if (isSticky) {
78
+ return ((0, jsx_runtime_1.jsx)(react_table_1.OuterScrollContainer, { children: (0, jsx_runtime_1.jsx)(react_table_1.InnerScrollContainer, { children: (0, jsx_runtime_1.jsxs)(react_table_1.Table, Object.assign({ ref: tableRef, "aria-label": "Data table", ouiaId: ouiaId, isExpandable: isExpandable, hasAnimations: true }, props, { isStickyHeader: true, children: [activeHeadState || (0, jsx_runtime_1.jsx)(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId, hasResizableColumns: hasResizableColumns }), bodyContent] })) }) }));
79
+ }
80
+ else {
81
+ return ((0, jsx_runtime_1.jsxs)(react_table_1.Table, Object.assign({ ref: tableRef, "aria-label": "Data table", ouiaId: ouiaId, isExpandable: isExpandable, hasAnimations: true }, props, { children: [activeHeadState || (0, jsx_runtime_1.jsx)(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId, hasResizableColumns: hasResizableColumns }), bodyContent] })));
82
+ }
43
83
  };
44
84
  exports.DataViewTableBasic = DataViewTableBasic;
45
85
  exports.default = exports.DataViewTableBasic;
@@ -1,21 +1,41 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  const jsx_runtime_1 = require("react/jsx-runtime");
4
16
  const react_1 = require("@testing-library/react");
17
+ const user_event_1 = __importDefault(require("@testing-library/user-event"));
5
18
  const DataView_1 = require("../DataView");
6
19
  const DataViewTableBasic_1 = require("./DataViewTableBasic");
7
20
  const repositories = [
8
- { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
9
- { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
10
- { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
11
- { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
12
- { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
13
- { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
21
+ { id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
22
+ { id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
23
+ { id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
24
+ { id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
25
+ { id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
26
+ { id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
14
27
  ];
15
- const rows = repositories.map(repo => ({
16
- row: Object.values(repo),
17
- }));
28
+ const rows = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
29
+ { id, cell: name },
30
+ branches,
31
+ prs,
32
+ workspaces,
33
+ lastCommit
34
+ ]);
18
35
  const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
36
+ const expandableContents = [
37
+ { rowId: 1, columnId: 1, content: (0, jsx_runtime_1.jsx)("div", { children: "Branch details for Repository one" }) },
38
+ ];
19
39
  const ouiaId = 'TableExample';
20
40
  describe('DataViewTable component', () => {
21
41
  test('should render correctly', () => {
@@ -34,4 +54,22 @@ describe('DataViewTable component', () => {
34
54
  const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(DataView_1.DataView, { activeState: "loading", children: (0, jsx_runtime_1.jsx)(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] }) }));
35
55
  expect(container).toMatchSnapshot();
36
56
  });
57
+ test('when isExpandable cell should be clickable and expandable', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ var _a, _b, _c;
59
+ const user = user_event_1.default.setup();
60
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows, isExpandable: true, expandedRows: expandableContents }));
61
+ // Initially, expandable content is rendered but should be hidden (not visible)
62
+ const initialBranchContent = react_1.screen.getByText('Branch details for Repository one');
63
+ expect((_a = initialBranchContent.closest('tr')) === null || _a === void 0 ? void 0 : _a.classList.contains('pf-m-expanded')).toBeFalsy();
64
+ // Find the first expandable button by ID
65
+ const branchExpandButton = document.getElementById('expandable-0-0-1');
66
+ expect(branchExpandButton).toBeTruthy();
67
+ // Verify the button is in the cell with "Branch one" text
68
+ expect((_b = branchExpandButton === null || branchExpandButton === void 0 ? void 0 : branchExpandButton.closest('td')) === null || _b === void 0 ? void 0 : _b.textContent).toContain('Branch one');
69
+ // Click the expand button for Branches column
70
+ yield user.click(branchExpandButton);
71
+ // After clicking, the expandable content should be visible
72
+ const branchContent = react_1.screen.getByText('Branch details for Repository one');
73
+ expect((_c = branchContent.closest('tr')) === null || _c === void 0 ? void 0 : _c.classList.contains('pf-m-expanded')).toBeTruthy();
74
+ }));
37
75
  });
@@ -16,6 +16,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
16
16
  trimValue?: boolean;
17
17
  /** Custom OUIA ID */
18
18
  ouiaId?: string;
19
+ /** Enable keyboard shortcut (/) to focus the filter. Defaults to true. */
20
+ enableShortcut?: boolean;
19
21
  }
20
22
  export declare const DataViewTextFilter: FC<DataViewTextFilterProps>;
21
23
  export default DataViewTextFilter;
@@ -13,9 +13,37 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.DataViewTextFilter = void 0;
15
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
+ const react_1 = require("react");
16
17
  const react_core_1 = require("@patternfly/react-core");
17
18
  const DataViewTextFilter = (_a) => {
18
- 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"]);
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"]);
20
+ (0, react_1.useEffect)(() => {
21
+ if (!enableShortcut) {
22
+ return;
23
+ }
24
+ const handleKeyDown = (event) => {
25
+ // Only handle "/" key when not typing in an input, textarea, or contenteditable element
26
+ if (event.key === '/' && !event.ctrlKey && !event.metaKey && !event.altKey) {
27
+ const target = event.target;
28
+ const isInputElement = target.tagName === 'INPUT' ||
29
+ target.tagName === 'TEXTAREA' ||
30
+ target.isContentEditable;
31
+ // Only focus if the filter is visible and we're not already in an input field
32
+ if (showToolbarItem && !isInputElement) {
33
+ // Find the input element by its ID (searchInputId prop)
34
+ const inputElement = document.getElementById(filterId);
35
+ if (inputElement) {
36
+ event.preventDefault();
37
+ inputElement.focus();
38
+ }
39
+ }
40
+ }
41
+ };
42
+ window.addEventListener('keydown', handleKeyDown);
43
+ return () => {
44
+ window.removeEventListener('keydown', handleKeyDown);
45
+ };
46
+ }, [showToolbarItem, filterId, enableShortcut]);
19
47
  return ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarFilter, { "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, 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));
20
48
  };
21
49
  exports.DataViewTextFilter = DataViewTextFilter;
@@ -1 +1 @@
1
- export {};
1
+ import '@testing-library/jest-dom';
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const react_1 = require("@testing-library/react");
8
+ require("@testing-library/jest-dom");
8
9
  const DataViewTextFilter_1 = __importDefault(require("./DataViewTextFilter"));
9
10
  const DataViewToolbar_1 = __importDefault(require("../DataViewToolbar"));
10
11
  describe('DataViewTextFilter component', () => {
@@ -19,4 +20,86 @@ describe('DataViewTextFilter component', () => {
19
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)) }));
20
21
  expect(container).toMatchSnapshot();
21
22
  });
23
+ it('should focus the search input when "/" key is pressed and filter is visible', () => {
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, { showToolbarItem: true })) }));
25
+ const input = document.getElementById('test-filter');
26
+ expect(input).toBeInTheDocument();
27
+ // Simulate pressing "/" key by creating and dispatching a KeyboardEvent
28
+ const keyEvent = new KeyboardEvent('keydown', {
29
+ key: '/',
30
+ code: 'Slash',
31
+ bubbles: true,
32
+ cancelable: true,
33
+ });
34
+ window.dispatchEvent(keyEvent);
35
+ // Check that the input has focus
36
+ expect(document.activeElement).toBe(input);
37
+ });
38
+ it('should not focus the search input when "/" key is pressed if filter is not visible', () => {
39
+ (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: false })) }));
40
+ const input = document.getElementById('test-filter');
41
+ // Simulate pressing "/" key
42
+ const keyEvent = new KeyboardEvent('keydown', {
43
+ key: '/',
44
+ code: 'Slash',
45
+ bubbles: true,
46
+ cancelable: true,
47
+ });
48
+ window.dispatchEvent(keyEvent);
49
+ if (input) {
50
+ expect(document.activeElement).not.toBe(input);
51
+ }
52
+ });
53
+ it('should not focus the search input when "/" key is pressed while typing in another input', () => {
54
+ const { container } = (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", { "data-testid": "other-input" }), (0, jsx_runtime_1.jsx)(DataViewToolbar_1.default, { filters: (0, jsx_runtime_1.jsx)(DataViewTextFilter_1.default, Object.assign({}, defaultProps, { showToolbarItem: true })) })] }));
55
+ const otherInput = container.querySelector('[data-testid="other-input"]');
56
+ // Focus the other input first
57
+ otherInput.focus();
58
+ expect(document.activeElement).toBe(otherInput);
59
+ // Simulate pressing "/" key while focused on the other input
60
+ // The event target should be the input element
61
+ const keyEvent = new KeyboardEvent('keydown', {
62
+ key: '/',
63
+ code: 'Slash',
64
+ bubbles: true,
65
+ cancelable: true,
66
+ });
67
+ Object.defineProperty(keyEvent, 'target', {
68
+ value: otherInput,
69
+ enumerable: true,
70
+ });
71
+ window.dispatchEvent(keyEvent);
72
+ // The search input should not be focused since we're already in an input field
73
+ expect(document.activeElement).toBe(otherInput);
74
+ });
75
+ it('should not focus the search input when enableShortcut is false', () => {
76
+ (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, enableShortcut: false })) }));
77
+ const input = document.getElementById('test-filter');
78
+ expect(input).toBeInTheDocument();
79
+ // Simulate pressing "/" key
80
+ const keyEvent = new KeyboardEvent('keydown', {
81
+ key: '/',
82
+ code: 'Slash',
83
+ bubbles: true,
84
+ cancelable: true,
85
+ });
86
+ window.dispatchEvent(keyEvent);
87
+ // The input should not be focused since the shortcut is disabled
88
+ expect(document.activeElement).not.toBe(input);
89
+ });
90
+ it('should focus the search input when enableShortcut is true (default)', () => {
91
+ (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 })) }));
92
+ const input = document.getElementById('test-filter');
93
+ expect(input).toBeInTheDocument();
94
+ // Simulate pressing "/" key
95
+ const keyEvent = new KeyboardEvent('keydown', {
96
+ key: '/',
97
+ code: 'Slash',
98
+ bubbles: true,
99
+ cancelable: true,
100
+ });
101
+ window.dispatchEvent(keyEvent);
102
+ // The input should be focused since the shortcut is enabled by default
103
+ expect(document.activeElement).toBe(input);
104
+ });
22
105
  });
@@ -5,13 +5,13 @@ export interface DataViewThResizableProps {
5
5
  isResizable?: boolean;
6
6
  /** Callback after the column is resized. Returns the triggering event, the column id passed in via cell props, and the new width of the column. */
7
7
  onResize?: (event: ReactMouseEvent | MouseEvent | ReactKeyboardEvent | KeyboardEvent | TouchEvent, id: string | number | undefined, width: number) => void;
8
- /** Width of the column */
8
+ /** Starting width in pixels of the column */
9
9
  width?: number;
10
- /** Minimum width of the column */
10
+ /** Minimum resize width in pixels of the column */
11
11
  minWidth?: number;
12
- /** Increment for keyboard navigation */
12
+ /** Increment in pixels for keyboard navigation */
13
13
  increment?: number;
14
- /** Increment for keyboard navigation while shift is held */
14
+ /** Increment in pixels for keyboard navigation while shift is held */
15
15
  shiftIncrement?: number;
16
16
  /** Provides an accessible name for the resizable column via a human readable string. */
17
17
  resizeButtonAriaLabel?: string;
@@ -216,7 +216,14 @@ const DataViewTh = (_a) => {
216
216
  onResize && onResize(e, thProps === null || thProps === void 0 ? void 0 : thProps.id, newSize);
217
217
  };
218
218
  const resizableContent = ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { "aria-live": "polite", className: "pf-v6-screen-reader", children: screenReaderText }), (0, jsx_runtime_1.jsx)(react_core_1.Button, { ref: resizeButtonRef, variant: "plain", hasNoPadding: true, icon: (0, jsx_runtime_1.jsx)(ResizeIcon, {}), onMouseDown: handleMousedown, onKeyDown: handleKeys, onTouchStart: handleTouchStart, "aria-label": resizeButtonAriaLabel, className: classes.dataViewResizableButton })] }));
219
- return ((0, jsx_runtime_1.jsx)(react_table_1.Th, Object.assign({}, thProps, props, { style: width > 0 ? { minWidth: width } : undefined, ref: thRef, modifier: "truncate", className: dataViewThClassName }, (isResizable && { additionalContent: resizableContent }), { children: content })));
219
+ const classNames = [];
220
+ if (thProps === null || thProps === void 0 ? void 0 : thProps.className) {
221
+ classNames.push(thProps.className);
222
+ }
223
+ if (dataViewThClassName) {
224
+ classNames.push(dataViewThClassName);
225
+ }
226
+ return ((0, jsx_runtime_1.jsx)(react_table_1.Th, Object.assign({ modifier: "truncate" }, thProps, props, { ref: thRef, style: width > 0 ? Object.assign(Object.assign({}, thProps === null || thProps === void 0 ? void 0 : thProps.style), { minWidth: width }) : thProps === null || thProps === void 0 ? void 0 : thProps.style, className: classNames.length > 0 ? classNames.join(' ') : undefined }, (isResizable && { additionalContent: resizableContent }), { children: content })));
220
227
  };
221
228
  exports.DataViewTh = DataViewTh;
222
229
  exports.default = exports.DataViewTh;
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTh';
2
+ export * from './DataViewTh';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.default = void 0;
21
+ var DataViewTh_1 = require("./DataViewTh");
22
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(DataViewTh_1).default; } });
23
+ __exportStar(require("./DataViewTh"), exports);
@@ -15,10 +15,22 @@ exports.DataViewToolbar = void 0;
15
15
  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
+ const react_jss_1 = require("react-jss");
19
+ const useStyles = (0, react_jss_1.createUseStyles)({
20
+ dataViewToolbarPagination: {
21
+ flexBasis: '100%',
22
+ width: '100%'
23
+ },
24
+ dataViewToolbarPaginationWrapper: {
25
+ flexBasis: '100%',
26
+ width: '100%'
27
+ }
28
+ });
18
29
  const DataViewToolbar = (_a) => {
19
30
  var { className, ouiaId = 'DataViewToolbar', bulkSelect, actions, toggleGroup, pagination, filters, customLabelGroupContent, clearAllFilters, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "actions", "toggleGroup", "pagination", "filters", "customLabelGroupContent", "clearAllFilters", "children"]);
31
+ const classes = useStyles();
20
32
  const defaultClearFilters = (0, react_1.useRef)((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, { ouiaId: `${ouiaId}-clear-all-filters`, variant: "link", onClick: clearAllFilters, isInline: true, children: "Clear filters" }) }));
21
- return ((0, jsx_runtime_1.jsx)(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className, customLabelGroupContent: customLabelGroupContent !== null && customLabelGroupContent !== void 0 ? customLabelGroupContent : defaultClearFilters.current }, props, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarContent, { children: [bulkSelect && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select`, children: bulkSelect })), filters && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: filters })), actions && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: actions })), toggleGroup && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: toggleGroup })), pagination && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination`, children: pagination })), children] }) })));
33
+ return ((0, jsx_runtime_1.jsx)(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className, customLabelGroupContent: customLabelGroupContent !== null && customLabelGroupContent !== void 0 ? customLabelGroupContent : defaultClearFilters.current }, props, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarContent, { children: [bulkSelect && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select`, children: bulkSelect })), filters && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: filters })), actions && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: actions })), toggleGroup && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: toggleGroup })), pagination && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination`, className: classes.dataViewToolbarPagination, children: (0, jsx_runtime_1.jsx)("div", { className: classes.dataViewToolbarPaginationWrapper, children: pagination }) })), children] }) })));
22
34
  };
23
35
  exports.DataViewToolbar = DataViewToolbar;
24
36
  exports.default = exports.DataViewToolbar;
@@ -0,0 +1,26 @@
1
+ import { ToolbarFilterProps, TreeViewDataItem } from '@patternfly/react-core';
2
+ import React, { FC } from 'react';
3
+ export interface DataViewTreeFilterProps {
4
+ /** Unique key for the filter attribute */
5
+ filterId: string;
6
+ /** Array of current filter values */
7
+ value?: string[];
8
+ /** Filter title displayed in the toolbar */
9
+ title: string;
10
+ /** Callback for when the selection changes */
11
+ onChange?: (event?: React.MouseEvent, values?: string[]) => void;
12
+ /** Controls visibility of the filter in the toolbar */
13
+ showToolbarItem?: ToolbarFilterProps['showToolbarItem'];
14
+ /** Custom OUIA ID */
15
+ ouiaId?: string;
16
+ /** Hierarchical data items for the tree structure */
17
+ items?: TreeViewDataItem[];
18
+ /** When true, expands all tree nodes by default */
19
+ defaultExpanded?: boolean;
20
+ /** Callback for when tree items are selected/deselected, provides all currently selected nodes */
21
+ onSelect?: (selectedItems: TreeViewDataItem[]) => void;
22
+ /** Array of pre-selected item id's to be checked on initial render */
23
+ defaultSelected?: string[];
24
+ }
25
+ export declare const DataViewTreeFilter: FC<DataViewTreeFilterProps>;
26
+ export default DataViewTreeFilter;