@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.
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +2 -1
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +11 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +46 -6
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +47 -9
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +29 -1
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -1
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +83 -0
- package/dist/cjs/DataViewTh/DataViewTh.d.ts +4 -4
- package/dist/cjs/DataViewTh/DataViewTh.js +8 -1
- package/dist/cjs/DataViewTh/index.d.ts +2 -0
- package/dist/cjs/DataViewTh/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +13 -1
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.js +229 -0
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.js +171 -0
- package/dist/cjs/DataViewTreeFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewTreeFilter/index.js +23 -0
- package/dist/cjs/Hooks/selection.d.ts +8 -8
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +10 -1
- package/dist/dynamic/DataViewTh/package.json +1 -0
- package/dist/dynamic/DataViewTreeFilter/package.json +1 -0
- package/dist/dynamic-modules.json +62 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +2 -1
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +11 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +48 -8
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +45 -10
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +2 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +29 -1
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -1
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +84 -1
- package/dist/esm/DataViewTh/DataViewTh.d.ts +4 -4
- package/dist/esm/DataViewTh/DataViewTh.js +8 -1
- package/dist/esm/DataViewTh/index.d.ts +2 -0
- package/dist/esm/DataViewTh/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +13 -1
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.js +225 -0
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
- package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.js +166 -0
- package/dist/esm/DataViewTreeFilter/index.d.ts +2 -0
- package/dist/esm/DataViewTreeFilter/index.js +2 -0
- package/dist/esm/Hooks/selection.d.ts +8 -8
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/generate-fed-package-json.js +18 -0
- package/generate-index.js +2 -2
- package/package.json +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +10 -4
- package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExpandableExample.tsx +108 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableInteractiveExample.tsx +148 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableStickyExample.tsx +90 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +63 -2
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +9 -2
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/TreeFilterExample.tsx +248 -0
- package/patternfly-docs/patternfly-docs.config.js +4 -1
- package/src/DataViewTable/DataViewTable.tsx +3 -1
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +7 -7
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +54 -12
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +101 -10
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +10 -10
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +129 -0
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +58 -22
- package/src/DataViewTh/DataViewTh.tsx +15 -7
- package/src/DataViewTh/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +17 -2
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +288 -280
- package/src/DataViewTreeFilter/DataViewTreeFilter.test.tsx +222 -0
- package/src/DataViewTreeFilter/DataViewTreeFilter.tsx +361 -0
- package/src/DataViewTreeFilter/__snapshots__/DataViewTreeFilter.test.tsx.snap +199 -0
- package/src/DataViewTreeFilter/index.ts +2 -0
- package/src/Hooks/selection.ts +8 -8
- package/src/index.ts +9 -0
|
@@ -4,7 +4,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
4
4
|
<div>
|
|
5
5
|
<table
|
|
6
6
|
aria-label="Repositories table"
|
|
7
|
-
class="pf-v6-c-table pf-m-grid-md"
|
|
7
|
+
class="pf-v6-c-table pf-m-grid-md pf-m-animate-expand"
|
|
8
8
|
data-ouia-component-id="TableExample"
|
|
9
9
|
data-ouia-component-type="PF6/Table"
|
|
10
10
|
data-ouia-safe="true"
|
|
@@ -67,7 +67,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
67
67
|
role="rowgroup"
|
|
68
68
|
>
|
|
69
69
|
<tr
|
|
70
|
-
class="pf-v6-c-table__tr"
|
|
70
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
71
71
|
data-ouia-component-id="TableExample-tr-0"
|
|
72
72
|
data-ouia-component-type="PF6/TableRow"
|
|
73
73
|
data-ouia-safe="true"
|
|
@@ -109,7 +109,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
109
109
|
</td>
|
|
110
110
|
</tr>
|
|
111
111
|
<tr
|
|
112
|
-
class="pf-v6-c-table__tr"
|
|
112
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
113
113
|
data-ouia-component-id="TableExample-tr-1"
|
|
114
114
|
data-ouia-component-type="PF6/TableRow"
|
|
115
115
|
data-ouia-safe="true"
|
|
@@ -151,7 +151,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
151
151
|
</td>
|
|
152
152
|
</tr>
|
|
153
153
|
<tr
|
|
154
|
-
class="pf-v6-c-table__tr"
|
|
154
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
155
155
|
data-ouia-component-id="TableExample-tr-2"
|
|
156
156
|
data-ouia-component-type="PF6/TableRow"
|
|
157
157
|
data-ouia-safe="true"
|
|
@@ -193,7 +193,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
193
193
|
</td>
|
|
194
194
|
</tr>
|
|
195
195
|
<tr
|
|
196
|
-
class="pf-v6-c-table__tr"
|
|
196
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
197
197
|
data-ouia-component-id="TableExample-tr-3"
|
|
198
198
|
data-ouia-component-type="PF6/TableRow"
|
|
199
199
|
data-ouia-safe="true"
|
|
@@ -235,7 +235,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
235
235
|
</td>
|
|
236
236
|
</tr>
|
|
237
237
|
<tr
|
|
238
|
-
class="pf-v6-c-table__tr"
|
|
238
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
239
239
|
data-ouia-component-id="TableExample-tr-4"
|
|
240
240
|
data-ouia-component-type="PF6/TableRow"
|
|
241
241
|
data-ouia-safe="true"
|
|
@@ -277,7 +277,7 @@ exports[`DataViewTable component should render a basic table correctly 1`] = `
|
|
|
277
277
|
</td>
|
|
278
278
|
</tr>
|
|
279
279
|
<tr
|
|
280
|
-
class="pf-v6-c-table__tr"
|
|
280
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
281
281
|
data-ouia-component-id="TableExample-tr-5"
|
|
282
282
|
data-ouia-component-type="PF6/TableRow"
|
|
283
283
|
data-ouia-safe="true"
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
2
3
|
import { DataView } from '../DataView';
|
|
3
|
-
import { DataViewTableBasic } from './DataViewTableBasic';
|
|
4
|
+
import { DataViewTableBasic, ExpandableContent } from './DataViewTableBasic';
|
|
4
5
|
|
|
5
6
|
interface Repository {
|
|
7
|
+
id: number;
|
|
6
8
|
name: string;
|
|
7
9
|
branches: string | null;
|
|
8
10
|
prs: string | null;
|
|
@@ -11,20 +13,28 @@ interface Repository {
|
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
const repositories: Repository[] = [
|
|
14
|
-
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
15
|
-
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
16
|
-
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
17
|
-
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
18
|
-
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
19
|
-
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
16
|
+
{ id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
17
|
+
{ id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
18
|
+
{ id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
19
|
+
{ id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
20
|
+
{ id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
21
|
+
{ id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
20
22
|
];
|
|
21
23
|
|
|
22
|
-
const rows = repositories.map(
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const rows = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
|
|
25
|
+
{ id, cell: name },
|
|
26
|
+
branches,
|
|
27
|
+
prs,
|
|
28
|
+
workspaces,
|
|
29
|
+
lastCommit
|
|
30
|
+
]);
|
|
25
31
|
|
|
26
32
|
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
27
33
|
|
|
34
|
+
const expandableContents: ExpandableContent[] = [
|
|
35
|
+
{ rowId: 1, columnId: 1, content: <div>Branch details for Repository one</div> },
|
|
36
|
+
];
|
|
37
|
+
|
|
28
38
|
const ouiaId = 'TableExample';
|
|
29
39
|
|
|
30
40
|
describe('DataViewTable component', () => {
|
|
@@ -57,8 +67,40 @@ describe('DataViewTable component', () => {
|
|
|
57
67
|
const { container } = render(
|
|
58
68
|
<DataView activeState="loading">
|
|
59
69
|
<DataViewTableBasic aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ loading: "Data is loading" }} rows={[]} />
|
|
60
|
-
</DataView>
|
|
70
|
+
</DataView>
|
|
61
71
|
);
|
|
62
72
|
expect(container).toMatchSnapshot();
|
|
63
73
|
});
|
|
74
|
+
|
|
75
|
+
test('when isExpandable cell should be clickable and expandable', async () => {
|
|
76
|
+
const user = userEvent.setup();
|
|
77
|
+
|
|
78
|
+
render(
|
|
79
|
+
<DataViewTableBasic
|
|
80
|
+
aria-label='Repositories table'
|
|
81
|
+
ouiaId={ouiaId}
|
|
82
|
+
columns={columns}
|
|
83
|
+
rows={rows}
|
|
84
|
+
isExpandable={true}
|
|
85
|
+
expandedRows={expandableContents}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Initially, expandable content is rendered but should be hidden (not visible)
|
|
90
|
+
const initialBranchContent = screen.getByText('Branch details for Repository one');
|
|
91
|
+
expect(initialBranchContent.closest('tr')?.classList.contains('pf-m-expanded')).toBeFalsy();
|
|
92
|
+
|
|
93
|
+
// Find the first expandable button by ID
|
|
94
|
+
const branchExpandButton = document.getElementById('expandable-0-0-1');
|
|
95
|
+
expect(branchExpandButton).toBeTruthy();
|
|
96
|
+
// Verify the button is in the cell with "Branch one" text
|
|
97
|
+
expect(branchExpandButton?.closest('td')?.textContent).toContain('Branch one');
|
|
98
|
+
|
|
99
|
+
// Click the expand button for Branches column
|
|
100
|
+
await user.click(branchExpandButton!);
|
|
101
|
+
|
|
102
|
+
// After clicking, the expandable content should be visible
|
|
103
|
+
const branchContent = screen.getByText('Branch details for Repository one');
|
|
104
|
+
expect(branchContent.closest('tr')?.classList.contains('pf-m-expanded')).toBeTruthy();
|
|
105
|
+
});
|
|
64
106
|
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { FC, useMemo } from 'react';
|
|
1
|
+
import { FC, useMemo, useState, useRef } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
ExpandableRowContent,
|
|
4
|
+
InnerScrollContainer,
|
|
5
|
+
OuterScrollContainer,
|
|
3
6
|
Table,
|
|
4
7
|
TableProps,
|
|
5
8
|
Tbody,
|
|
@@ -11,12 +14,20 @@ import { DataViewTableHead } from '../DataViewTableHead';
|
|
|
11
14
|
import { DataViewTh, DataViewTr, isDataViewTdObject, isDataViewTrObject } from '../DataViewTable';
|
|
12
15
|
import { DataViewState } from '../DataView/DataView';
|
|
13
16
|
|
|
17
|
+
export interface ExpandableContent {
|
|
18
|
+
rowId: number;
|
|
19
|
+
columnId: number;
|
|
20
|
+
content: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
/** extends TableProps */
|
|
15
24
|
export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
16
25
|
/** Columns definition */
|
|
17
26
|
columns: DataViewTh[];
|
|
18
27
|
/** Current page rows */
|
|
19
28
|
rows: DataViewTr[];
|
|
29
|
+
/** Expanded rows content */
|
|
30
|
+
expandedRows?: ExpandableContent[];
|
|
20
31
|
/** Table head states to be displayed when active */
|
|
21
32
|
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>
|
|
22
33
|
/** Table body states to be displayed when active */
|
|
@@ -25,15 +36,22 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
|
|
|
25
36
|
ouiaId?: string;
|
|
26
37
|
/** @hide Indicates if the table is resizable */
|
|
27
38
|
hasResizableColumns?: boolean;
|
|
39
|
+
/** Toggles expandable */
|
|
40
|
+
isExpandable?: boolean;
|
|
41
|
+
/** Toggles sticky columns and header */
|
|
42
|
+
isSticky?: boolean;
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
|
|
31
46
|
columns,
|
|
32
47
|
rows,
|
|
48
|
+
expandedRows,
|
|
33
49
|
ouiaId = 'DataViewTableBasic',
|
|
34
50
|
headStates,
|
|
35
51
|
bodyStates,
|
|
36
52
|
hasResizableColumns,
|
|
53
|
+
isExpandable = false,
|
|
54
|
+
isSticky = false,
|
|
37
55
|
...props
|
|
38
56
|
}: DataViewTableBasicProps) => {
|
|
39
57
|
const { selection, activeState, isSelectable } = useInternalContext();
|
|
@@ -42,10 +60,30 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
|
|
|
42
60
|
const activeHeadState = useMemo(() => activeState ? headStates?.[activeState] : undefined, [ activeState, headStates ]);
|
|
43
61
|
const activeBodyState = useMemo(() => activeState ? bodyStates?.[activeState] : undefined, [ activeState, bodyStates ]);
|
|
44
62
|
|
|
63
|
+
const [expandedRowsState, setExpandedRowsState] = useState<Record<number, boolean>>({})
|
|
64
|
+
const [expandedColumnIndex, setExpandedColumnIndex] = useState<Record<number, number>>({})
|
|
65
|
+
|
|
66
|
+
const tableRef = useRef<HTMLTableElement>(null);
|
|
67
|
+
|
|
68
|
+
const needsSeparateTbody = isExpandable;
|
|
69
|
+
|
|
45
70
|
const renderedRows = useMemo(() => rows.map((row, rowIndex) => {
|
|
46
71
|
const rowIsObject = isDataViewTrObject(row);
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
const isRowExpanded = expandedRowsState[rowIndex] || false;
|
|
73
|
+
const expandedColIndex = expandedColumnIndex[rowIndex];
|
|
74
|
+
|
|
75
|
+
// Get the first cell to extract the row ID
|
|
76
|
+
const rowData = rowIsObject ? row.row : row;
|
|
77
|
+
const firstCell = rowData[0];
|
|
78
|
+
const rowId = isDataViewTdObject(firstCell) ? (firstCell as { id?: number }).id : undefined;
|
|
79
|
+
|
|
80
|
+
// Find all expandable contents for this row
|
|
81
|
+
const rowExpandableContents = isExpandable ? expandedRows?.filter(
|
|
82
|
+
(content) => content.rowId === rowId
|
|
83
|
+
) : [];
|
|
84
|
+
|
|
85
|
+
const rowContent = (
|
|
86
|
+
<Tr key={needsSeparateTbody ? undefined : rowIndex} ouiaId={`${ouiaId}-tr-${rowIndex}`} {...(rowIsObject && row?.props)} isContentExpanded={isRowExpanded} isControlRow>
|
|
49
87
|
{isSelectable && (
|
|
50
88
|
<Td
|
|
51
89
|
key={`select-${rowIndex}`}
|
|
@@ -61,10 +99,29 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
|
|
|
61
99
|
)}
|
|
62
100
|
{(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
63
101
|
const cellIsObject = isDataViewTdObject(cell);
|
|
102
|
+
const cellExpandableContent = isExpandable ? expandedRows?.find(
|
|
103
|
+
(content) => content.rowId === rowId && content.columnId === colIndex
|
|
104
|
+
) : undefined;
|
|
64
105
|
return (
|
|
65
106
|
<Td
|
|
66
107
|
key={colIndex}
|
|
67
108
|
{...(cellIsObject && (cell?.props ?? {}))}
|
|
109
|
+
{...(cellExpandableContent != null && {
|
|
110
|
+
compoundExpand: {
|
|
111
|
+
isExpanded: isRowExpanded && expandedColIndex === colIndex,
|
|
112
|
+
expandId: `expandable-${rowIndex}`,
|
|
113
|
+
onToggle: () => {
|
|
114
|
+
setExpandedRowsState(prev => {
|
|
115
|
+
const isSameColumn = expandedColIndex === colIndex;
|
|
116
|
+
const wasExpanded = prev[rowIndex];
|
|
117
|
+
return { ...prev, [rowIndex]: isSameColumn ? !wasExpanded : true };
|
|
118
|
+
});
|
|
119
|
+
setExpandedColumnIndex(prev => ({ ...prev, [rowIndex]: colIndex }));
|
|
120
|
+
},
|
|
121
|
+
rowIndex,
|
|
122
|
+
columnIndex: colIndex
|
|
123
|
+
}
|
|
124
|
+
})}
|
|
68
125
|
data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}
|
|
69
126
|
>
|
|
70
127
|
{cellIsObject ? cell.cell : cell}
|
|
@@ -73,14 +130,48 @@ export const DataViewTableBasic: FC<DataViewTableBasicProps> = ({
|
|
|
73
130
|
})}
|
|
74
131
|
</Tr>
|
|
75
132
|
);
|
|
76
|
-
}), [ rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId ]);
|
|
77
133
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
134
|
+
if (needsSeparateTbody) {
|
|
135
|
+
return (
|
|
136
|
+
<Tbody key={rowIndex} isExpanded={isRowExpanded}>
|
|
137
|
+
{rowContent}
|
|
138
|
+
{rowExpandableContents?.map((expandableContent) => (
|
|
139
|
+
<Tr key={`expand-${rowIndex}-${expandableContent.columnId}`} isExpanded={isRowExpanded && expandedColIndex === expandableContent.columnId}>
|
|
140
|
+
<Td colSpan={rowData.length + (isSelectable ? 1 : 0)} data-expanded-column-index={expandableContent.columnId}>
|
|
141
|
+
<ExpandableRowContent>
|
|
142
|
+
{expandableContent.content}
|
|
143
|
+
</ExpandableRowContent>
|
|
144
|
+
</Td>
|
|
145
|
+
</Tr>
|
|
146
|
+
))}
|
|
147
|
+
</Tbody>
|
|
148
|
+
);
|
|
149
|
+
} else {
|
|
150
|
+
return rowContent;
|
|
151
|
+
}
|
|
152
|
+
}), [ rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId, expandedRowsState, expandedColumnIndex, expandedRows, isExpandable, needsSeparateTbody ]);
|
|
153
|
+
|
|
154
|
+
const bodyContent = activeBodyState || (needsSeparateTbody ? renderedRows : <Tbody>{renderedRows}</Tbody>);
|
|
155
|
+
|
|
156
|
+
if (isSticky) {
|
|
157
|
+
return (
|
|
158
|
+
<OuterScrollContainer>
|
|
159
|
+
<InnerScrollContainer>
|
|
160
|
+
<Table ref={tableRef} aria-label="Data table" ouiaId={ouiaId} isExpandable={isExpandable} hasAnimations {...props} isStickyHeader >
|
|
161
|
+
{ activeHeadState || <DataViewTableHead columns={columns} ouiaId={ouiaId} hasResizableColumns={hasResizableColumns} /> }
|
|
162
|
+
{ bodyContent }
|
|
163
|
+
</Table>
|
|
164
|
+
</InnerScrollContainer>
|
|
165
|
+
</OuterScrollContainer>
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
return (
|
|
169
|
+
<Table ref={tableRef} aria-label="Data table" ouiaId={ouiaId} isExpandable={isExpandable} hasAnimations {...props}>
|
|
170
|
+
{ activeHeadState || <DataViewTableHead columns={columns} ouiaId={ouiaId} hasResizableColumns={hasResizableColumns} /> }
|
|
171
|
+
{ bodyContent }
|
|
172
|
+
</Table>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
84
175
|
};
|
|
85
176
|
|
|
86
177
|
export default DataViewTableBasic;
|
|
@@ -4,7 +4,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
4
4
|
<div>
|
|
5
5
|
<table
|
|
6
6
|
aria-label="Repositories table"
|
|
7
|
-
class="pf-v6-c-table pf-m-grid-md"
|
|
7
|
+
class="pf-v6-c-table pf-m-grid-md pf-m-animate-expand"
|
|
8
8
|
data-ouia-component-id="TableExample"
|
|
9
9
|
data-ouia-component-type="PF6/Table"
|
|
10
10
|
data-ouia-safe="true"
|
|
@@ -67,7 +67,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
67
67
|
role="rowgroup"
|
|
68
68
|
>
|
|
69
69
|
<tr
|
|
70
|
-
class="pf-v6-c-table__tr"
|
|
70
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
71
71
|
data-ouia-component-id="TableExample-tr-0"
|
|
72
72
|
data-ouia-component-type="PF6/TableRow"
|
|
73
73
|
data-ouia-safe="true"
|
|
@@ -109,7 +109,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
109
109
|
</td>
|
|
110
110
|
</tr>
|
|
111
111
|
<tr
|
|
112
|
-
class="pf-v6-c-table__tr"
|
|
112
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
113
113
|
data-ouia-component-id="TableExample-tr-1"
|
|
114
114
|
data-ouia-component-type="PF6/TableRow"
|
|
115
115
|
data-ouia-safe="true"
|
|
@@ -151,7 +151,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
151
151
|
</td>
|
|
152
152
|
</tr>
|
|
153
153
|
<tr
|
|
154
|
-
class="pf-v6-c-table__tr"
|
|
154
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
155
155
|
data-ouia-component-id="TableExample-tr-2"
|
|
156
156
|
data-ouia-component-type="PF6/TableRow"
|
|
157
157
|
data-ouia-safe="true"
|
|
@@ -193,7 +193,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
193
193
|
</td>
|
|
194
194
|
</tr>
|
|
195
195
|
<tr
|
|
196
|
-
class="pf-v6-c-table__tr"
|
|
196
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
197
197
|
data-ouia-component-id="TableExample-tr-3"
|
|
198
198
|
data-ouia-component-type="PF6/TableRow"
|
|
199
199
|
data-ouia-safe="true"
|
|
@@ -235,7 +235,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
235
235
|
</td>
|
|
236
236
|
</tr>
|
|
237
237
|
<tr
|
|
238
|
-
class="pf-v6-c-table__tr"
|
|
238
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
239
239
|
data-ouia-component-id="TableExample-tr-4"
|
|
240
240
|
data-ouia-component-type="PF6/TableRow"
|
|
241
241
|
data-ouia-safe="true"
|
|
@@ -277,7 +277,7 @@ exports[`DataViewTable component should render correctly 1`] = `
|
|
|
277
277
|
</td>
|
|
278
278
|
</tr>
|
|
279
279
|
<tr
|
|
280
|
-
class="pf-v6-c-table__tr"
|
|
280
|
+
class="pf-v6-c-table__tr pf-v6-c-table__control-row"
|
|
281
281
|
data-ouia-component-id="TableExample-tr-5"
|
|
282
282
|
data-ouia-component-type="PF6/TableRow"
|
|
283
283
|
data-ouia-safe="true"
|
|
@@ -335,7 +335,7 @@ exports[`DataViewTable component should render with a loading state 1`] = `
|
|
|
335
335
|
>
|
|
336
336
|
<table
|
|
337
337
|
aria-label="Repositories table"
|
|
338
|
-
class="pf-v6-c-table pf-m-grid-md"
|
|
338
|
+
class="pf-v6-c-table pf-m-grid-md pf-m-animate-expand"
|
|
339
339
|
data-ouia-component-id="TableExample"
|
|
340
340
|
data-ouia-component-type="PF6/Table"
|
|
341
341
|
data-ouia-safe="true"
|
|
@@ -412,7 +412,7 @@ exports[`DataViewTable component should render with an empty state 1`] = `
|
|
|
412
412
|
>
|
|
413
413
|
<table
|
|
414
414
|
aria-label="Repositories table"
|
|
415
|
-
class="pf-v6-c-table pf-m-grid-md"
|
|
415
|
+
class="pf-v6-c-table pf-m-grid-md pf-m-animate-expand"
|
|
416
416
|
data-ouia-component-id="TableExample"
|
|
417
417
|
data-ouia-component-type="PF6/Table"
|
|
418
418
|
data-ouia-safe="true"
|
|
@@ -489,7 +489,7 @@ exports[`DataViewTable component should render with an error state 1`] = `
|
|
|
489
489
|
>
|
|
490
490
|
<table
|
|
491
491
|
aria-label="Repositories table"
|
|
492
|
-
class="pf-v6-c-table pf-m-grid-md"
|
|
492
|
+
class="pf-v6-c-table pf-m-grid-md pf-m-animate-expand"
|
|
493
493
|
data-ouia-component-id="TableExample"
|
|
494
494
|
data-ouia-component-type="PF6/Table"
|
|
495
495
|
data-ouia-safe="true"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { render } from '@testing-library/react';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
2
3
|
import DataViewTextFilter, { DataViewTextFilterProps } from './DataViewTextFilter';
|
|
3
4
|
import DataViewToolbar from '../DataViewToolbar';
|
|
4
5
|
|
|
@@ -20,4 +21,132 @@ describe('DataViewTextFilter component', () => {
|
|
|
20
21
|
/>);
|
|
21
22
|
expect(container).toMatchSnapshot();
|
|
22
23
|
});
|
|
24
|
+
|
|
25
|
+
it('should focus the search input when "/" key is pressed and filter is visible', () => {
|
|
26
|
+
render(<DataViewToolbar
|
|
27
|
+
filters={
|
|
28
|
+
<DataViewTextFilter {...defaultProps} showToolbarItem={true} />
|
|
29
|
+
}
|
|
30
|
+
/>);
|
|
31
|
+
|
|
32
|
+
const input = document.getElementById('test-filter') as HTMLInputElement;
|
|
33
|
+
expect(input).toBeInTheDocument();
|
|
34
|
+
|
|
35
|
+
// Simulate pressing "/" key by creating and dispatching a KeyboardEvent
|
|
36
|
+
const keyEvent = new KeyboardEvent('keydown', {
|
|
37
|
+
key: '/',
|
|
38
|
+
code: 'Slash',
|
|
39
|
+
bubbles: true,
|
|
40
|
+
cancelable: true,
|
|
41
|
+
});
|
|
42
|
+
window.dispatchEvent(keyEvent);
|
|
43
|
+
|
|
44
|
+
// Check that the input has focus
|
|
45
|
+
expect(document.activeElement).toBe(input);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should not focus the search input when "/" key is pressed if filter is not visible', () => {
|
|
49
|
+
render(<DataViewToolbar
|
|
50
|
+
filters={
|
|
51
|
+
<DataViewTextFilter {...defaultProps} showToolbarItem={false} />
|
|
52
|
+
}
|
|
53
|
+
/>);
|
|
54
|
+
|
|
55
|
+
const input = document.getElementById('test-filter') as HTMLInputElement;
|
|
56
|
+
|
|
57
|
+
// Simulate pressing "/" key
|
|
58
|
+
const keyEvent = new KeyboardEvent('keydown', {
|
|
59
|
+
key: '/',
|
|
60
|
+
code: 'Slash',
|
|
61
|
+
bubbles: true,
|
|
62
|
+
cancelable: true,
|
|
63
|
+
});
|
|
64
|
+
window.dispatchEvent(keyEvent);
|
|
65
|
+
|
|
66
|
+
if (input) {
|
|
67
|
+
expect(document.activeElement).not.toBe(input);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should not focus the search input when "/" key is pressed while typing in another input', () => {
|
|
72
|
+
const { container } = render(
|
|
73
|
+
<div>
|
|
74
|
+
<input data-testid="other-input" />
|
|
75
|
+
<DataViewToolbar
|
|
76
|
+
filters={
|
|
77
|
+
<DataViewTextFilter {...defaultProps} showToolbarItem={true} />
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const otherInput = container.querySelector('[data-testid="other-input"]') as HTMLInputElement;
|
|
84
|
+
|
|
85
|
+
// Focus the other input first
|
|
86
|
+
otherInput.focus();
|
|
87
|
+
expect(document.activeElement).toBe(otherInput);
|
|
88
|
+
|
|
89
|
+
// Simulate pressing "/" key while focused on the other input
|
|
90
|
+
// The event target should be the input element
|
|
91
|
+
const keyEvent = new KeyboardEvent('keydown', {
|
|
92
|
+
key: '/',
|
|
93
|
+
code: 'Slash',
|
|
94
|
+
bubbles: true,
|
|
95
|
+
cancelable: true,
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(keyEvent, 'target', {
|
|
98
|
+
value: otherInput,
|
|
99
|
+
enumerable: true,
|
|
100
|
+
});
|
|
101
|
+
window.dispatchEvent(keyEvent);
|
|
102
|
+
|
|
103
|
+
// The search input should not be focused since we're already in an input field
|
|
104
|
+
expect(document.activeElement).toBe(otherInput);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should not focus the search input when enableShortcut is false', () => {
|
|
108
|
+
render(<DataViewToolbar
|
|
109
|
+
filters={
|
|
110
|
+
<DataViewTextFilter {...defaultProps} showToolbarItem={true} enableShortcut={false} />
|
|
111
|
+
}
|
|
112
|
+
/>);
|
|
113
|
+
|
|
114
|
+
const input = document.getElementById('test-filter') as HTMLInputElement;
|
|
115
|
+
expect(input).toBeInTheDocument();
|
|
116
|
+
|
|
117
|
+
// Simulate pressing "/" key
|
|
118
|
+
const keyEvent = new KeyboardEvent('keydown', {
|
|
119
|
+
key: '/',
|
|
120
|
+
code: 'Slash',
|
|
121
|
+
bubbles: true,
|
|
122
|
+
cancelable: true,
|
|
123
|
+
});
|
|
124
|
+
window.dispatchEvent(keyEvent);
|
|
125
|
+
|
|
126
|
+
// The input should not be focused since the shortcut is disabled
|
|
127
|
+
expect(document.activeElement).not.toBe(input);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should focus the search input when enableShortcut is true (default)', () => {
|
|
131
|
+
render(<DataViewToolbar
|
|
132
|
+
filters={
|
|
133
|
+
<DataViewTextFilter {...defaultProps} showToolbarItem={true} />
|
|
134
|
+
}
|
|
135
|
+
/>);
|
|
136
|
+
|
|
137
|
+
const input = document.getElementById('test-filter') as HTMLInputElement;
|
|
138
|
+
expect(input).toBeInTheDocument();
|
|
139
|
+
|
|
140
|
+
// Simulate pressing "/" key
|
|
141
|
+
const keyEvent = new KeyboardEvent('keydown', {
|
|
142
|
+
key: '/',
|
|
143
|
+
code: 'Slash',
|
|
144
|
+
bubbles: true,
|
|
145
|
+
cancelable: true,
|
|
146
|
+
});
|
|
147
|
+
window.dispatchEvent(keyEvent);
|
|
148
|
+
|
|
149
|
+
// The input should be focused since the shortcut is enabled by default
|
|
150
|
+
expect(document.activeElement).toBe(input);
|
|
151
|
+
});
|
|
23
152
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
1
|
+
import { FC, useEffect } from 'react';
|
|
2
2
|
import { SearchInput, SearchInputProps, ToolbarFilter, ToolbarFilterProps } from '@patternfly/react-core';
|
|
3
3
|
|
|
4
4
|
/** extends SearchInputProps */
|
|
@@ -17,6 +17,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
|
|
|
17
17
|
trimValue?: boolean;
|
|
18
18
|
/** Custom OUIA ID */
|
|
19
19
|
ouiaId?: string;
|
|
20
|
+
/** Enable keyboard shortcut (/) to focus the filter. Defaults to true. */
|
|
21
|
+
enableShortcut?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
|
|
@@ -28,27 +30,61 @@ export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
|
|
|
28
30
|
showToolbarItem,
|
|
29
31
|
trimValue = true,
|
|
30
32
|
ouiaId = 'DataViewTextFilter',
|
|
33
|
+
enableShortcut = true,
|
|
31
34
|
...props
|
|
32
|
-
}: DataViewTextFilterProps) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
35
|
+
}: DataViewTextFilterProps) => {
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!enableShortcut) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
42
|
+
// Only handle "/" key when not typing in an input, textarea, or contenteditable element
|
|
43
|
+
if (event.key === '/' && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
44
|
+
const target = event.target as HTMLElement;
|
|
45
|
+
const isInputElement = target.tagName === 'INPUT' ||
|
|
46
|
+
target.tagName === 'TEXTAREA' ||
|
|
47
|
+
target.isContentEditable;
|
|
48
|
+
|
|
49
|
+
// Only focus if the filter is visible and we're not already in an input field
|
|
50
|
+
if (showToolbarItem && !isInputElement) {
|
|
51
|
+
// Find the input element by its ID (searchInputId prop)
|
|
52
|
+
const inputElement = document.getElementById(filterId) as HTMLInputElement;
|
|
53
|
+
if (inputElement) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
inputElement.focus();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
62
|
+
return () => {
|
|
63
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
64
|
+
};
|
|
65
|
+
}, [showToolbarItem, filterId, enableShortcut]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ToolbarFilter
|
|
69
|
+
key={ouiaId}
|
|
70
|
+
data-ouia-component-id={ouiaId}
|
|
71
|
+
labels={value.length > 0 ? [ { key: title, node: value } ] : []}
|
|
72
|
+
deleteLabel={() => onChange?.(undefined, '')}
|
|
73
|
+
categoryName={title}
|
|
74
|
+
showToolbarItem={showToolbarItem}
|
|
75
|
+
>
|
|
76
|
+
<SearchInput
|
|
77
|
+
searchInputId={filterId}
|
|
78
|
+
value={value}
|
|
79
|
+
onChange={(e, inputValue) => onChange?.(e, trimValue ? inputValue.trim() : inputValue)}
|
|
80
|
+
onClear={onClear}
|
|
81
|
+
placeholder={`Filter by ${title}`}
|
|
82
|
+
aria-label={`${title ?? filterId} filter`}
|
|
83
|
+
data-ouia-component-id={`${ouiaId}-input`}
|
|
84
|
+
{...props}
|
|
85
|
+
/>
|
|
86
|
+
</ToolbarFilter>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
53
89
|
|
|
54
90
|
export default DataViewTextFilter;
|