@patternfly/react-data-view 6.1.0-prerelease.1 → 7.0.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/DataView/DataView.d.ts +12 -0
- package/dist/cjs/DataView/DataView.js +14 -3
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
- package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
- package/dist/cjs/DataViewEventsContext/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
- package/dist/cjs/DataViewTable/index.d.ts +2 -0
- package/dist/cjs/DataViewTable/index.js +23 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHead/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +132 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/Hooks/pagination.d.ts +13 -1
- package/dist/cjs/Hooks/pagination.js +36 -4
- package/dist/cjs/Hooks/pagination.test.js +1 -1
- package/dist/cjs/Hooks/selection.d.ts +3 -3
- package/dist/cjs/Hooks/selection.js +4 -6
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/InternalContext/InternalContext.d.ts +25 -0
- package/dist/cjs/InternalContext/InternalContext.js +40 -0
- package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
- package/dist/cjs/InternalContext/index.d.ts +2 -0
- package/dist/cjs/InternalContext/index.js +23 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.js +20 -2
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewTable/package.json +1 -0
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHead/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +12 -0
- package/dist/esm/DataView/DataView.js +13 -2
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
- package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
- package/dist/esm/DataViewEventsContext/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/esm/DataViewTable/DataViewTable.js +8 -0
- package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
- package/dist/esm/DataViewTable/index.d.ts +2 -0
- package/dist/esm/DataViewTable/index.js +2 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +105 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/Hooks/pagination.d.ts +13 -1
- package/dist/esm/Hooks/pagination.js +36 -4
- package/dist/esm/Hooks/pagination.test.js +1 -1
- package/dist/esm/Hooks/selection.d.ts +3 -3
- package/dist/esm/Hooks/selection.js +4 -6
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/InternalContext/InternalContext.d.ts +25 -0
- package/dist/esm/InternalContext/InternalContext.js +12 -0
- package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/esm/InternalContext/InternalContext.test.js +51 -0
- package/dist/esm/InternalContext/index.d.ts +2 -0
- package/dist/esm/InternalContext/index.js +2 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +80 -5
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +4 -4
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +32 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +108 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +14 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +28 -37
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/patternfly-docs/pages/index.js +1 -1
- package/src/DataView/DataView.tsx +25 -3
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +37 -0
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +82 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +53 -0
- package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +164 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +8 -8
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +68 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +6 -7
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +51 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Table } from '@patternfly/react-table';
|
|
4
|
+
import { DataViewTableHead } from './DataViewTableHead';
|
|
5
|
+
import { DataViewSelection } from '../InternalContext';
|
|
6
|
+
import { DataView } from '../DataView';
|
|
7
|
+
|
|
8
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
9
|
+
|
|
10
|
+
const ouiaId = 'HeaderExample';
|
|
11
|
+
|
|
12
|
+
describe('DataViewTableHead component', () => {
|
|
13
|
+
const mockSelection: DataViewSelection = {
|
|
14
|
+
onSelect: jest.fn(),
|
|
15
|
+
isSelected: jest.fn(),
|
|
16
|
+
isSelectDisabled: jest.fn(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('should render correctly', () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<Table>
|
|
22
|
+
<DataViewTableHead columns={columns} ouiaId={ouiaId} />
|
|
23
|
+
</Table>
|
|
24
|
+
);
|
|
25
|
+
expect(container).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('should render the tree table correctly when isTreeTable is true', () => {
|
|
29
|
+
const { container } = render(
|
|
30
|
+
<DataView selection={mockSelection}>
|
|
31
|
+
<Table>
|
|
32
|
+
<DataViewTableHead isTreeTable columns={columns} ouiaId={ouiaId} />
|
|
33
|
+
</Table>
|
|
34
|
+
</DataView>
|
|
35
|
+
);
|
|
36
|
+
expect(container).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should render selection column when selection is provided', () => {
|
|
40
|
+
const { container } = render(
|
|
41
|
+
<DataView selection={mockSelection}>
|
|
42
|
+
<Table>
|
|
43
|
+
<DataViewTableHead columns={columns} ouiaId={ouiaId} />
|
|
44
|
+
</Table>
|
|
45
|
+
</DataView>
|
|
46
|
+
);
|
|
47
|
+
expect(container).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Th,
|
|
4
|
+
Thead,
|
|
5
|
+
TheadProps,
|
|
6
|
+
Tr
|
|
7
|
+
} from '@patternfly/react-table';
|
|
8
|
+
import { useInternalContext } from '../InternalContext';
|
|
9
|
+
import { DataViewTh, isDataViewThObject } from '../DataViewTable';
|
|
10
|
+
|
|
11
|
+
export interface DataViewTableHeadProps extends TheadProps {
|
|
12
|
+
/** Indicates whether table is a tree */
|
|
13
|
+
isTreeTable?: boolean;
|
|
14
|
+
/** Columns definition */
|
|
15
|
+
columns: DataViewTh[];
|
|
16
|
+
/** Custom OUIA ID */
|
|
17
|
+
ouiaId?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const DataViewTableHead: React.FC<DataViewTableHeadProps> = ({
|
|
21
|
+
isTreeTable = false,
|
|
22
|
+
columns,
|
|
23
|
+
ouiaId = 'DataViewTableHead',
|
|
24
|
+
...props
|
|
25
|
+
}: DataViewTableHeadProps) => {
|
|
26
|
+
const { selection } = useInternalContext();
|
|
27
|
+
const { onSelect, isSelected } = selection ?? {};
|
|
28
|
+
|
|
29
|
+
const cells = useMemo(() => [
|
|
30
|
+
onSelect && isSelected && !isTreeTable ? (
|
|
31
|
+
<Th key="row-select" screenReaderText='Data selection table head cell' />
|
|
32
|
+
) : null,
|
|
33
|
+
...columns.map((column, index) => (
|
|
34
|
+
<Th
|
|
35
|
+
key={index}
|
|
36
|
+
{...(isDataViewThObject(column) && (column?.props ?? {}))}
|
|
37
|
+
data-ouia-component-id={`${ouiaId}-th-${index}`}
|
|
38
|
+
>
|
|
39
|
+
{isDataViewThObject(column) ? column.cell : column}
|
|
40
|
+
</Th>
|
|
41
|
+
)
|
|
42
|
+
) ], [ columns, ouiaId, onSelect, isSelected, isTreeTable ]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Thead data-ouia-component-id={`${ouiaId}-thead`} {...props}>
|
|
46
|
+
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
47
|
+
{cells}
|
|
48
|
+
</Tr>
|
|
49
|
+
</Thead>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default DataViewTableHead;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataViewTableHead component should render correctly 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<table
|
|
6
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
7
|
+
data-ouia-component-id="OUIA-Generated-Table-1"
|
|
8
|
+
data-ouia-component-type="PF6/Table"
|
|
9
|
+
data-ouia-safe="true"
|
|
10
|
+
role="grid"
|
|
11
|
+
>
|
|
12
|
+
<thead
|
|
13
|
+
class="pf-v6-c-table__thead"
|
|
14
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
15
|
+
>
|
|
16
|
+
<tr
|
|
17
|
+
class="pf-v6-c-table__tr"
|
|
18
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
19
|
+
data-ouia-component-type="PF6/TableRow"
|
|
20
|
+
data-ouia-safe="true"
|
|
21
|
+
>
|
|
22
|
+
<th
|
|
23
|
+
class="pf-v6-c-table__th"
|
|
24
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
25
|
+
scope="col"
|
|
26
|
+
tabindex="-1"
|
|
27
|
+
>
|
|
28
|
+
Repositories
|
|
29
|
+
</th>
|
|
30
|
+
<th
|
|
31
|
+
class="pf-v6-c-table__th"
|
|
32
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
33
|
+
scope="col"
|
|
34
|
+
tabindex="-1"
|
|
35
|
+
>
|
|
36
|
+
Branches
|
|
37
|
+
</th>
|
|
38
|
+
<th
|
|
39
|
+
class="pf-v6-c-table__th"
|
|
40
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
41
|
+
scope="col"
|
|
42
|
+
tabindex="-1"
|
|
43
|
+
>
|
|
44
|
+
Pull requests
|
|
45
|
+
</th>
|
|
46
|
+
<th
|
|
47
|
+
class="pf-v6-c-table__th"
|
|
48
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
49
|
+
scope="col"
|
|
50
|
+
tabindex="-1"
|
|
51
|
+
>
|
|
52
|
+
Workspaces
|
|
53
|
+
</th>
|
|
54
|
+
<th
|
|
55
|
+
class="pf-v6-c-table__th"
|
|
56
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
57
|
+
scope="col"
|
|
58
|
+
tabindex="-1"
|
|
59
|
+
>
|
|
60
|
+
Last commit
|
|
61
|
+
</th>
|
|
62
|
+
</tr>
|
|
63
|
+
</thead>
|
|
64
|
+
</table>
|
|
65
|
+
</div>
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
exports[`DataViewTableHead component should render selection column when selection is provided 1`] = `
|
|
69
|
+
<div>
|
|
70
|
+
<div
|
|
71
|
+
class="pf-v6-l-stack"
|
|
72
|
+
data-ouia-component-id="DataView-stack"
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
class="pf-v6-l-stack__item"
|
|
76
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
77
|
+
>
|
|
78
|
+
<table
|
|
79
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
80
|
+
data-ouia-component-id="OUIA-Generated-Table-3"
|
|
81
|
+
data-ouia-component-type="PF6/Table"
|
|
82
|
+
data-ouia-safe="true"
|
|
83
|
+
role="grid"
|
|
84
|
+
>
|
|
85
|
+
<thead
|
|
86
|
+
class="pf-v6-c-table__thead"
|
|
87
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
88
|
+
>
|
|
89
|
+
<tr
|
|
90
|
+
class="pf-v6-c-table__tr"
|
|
91
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
92
|
+
data-ouia-component-type="PF6/TableRow"
|
|
93
|
+
data-ouia-safe="true"
|
|
94
|
+
>
|
|
95
|
+
<th
|
|
96
|
+
class="pf-v6-c-table__th"
|
|
97
|
+
scope="col"
|
|
98
|
+
tabindex="-1"
|
|
99
|
+
>
|
|
100
|
+
<span
|
|
101
|
+
class="pf-v6-u-screen-reader"
|
|
102
|
+
>
|
|
103
|
+
Data selection table head cell
|
|
104
|
+
</span>
|
|
105
|
+
</th>
|
|
106
|
+
<th
|
|
107
|
+
class="pf-v6-c-table__th"
|
|
108
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
109
|
+
scope="col"
|
|
110
|
+
tabindex="-1"
|
|
111
|
+
>
|
|
112
|
+
Repositories
|
|
113
|
+
</th>
|
|
114
|
+
<th
|
|
115
|
+
class="pf-v6-c-table__th"
|
|
116
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
117
|
+
scope="col"
|
|
118
|
+
tabindex="-1"
|
|
119
|
+
>
|
|
120
|
+
Branches
|
|
121
|
+
</th>
|
|
122
|
+
<th
|
|
123
|
+
class="pf-v6-c-table__th"
|
|
124
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
125
|
+
scope="col"
|
|
126
|
+
tabindex="-1"
|
|
127
|
+
>
|
|
128
|
+
Pull requests
|
|
129
|
+
</th>
|
|
130
|
+
<th
|
|
131
|
+
class="pf-v6-c-table__th"
|
|
132
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
133
|
+
scope="col"
|
|
134
|
+
tabindex="-1"
|
|
135
|
+
>
|
|
136
|
+
Workspaces
|
|
137
|
+
</th>
|
|
138
|
+
<th
|
|
139
|
+
class="pf-v6-c-table__th"
|
|
140
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
141
|
+
scope="col"
|
|
142
|
+
tabindex="-1"
|
|
143
|
+
>
|
|
144
|
+
Last commit
|
|
145
|
+
</th>
|
|
146
|
+
</tr>
|
|
147
|
+
</thead>
|
|
148
|
+
</table>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
`;
|
|
153
|
+
|
|
154
|
+
exports[`DataViewTableHead component should render the tree table correctly when isTreeTable is true 1`] = `
|
|
155
|
+
<div>
|
|
156
|
+
<div
|
|
157
|
+
class="pf-v6-l-stack"
|
|
158
|
+
data-ouia-component-id="DataView-stack"
|
|
159
|
+
>
|
|
160
|
+
<div
|
|
161
|
+
class="pf-v6-l-stack__item"
|
|
162
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
163
|
+
>
|
|
164
|
+
<table
|
|
165
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
166
|
+
data-ouia-component-id="OUIA-Generated-Table-2"
|
|
167
|
+
data-ouia-component-type="PF6/Table"
|
|
168
|
+
data-ouia-safe="true"
|
|
169
|
+
role="grid"
|
|
170
|
+
>
|
|
171
|
+
<thead
|
|
172
|
+
class="pf-v6-c-table__thead"
|
|
173
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
174
|
+
>
|
|
175
|
+
<tr
|
|
176
|
+
class="pf-v6-c-table__tr"
|
|
177
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
178
|
+
data-ouia-component-type="PF6/TableRow"
|
|
179
|
+
data-ouia-safe="true"
|
|
180
|
+
>
|
|
181
|
+
<th
|
|
182
|
+
class="pf-v6-c-table__th"
|
|
183
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
184
|
+
scope="col"
|
|
185
|
+
tabindex="-1"
|
|
186
|
+
>
|
|
187
|
+
Repositories
|
|
188
|
+
</th>
|
|
189
|
+
<th
|
|
190
|
+
class="pf-v6-c-table__th"
|
|
191
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
192
|
+
scope="col"
|
|
193
|
+
tabindex="-1"
|
|
194
|
+
>
|
|
195
|
+
Branches
|
|
196
|
+
</th>
|
|
197
|
+
<th
|
|
198
|
+
class="pf-v6-c-table__th"
|
|
199
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
200
|
+
scope="col"
|
|
201
|
+
tabindex="-1"
|
|
202
|
+
>
|
|
203
|
+
Pull requests
|
|
204
|
+
</th>
|
|
205
|
+
<th
|
|
206
|
+
class="pf-v6-c-table__th"
|
|
207
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
208
|
+
scope="col"
|
|
209
|
+
tabindex="-1"
|
|
210
|
+
>
|
|
211
|
+
Workspaces
|
|
212
|
+
</th>
|
|
213
|
+
<th
|
|
214
|
+
class="pf-v6-c-table__th"
|
|
215
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
216
|
+
scope="col"
|
|
217
|
+
tabindex="-1"
|
|
218
|
+
>
|
|
219
|
+
Last commit
|
|
220
|
+
</th>
|
|
221
|
+
</tr>
|
|
222
|
+
</thead>
|
|
223
|
+
</table>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
`;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
|
|
4
|
+
import { DataView } from '../DataView';
|
|
5
|
+
import { DataViewTable } from '../DataViewTable';
|
|
6
|
+
import { DataViewSelection } from '../InternalContext';
|
|
7
|
+
|
|
8
|
+
const repositories = [
|
|
9
|
+
{
|
|
10
|
+
name: 'Repository one',
|
|
11
|
+
branches: 'Branch one',
|
|
12
|
+
prs: 'Pull request one',
|
|
13
|
+
workspaces: 'Workspace one',
|
|
14
|
+
lastCommit: 'Timestamp one',
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
name: 'Repository two',
|
|
18
|
+
branches: 'Branch two',
|
|
19
|
+
prs: 'Pull request two',
|
|
20
|
+
workspaces: 'Workspace two',
|
|
21
|
+
lastCommit: 'Timestamp two',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'Repository three',
|
|
25
|
+
branches: 'Branch three',
|
|
26
|
+
prs: 'Pull request three',
|
|
27
|
+
workspaces: 'Workspace three',
|
|
28
|
+
lastCommit: 'Timestamp three',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Repository four',
|
|
34
|
+
branches: 'Branch four',
|
|
35
|
+
prs: 'Pull request four',
|
|
36
|
+
workspaces: 'Workspace four',
|
|
37
|
+
lastCommit: 'Timestamp four',
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
name: 'Repository five',
|
|
41
|
+
branches: 'Branch five',
|
|
42
|
+
prs: 'Pull request five',
|
|
43
|
+
workspaces: 'Workspace five',
|
|
44
|
+
lastCommit: 'Timestamp five',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Repository six',
|
|
50
|
+
branches: 'Branch six',
|
|
51
|
+
prs: 'Pull request six',
|
|
52
|
+
workspaces: 'Workspace six',
|
|
53
|
+
lastCommit: 'Timestamp six',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// Build rows for DataViewTable
|
|
58
|
+
const buildRows = (repositories) => repositories.map((repo) => ({
|
|
59
|
+
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
|
|
60
|
+
id: repo.name,
|
|
61
|
+
...(repo.children ? { children: buildRows(repo.children) } : {}),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const rows = buildRows(repositories);
|
|
65
|
+
|
|
66
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
67
|
+
|
|
68
|
+
const ouiaId = 'TreeTableExample';
|
|
69
|
+
|
|
70
|
+
describe('DataViewTableTree component', () => {
|
|
71
|
+
const mockSelection: DataViewSelection = {
|
|
72
|
+
onSelect: jest.fn(),
|
|
73
|
+
isSelected: jest.fn(),
|
|
74
|
+
isSelectDisabled: jest.fn(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
test('should render the tree table correctly', () => {
|
|
78
|
+
const { container } = render(
|
|
79
|
+
<DataView selection={mockSelection}>
|
|
80
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
|
|
81
|
+
</DataView>
|
|
82
|
+
);
|
|
83
|
+
expect(container).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('should render tree table with an empty state', () => {
|
|
87
|
+
const { container } = render(
|
|
88
|
+
<DataView activeState="empty">
|
|
89
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ empty: "No data found" }} rows={[]} />
|
|
90
|
+
|
|
91
|
+
</DataView>
|
|
92
|
+
);
|
|
93
|
+
expect(container).toMatchSnapshot();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('should render tree table with an error state', () => {
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<DataView activeState="error">
|
|
99
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ error: "Some error" }} rows={[]} />
|
|
100
|
+
</DataView>
|
|
101
|
+
);
|
|
102
|
+
expect(container).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('should render tree table with a loading state', () => {
|
|
106
|
+
const { container } = render(
|
|
107
|
+
<DataView activeState="loading">
|
|
108
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ loading: "Data is loading" }} rows={[]} />
|
|
109
|
+
</DataView>
|
|
110
|
+
);
|
|
111
|
+
expect(container).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
TableProps,
|
|
5
|
+
Tbody,
|
|
6
|
+
Td,
|
|
7
|
+
TdProps,
|
|
8
|
+
TreeRowWrapper,
|
|
9
|
+
} from '@patternfly/react-table';
|
|
10
|
+
import { useInternalContext } from '../InternalContext';
|
|
11
|
+
import { DataViewTableHead } from '../DataViewTableHead';
|
|
12
|
+
import { DataViewTh, DataViewTrTree, isDataViewTdObject } from '../DataViewTable';
|
|
13
|
+
import { DataViewState } from '../DataView/DataView';
|
|
14
|
+
|
|
15
|
+
const getDescendants = (node: DataViewTrTree): DataViewTrTree[] => (!node.children || !node.children.length) ? [ node ] : node.children.flatMap(getDescendants);
|
|
16
|
+
|
|
17
|
+
const isNodeChecked = (node: DataViewTrTree, isSelected: (node: DataViewTrTree) => boolean) => {
|
|
18
|
+
let allSelected = true;
|
|
19
|
+
let someSelected = false;
|
|
20
|
+
|
|
21
|
+
for (const descendant of getDescendants(node)) {
|
|
22
|
+
const selected = !!isSelected?.(descendant);
|
|
23
|
+
|
|
24
|
+
someSelected ||= selected;
|
|
25
|
+
allSelected &&= selected;
|
|
26
|
+
|
|
27
|
+
if (!allSelected && someSelected) { return null }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return allSelected;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
34
|
+
/** Columns definition */
|
|
35
|
+
columns: DataViewTh[];
|
|
36
|
+
/** Current page rows */
|
|
37
|
+
rows: DataViewTrTree[];
|
|
38
|
+
/** Table head states to be displayed when active */
|
|
39
|
+
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>
|
|
40
|
+
/** Table body states to be displayed when active */
|
|
41
|
+
bodyStates?: Partial<Record<DataViewState | string, React.ReactNode>>
|
|
42
|
+
/** Optional icon for the leaf rows */
|
|
43
|
+
leafIcon?: React.ReactNode;
|
|
44
|
+
/** Optional icon for the expanded parent rows */
|
|
45
|
+
expandedIcon?: React.ReactNode;
|
|
46
|
+
/** Optional icon for the collapsed parent rows */
|
|
47
|
+
collapsedIcon?: React.ReactNode;
|
|
48
|
+
/** Custom OUIA ID */
|
|
49
|
+
ouiaId?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
|
|
53
|
+
columns,
|
|
54
|
+
rows,
|
|
55
|
+
headStates,
|
|
56
|
+
bodyStates,
|
|
57
|
+
leafIcon = null,
|
|
58
|
+
expandedIcon = null,
|
|
59
|
+
collapsedIcon = null,
|
|
60
|
+
ouiaId = 'DataViewTableTree',
|
|
61
|
+
...props
|
|
62
|
+
}: DataViewTableTreeProps) => {
|
|
63
|
+
const { selection, activeState } = useInternalContext();
|
|
64
|
+
const { onSelect, isSelected, isSelectDisabled } = selection ?? {};
|
|
65
|
+
const [ expandedNodeIds, setExpandedNodeIds ] = React.useState<string[]>([]);
|
|
66
|
+
const [ expandedDetailsNodeNames, setExpandedDetailsNodeIds ] = React.useState<string[]>([]);
|
|
67
|
+
|
|
68
|
+
const activeHeadState = useMemo(() => activeState ? headStates?.[activeState] : undefined, [ activeState, headStates ]);
|
|
69
|
+
const activeBodyState = useMemo(() => activeState ? bodyStates?.[activeState] : undefined, [ activeState, bodyStates ]);
|
|
70
|
+
|
|
71
|
+
const nodes = useMemo(() => {
|
|
72
|
+
|
|
73
|
+
const renderRows = (
|
|
74
|
+
[ node, ...remainingNodes ]: DataViewTrTree[],
|
|
75
|
+
level = 1,
|
|
76
|
+
posinset = 1,
|
|
77
|
+
rowIndex = 0,
|
|
78
|
+
isHidden = false
|
|
79
|
+
): React.ReactNode[] => {
|
|
80
|
+
if (!node) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const isExpanded = expandedNodeIds.includes(node.id);
|
|
84
|
+
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
85
|
+
const isChecked = isSelected && isNodeChecked(node, isSelected);
|
|
86
|
+
let icon = leafIcon;
|
|
87
|
+
if (node.children) {
|
|
88
|
+
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const treeRow: TdProps['treeRow'] = {
|
|
92
|
+
onCollapse: () =>
|
|
93
|
+
setExpandedNodeIds(prevExpanded => {
|
|
94
|
+
const otherExpandedNodeIds = prevExpanded.filter(id => id !== node.id);
|
|
95
|
+
return isExpanded ? otherExpandedNodeIds : [ ...otherExpandedNodeIds, node.id ];
|
|
96
|
+
}),
|
|
97
|
+
onToggleRowDetails: () =>
|
|
98
|
+
setExpandedDetailsNodeIds(prevDetailsExpanded => {
|
|
99
|
+
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
100
|
+
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [ ...otherDetailsExpandedNodeIds, node.id ];
|
|
101
|
+
}),
|
|
102
|
+
onCheckChange: (isSelectDisabled?.(node) || !onSelect) ? undefined : (_event, isChecking) => onSelect?.(isChecking, getDescendants(node)),
|
|
103
|
+
rowIndex,
|
|
104
|
+
props: {
|
|
105
|
+
isExpanded,
|
|
106
|
+
isDetailsExpanded,
|
|
107
|
+
isHidden,
|
|
108
|
+
'aria-level': level,
|
|
109
|
+
'aria-posinset': posinset,
|
|
110
|
+
'aria-setsize': node.children?.length ?? 0,
|
|
111
|
+
isChecked,
|
|
112
|
+
checkboxId: `checkbox_id_${node.id?.toLowerCase().replace(/\s+/g, '_')}`,
|
|
113
|
+
icon,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const childRows = node.children?.length
|
|
118
|
+
? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
|
|
119
|
+
: [];
|
|
120
|
+
|
|
121
|
+
return [
|
|
122
|
+
<TreeRowWrapper key={node.id} row={{ props: treeRow.props }} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
123
|
+
{node.row.map((cell, colIndex) => {
|
|
124
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
125
|
+
return (
|
|
126
|
+
<Td
|
|
127
|
+
key={colIndex}
|
|
128
|
+
treeRow={colIndex === 0 ? treeRow : undefined}
|
|
129
|
+
{...(cellIsObject && (cell?.props ?? {}))}
|
|
130
|
+
data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}
|
|
131
|
+
>
|
|
132
|
+
{cellIsObject ? cell.cell : cell}
|
|
133
|
+
</Td>
|
|
134
|
+
);
|
|
135
|
+
})}
|
|
136
|
+
</TreeRowWrapper>,
|
|
137
|
+
...childRows,
|
|
138
|
+
...renderRows(remainingNodes, level, posinset + 1, rowIndex + 1 + childRows.length, isHidden),
|
|
139
|
+
];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return renderRows(rows);
|
|
143
|
+
}, [
|
|
144
|
+
rows,
|
|
145
|
+
expandedNodeIds,
|
|
146
|
+
expandedDetailsNodeNames,
|
|
147
|
+
leafIcon,
|
|
148
|
+
expandedIcon,
|
|
149
|
+
collapsedIcon,
|
|
150
|
+
isSelected,
|
|
151
|
+
onSelect,
|
|
152
|
+
isSelectDisabled,
|
|
153
|
+
ouiaId
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Table isTreeTable aria-label="Data table" ouiaId={ouiaId} {...props}>
|
|
158
|
+
{activeHeadState || <DataViewTableHead isTreeTable columns={columns} ouiaId={ouiaId} />}
|
|
159
|
+
{activeBodyState || <Tbody>{nodes}</Tbody>}
|
|
160
|
+
</Table>
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default DataViewTableTree;
|