@patternfly/react-data-view 5.1.0 → 5.1.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 +4 -0
- package/dist/cjs/DataView/DataView.js +7 -1
- 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 +13 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +49 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +27 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.js +57 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.js +36 -0
- package/dist/cjs/DataViewTableHeader/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHeader/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +120 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +75 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- 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 +17 -0
- package/dist/cjs/InternalContext/InternalContext.js +35 -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/DataViewTableHeader/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 +4 -0
- package/dist/esm/DataView/DataView.js +7 -1
- 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 +13 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +42 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +22 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.js +30 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.js +31 -0
- package/dist/esm/DataViewTableHeader/index.d.ts +2 -0
- package/dist/esm/DataViewTableHeader/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +93 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +70 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- 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 +17 -0
- package/dist/esm/InternalContext/InternalContext.js +7 -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/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +45 -3
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +47 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
- 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 +6 -5
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +15 -32
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +1 -0
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/src/DataView/DataView.tsx +14 -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 +1010 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +37 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +71 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +324 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHeader/DataViewTableHeader.test.tsx +52 -0
- package/src/DataViewTableHeader/DataViewTableHeader.tsx +53 -0
- package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +227 -0
- package/src/DataViewTableHeader/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +85 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +144 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +937 -0
- package/src/DataViewTableTree/index.ts +2 -0
- 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 +35 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataViewTableHeader component should render correctly 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<table
|
|
6
|
+
class="pf-v5-c-table pf-m-grid-md"
|
|
7
|
+
data-ouia-component-id="OUIA-Generated-Table-1"
|
|
8
|
+
data-ouia-component-type="PF5/Table"
|
|
9
|
+
data-ouia-safe="true"
|
|
10
|
+
role="grid"
|
|
11
|
+
>
|
|
12
|
+
<thead
|
|
13
|
+
class="pf-v5-c-table__thead"
|
|
14
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
15
|
+
>
|
|
16
|
+
<tr
|
|
17
|
+
class="pf-v5-c-table__tr"
|
|
18
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
19
|
+
data-ouia-component-type="PF5/TableRow"
|
|
20
|
+
data-ouia-safe="true"
|
|
21
|
+
>
|
|
22
|
+
<th
|
|
23
|
+
class="pf-v5-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-v5-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-v5-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-v5-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-v5-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[`DataViewTableHeader component should render selection column when selection is provided 1`] = `
|
|
69
|
+
<div>
|
|
70
|
+
<div
|
|
71
|
+
class="pf-v5-l-stack"
|
|
72
|
+
data-ouia-component-id="DataView-stack}"
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
class="pf-v5-l-stack__item"
|
|
76
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
77
|
+
>
|
|
78
|
+
<table
|
|
79
|
+
class="pf-v5-c-table pf-m-grid-md"
|
|
80
|
+
data-ouia-component-id="OUIA-Generated-Table-3"
|
|
81
|
+
data-ouia-component-type="PF5/Table"
|
|
82
|
+
data-ouia-safe="true"
|
|
83
|
+
role="grid"
|
|
84
|
+
>
|
|
85
|
+
<thead
|
|
86
|
+
class="pf-v5-c-table__thead"
|
|
87
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
88
|
+
>
|
|
89
|
+
<tr
|
|
90
|
+
class="pf-v5-c-table__tr"
|
|
91
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
92
|
+
data-ouia-component-type="PF5/TableRow"
|
|
93
|
+
data-ouia-safe="true"
|
|
94
|
+
>
|
|
95
|
+
<th
|
|
96
|
+
class="pf-v5-c-table__th"
|
|
97
|
+
scope="col"
|
|
98
|
+
tabindex="-1"
|
|
99
|
+
>
|
|
100
|
+
<span
|
|
101
|
+
class="pf-v5-screen-reader"
|
|
102
|
+
>
|
|
103
|
+
Data selection table header cell
|
|
104
|
+
</span>
|
|
105
|
+
</th>
|
|
106
|
+
<th
|
|
107
|
+
class="pf-v5-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-v5-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-v5-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-v5-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-v5-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[`DataViewTableHeader component should render the tree table correctly when isTreeTable is true 1`] = `
|
|
155
|
+
<div>
|
|
156
|
+
<div
|
|
157
|
+
class="pf-v5-l-stack"
|
|
158
|
+
data-ouia-component-id="DataView-stack}"
|
|
159
|
+
>
|
|
160
|
+
<div
|
|
161
|
+
class="pf-v5-l-stack__item"
|
|
162
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
163
|
+
>
|
|
164
|
+
<table
|
|
165
|
+
class="pf-v5-c-table pf-m-grid-md"
|
|
166
|
+
data-ouia-component-id="OUIA-Generated-Table-2"
|
|
167
|
+
data-ouia-component-type="PF5/Table"
|
|
168
|
+
data-ouia-safe="true"
|
|
169
|
+
role="grid"
|
|
170
|
+
>
|
|
171
|
+
<thead
|
|
172
|
+
class="pf-v5-c-table__thead"
|
|
173
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
174
|
+
>
|
|
175
|
+
<tr
|
|
176
|
+
class="pf-v5-c-table__tr"
|
|
177
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
178
|
+
data-ouia-component-type="PF5/TableRow"
|
|
179
|
+
data-ouia-safe="true"
|
|
180
|
+
>
|
|
181
|
+
<th
|
|
182
|
+
class="pf-v5-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-v5-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-v5-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-v5-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-v5-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,85 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
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 { DataViewTableHeader } from '../DataViewTableHeader';
|
|
12
|
+
import { DataViewTh, DataViewTrTree, isDataViewTdObject } from '../DataViewTable';
|
|
13
|
+
|
|
14
|
+
const getDescendants = (node: DataViewTrTree): DataViewTrTree[] => (!node.children || !node.children.length) ? [ node ] : node.children.flatMap(getDescendants);
|
|
15
|
+
|
|
16
|
+
const isNodeChecked = (node: DataViewTrTree, isSelected: (node: DataViewTrTree) => boolean) => {
|
|
17
|
+
let allSelected = true;
|
|
18
|
+
let someSelected = false;
|
|
19
|
+
|
|
20
|
+
for (const descendant of getDescendants(node)) {
|
|
21
|
+
const selected = !!isSelected?.(descendant);
|
|
22
|
+
|
|
23
|
+
someSelected ||= selected;
|
|
24
|
+
allSelected &&= selected;
|
|
25
|
+
|
|
26
|
+
if (!allSelected && someSelected) { return null }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return allSelected;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
33
|
+
/** Columns definition */
|
|
34
|
+
columns: DataViewTh[];
|
|
35
|
+
/** Current page rows */
|
|
36
|
+
rows: DataViewTrTree[];
|
|
37
|
+
/** Optional icon for the leaf rows */
|
|
38
|
+
leafIcon?: React.ReactNode;
|
|
39
|
+
/** Optional icon for the expanded parent rows */
|
|
40
|
+
expandedIcon?: React.ReactNode;
|
|
41
|
+
/** Optional icon for the collapsed parent rows */
|
|
42
|
+
collapsedIcon?: React.ReactNode;
|
|
43
|
+
/** Custom OUIA ID */
|
|
44
|
+
ouiaId?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
|
|
48
|
+
columns,
|
|
49
|
+
rows,
|
|
50
|
+
leafIcon = null,
|
|
51
|
+
expandedIcon = null,
|
|
52
|
+
collapsedIcon = null,
|
|
53
|
+
ouiaId = 'DataViewTableTree',
|
|
54
|
+
...props
|
|
55
|
+
}: DataViewTableTreeProps) => {
|
|
56
|
+
const { selection } = useInternalContext();
|
|
57
|
+
const { onSelect, isSelected, isSelectDisabled } = selection ?? {};
|
|
58
|
+
const [ expandedNodeIds, setExpandedNodeIds ] = React.useState<string[]>([]);
|
|
59
|
+
const [ expandedDetailsNodeNames, setExpandedDetailsNodeIds ] = React.useState<string[]>([]);
|
|
60
|
+
|
|
61
|
+
const nodes = useMemo(() => {
|
|
62
|
+
|
|
63
|
+
const renderRows = (
|
|
64
|
+
[ node, ...remainingNodes ]: DataViewTrTree[],
|
|
65
|
+
level = 1,
|
|
66
|
+
posinset = 1,
|
|
67
|
+
rowIndex = 0,
|
|
68
|
+
isHidden = false
|
|
69
|
+
): React.ReactNode[] => {
|
|
70
|
+
if (!node) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const isExpanded = expandedNodeIds.includes(node.id);
|
|
74
|
+
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
75
|
+
const isChecked = isSelected && isNodeChecked(node, isSelected);
|
|
76
|
+
let icon = leafIcon;
|
|
77
|
+
if (node.children) {
|
|
78
|
+
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const treeRow: TdProps['treeRow'] = {
|
|
82
|
+
onCollapse: () =>
|
|
83
|
+
setExpandedNodeIds(prevExpanded => {
|
|
84
|
+
const otherExpandedNodeIds = prevExpanded.filter(id => id !== node.id);
|
|
85
|
+
return isExpanded ? otherExpandedNodeIds : [ ...otherExpandedNodeIds, node.id ];
|
|
86
|
+
}),
|
|
87
|
+
onToggleRowDetails: () =>
|
|
88
|
+
setExpandedDetailsNodeIds(prevDetailsExpanded => {
|
|
89
|
+
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
90
|
+
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [ ...otherDetailsExpandedNodeIds, node.id ];
|
|
91
|
+
}),
|
|
92
|
+
onCheckChange: (isSelectDisabled?.(node) || !onSelect) ? undefined : (_event, isChecking) => onSelect?.(isChecking, getDescendants(node)),
|
|
93
|
+
rowIndex,
|
|
94
|
+
props: {
|
|
95
|
+
isExpanded,
|
|
96
|
+
isDetailsExpanded,
|
|
97
|
+
isHidden,
|
|
98
|
+
'aria-level': level,
|
|
99
|
+
'aria-posinset': posinset,
|
|
100
|
+
'aria-setsize': node.children?.length ?? 0,
|
|
101
|
+
isChecked,
|
|
102
|
+
ouiaId: `${ouiaId}-tree-toggle-${node.id}`,
|
|
103
|
+
checkboxId: `checkbox_id_${node.id?.toLowerCase().replace(/\s+/g, '_')}`,
|
|
104
|
+
icon,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const childRows = node.children?.length
|
|
109
|
+
? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
|
|
110
|
+
: [];
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
<TreeRowWrapper key={node.id} row={{ props: treeRow.props }}>
|
|
114
|
+
{node.row.map((cell, colIndex) => {
|
|
115
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
116
|
+
return (
|
|
117
|
+
<Td
|
|
118
|
+
key={colIndex}
|
|
119
|
+
treeRow={colIndex === 0 ? treeRow : undefined}
|
|
120
|
+
{...(cellIsObject && (cell?.props ?? {}))}
|
|
121
|
+
data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}
|
|
122
|
+
>
|
|
123
|
+
{cellIsObject ? cell.cell : cell}
|
|
124
|
+
</Td>
|
|
125
|
+
);
|
|
126
|
+
})}
|
|
127
|
+
</TreeRowWrapper>,
|
|
128
|
+
...childRows,
|
|
129
|
+
...renderRows(remainingNodes, level, posinset + 1, rowIndex + 1 + childRows.length, isHidden),
|
|
130
|
+
];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return renderRows(rows);
|
|
134
|
+
}, [ rows, expandedNodeIds, expandedDetailsNodeNames, leafIcon, expandedIcon, collapsedIcon, isSelected, onSelect, isSelectDisabled, ouiaId ]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Table isTreeTable aria-label="Data table" ouiaId={ouiaId} {...props}>
|
|
138
|
+
<DataViewTableHeader isTreeTable columns={columns} ouiaId={ouiaId} />
|
|
139
|
+
<Tbody>{nodes}</Tbody>
|
|
140
|
+
</Table>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export default DataViewTableTree;
|