@patternfly/react-data-view 5.1.1 → 5.1.3
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 +18 -14
- package/dist/cjs/DataViewTable/DataViewTable.js +3 -44
- package/dist/cjs/DataViewTable/DataViewTable.test.js +40 -10
- 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/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/InternalContext/InternalContext.test.js +4 -3
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +10 -1
- 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/esm/DataViewTable/DataViewTable.d.ts +18 -14
- package/dist/esm/DataViewTable/DataViewTable.js +3 -44
- package/dist/esm/DataViewTable/DataViewTable.test.js +40 -10
- 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/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/InternalContext/InternalContext.test.js +5 -4
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +14 -2
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +29 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +7 -7
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +6 -6
- package/src/DataViewTable/DataViewTable.test.tsx +53 -10
- package/src/DataViewTable/DataViewTable.tsx +20 -79
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +721 -31
- 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/DataViewToolbar/DataViewToolbar.tsx +4 -1
- package/src/InternalContext/InternalContext.test.tsx +8 -7
- package/src/index.ts +9 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { DataViewTableBasic } from './DataViewTableBasic';
|
|
4
|
+
|
|
5
|
+
interface Repository {
|
|
6
|
+
name: string;
|
|
7
|
+
branches: string | null;
|
|
8
|
+
prs: string | null;
|
|
9
|
+
workspaces: string;
|
|
10
|
+
lastCommit: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
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' }
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const rows = repositories.map(repo => ({
|
|
23
|
+
row: Object.values(repo),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
27
|
+
|
|
28
|
+
const ouiaId = 'TableExample';
|
|
29
|
+
|
|
30
|
+
describe('DataViewTable component', () => {
|
|
31
|
+
test('should render correctly', () => {
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<DataViewTableBasic aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
34
|
+
);
|
|
35
|
+
expect(container).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
TableProps,
|
|
5
|
+
Tbody,
|
|
6
|
+
Td,
|
|
7
|
+
Tr,
|
|
8
|
+
} from '@patternfly/react-table';
|
|
9
|
+
import { useInternalContext } from '../InternalContext';
|
|
10
|
+
import { DataViewTableHeader } from '../DataViewTableHeader';
|
|
11
|
+
import { DataViewTh, DataViewTr, isDataViewTdObject, isDataViewTrObject } from '../DataViewTable';
|
|
12
|
+
|
|
13
|
+
export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
14
|
+
/** Columns definition */
|
|
15
|
+
columns: DataViewTh[];
|
|
16
|
+
/** Current page rows */
|
|
17
|
+
rows: DataViewTr[];
|
|
18
|
+
/** Custom OUIA ID */
|
|
19
|
+
ouiaId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DataViewTableBasic: React.FC<DataViewTableBasicProps> = ({
|
|
23
|
+
columns,
|
|
24
|
+
rows,
|
|
25
|
+
ouiaId = 'DataViewTableBasic',
|
|
26
|
+
...props
|
|
27
|
+
}: DataViewTableBasicProps) => {
|
|
28
|
+
const { selection } = useInternalContext();
|
|
29
|
+
const { onSelect, isSelected, isSelectDisabled } = selection ?? {};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Table aria-label="Data table" ouiaId={ouiaId} {...props}>
|
|
33
|
+
<DataViewTableHeader columns={columns} ouiaId={ouiaId} />
|
|
34
|
+
<Tbody>
|
|
35
|
+
{rows.map((row, rowIndex) => {
|
|
36
|
+
const rowIsObject = isDataViewTrObject(row);
|
|
37
|
+
return (
|
|
38
|
+
<Tr key={rowIndex} ouiaId={`${ouiaId}-tr-${rowIndex}`} {...(rowIsObject && (row?.props ?? {}))}>
|
|
39
|
+
{onSelect && isSelected && (
|
|
40
|
+
<Td
|
|
41
|
+
key={`select-${rowIndex}`}
|
|
42
|
+
select={{
|
|
43
|
+
rowIndex,
|
|
44
|
+
onSelect: (_event, isSelecting) => {
|
|
45
|
+
onSelect?.(isSelecting, rowIsObject ? row : [ row ])
|
|
46
|
+
},
|
|
47
|
+
isSelected: isSelected?.(row) || false,
|
|
48
|
+
isDisabled: isSelectDisabled?.(row) || false,
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
{(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
53
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
54
|
+
return (
|
|
55
|
+
<Td
|
|
56
|
+
key={colIndex}
|
|
57
|
+
{...(cellIsObject && (cell?.props ?? {}))}
|
|
58
|
+
data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}
|
|
59
|
+
>
|
|
60
|
+
{cellIsObject ? cell.cell : cell}
|
|
61
|
+
</Td>
|
|
62
|
+
)
|
|
63
|
+
})}
|
|
64
|
+
</Tr>
|
|
65
|
+
)})}
|
|
66
|
+
</Tbody>
|
|
67
|
+
</Table>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default DataViewTableBasic;
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataViewTable component should render correctly 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<table
|
|
6
|
+
aria-label="Repositories table"
|
|
7
|
+
class="pf-v5-c-table pf-m-grid-md"
|
|
8
|
+
data-ouia-component-id="TableExample"
|
|
9
|
+
data-ouia-component-type="PF5/Table"
|
|
10
|
+
data-ouia-safe="true"
|
|
11
|
+
role="grid"
|
|
12
|
+
>
|
|
13
|
+
<thead
|
|
14
|
+
class="pf-v5-c-table__thead"
|
|
15
|
+
data-ouia-component-id="TableExample-thead"
|
|
16
|
+
>
|
|
17
|
+
<tr
|
|
18
|
+
class="pf-v5-c-table__tr"
|
|
19
|
+
data-ouia-component-id="TableExample-tr-head"
|
|
20
|
+
data-ouia-component-type="PF5/TableRow"
|
|
21
|
+
data-ouia-safe="true"
|
|
22
|
+
>
|
|
23
|
+
<th
|
|
24
|
+
class="pf-v5-c-table__th"
|
|
25
|
+
data-ouia-component-id="TableExample-th-0"
|
|
26
|
+
scope="col"
|
|
27
|
+
tabindex="-1"
|
|
28
|
+
>
|
|
29
|
+
Repositories
|
|
30
|
+
</th>
|
|
31
|
+
<th
|
|
32
|
+
class="pf-v5-c-table__th"
|
|
33
|
+
data-ouia-component-id="TableExample-th-1"
|
|
34
|
+
scope="col"
|
|
35
|
+
tabindex="-1"
|
|
36
|
+
>
|
|
37
|
+
Branches
|
|
38
|
+
</th>
|
|
39
|
+
<th
|
|
40
|
+
class="pf-v5-c-table__th"
|
|
41
|
+
data-ouia-component-id="TableExample-th-2"
|
|
42
|
+
scope="col"
|
|
43
|
+
tabindex="-1"
|
|
44
|
+
>
|
|
45
|
+
Pull requests
|
|
46
|
+
</th>
|
|
47
|
+
<th
|
|
48
|
+
class="pf-v5-c-table__th"
|
|
49
|
+
data-ouia-component-id="TableExample-th-3"
|
|
50
|
+
scope="col"
|
|
51
|
+
tabindex="-1"
|
|
52
|
+
>
|
|
53
|
+
Workspaces
|
|
54
|
+
</th>
|
|
55
|
+
<th
|
|
56
|
+
class="pf-v5-c-table__th"
|
|
57
|
+
data-ouia-component-id="TableExample-th-4"
|
|
58
|
+
scope="col"
|
|
59
|
+
tabindex="-1"
|
|
60
|
+
>
|
|
61
|
+
Last commit
|
|
62
|
+
</th>
|
|
63
|
+
</tr>
|
|
64
|
+
</thead>
|
|
65
|
+
<tbody
|
|
66
|
+
class="pf-v5-c-table__tbody"
|
|
67
|
+
role="rowgroup"
|
|
68
|
+
>
|
|
69
|
+
<tr
|
|
70
|
+
class="pf-v5-c-table__tr"
|
|
71
|
+
data-ouia-component-id="TableExample-tr-0"
|
|
72
|
+
data-ouia-component-type="PF5/TableRow"
|
|
73
|
+
data-ouia-safe="true"
|
|
74
|
+
>
|
|
75
|
+
<td
|
|
76
|
+
class="pf-v5-c-table__td"
|
|
77
|
+
data-ouia-component-id="TableExample-td-0-0"
|
|
78
|
+
tabindex="-1"
|
|
79
|
+
>
|
|
80
|
+
Repository one
|
|
81
|
+
</td>
|
|
82
|
+
<td
|
|
83
|
+
class="pf-v5-c-table__td"
|
|
84
|
+
data-ouia-component-id="TableExample-td-0-1"
|
|
85
|
+
tabindex="-1"
|
|
86
|
+
>
|
|
87
|
+
Branch one
|
|
88
|
+
</td>
|
|
89
|
+
<td
|
|
90
|
+
class="pf-v5-c-table__td"
|
|
91
|
+
data-ouia-component-id="TableExample-td-0-2"
|
|
92
|
+
tabindex="-1"
|
|
93
|
+
>
|
|
94
|
+
Pull request one
|
|
95
|
+
</td>
|
|
96
|
+
<td
|
|
97
|
+
class="pf-v5-c-table__td"
|
|
98
|
+
data-ouia-component-id="TableExample-td-0-3"
|
|
99
|
+
tabindex="-1"
|
|
100
|
+
>
|
|
101
|
+
Workspace one
|
|
102
|
+
</td>
|
|
103
|
+
<td
|
|
104
|
+
class="pf-v5-c-table__td"
|
|
105
|
+
data-ouia-component-id="TableExample-td-0-4"
|
|
106
|
+
tabindex="-1"
|
|
107
|
+
>
|
|
108
|
+
Timestamp one
|
|
109
|
+
</td>
|
|
110
|
+
</tr>
|
|
111
|
+
<tr
|
|
112
|
+
class="pf-v5-c-table__tr"
|
|
113
|
+
data-ouia-component-id="TableExample-tr-1"
|
|
114
|
+
data-ouia-component-type="PF5/TableRow"
|
|
115
|
+
data-ouia-safe="true"
|
|
116
|
+
>
|
|
117
|
+
<td
|
|
118
|
+
class="pf-v5-c-table__td"
|
|
119
|
+
data-ouia-component-id="TableExample-td-1-0"
|
|
120
|
+
tabindex="-1"
|
|
121
|
+
>
|
|
122
|
+
Repository two
|
|
123
|
+
</td>
|
|
124
|
+
<td
|
|
125
|
+
class="pf-v5-c-table__td"
|
|
126
|
+
data-ouia-component-id="TableExample-td-1-1"
|
|
127
|
+
tabindex="-1"
|
|
128
|
+
>
|
|
129
|
+
Branch two
|
|
130
|
+
</td>
|
|
131
|
+
<td
|
|
132
|
+
class="pf-v5-c-table__td"
|
|
133
|
+
data-ouia-component-id="TableExample-td-1-2"
|
|
134
|
+
tabindex="-1"
|
|
135
|
+
>
|
|
136
|
+
Pull request two
|
|
137
|
+
</td>
|
|
138
|
+
<td
|
|
139
|
+
class="pf-v5-c-table__td"
|
|
140
|
+
data-ouia-component-id="TableExample-td-1-3"
|
|
141
|
+
tabindex="-1"
|
|
142
|
+
>
|
|
143
|
+
Workspace two
|
|
144
|
+
</td>
|
|
145
|
+
<td
|
|
146
|
+
class="pf-v5-c-table__td"
|
|
147
|
+
data-ouia-component-id="TableExample-td-1-4"
|
|
148
|
+
tabindex="-1"
|
|
149
|
+
>
|
|
150
|
+
Timestamp two
|
|
151
|
+
</td>
|
|
152
|
+
</tr>
|
|
153
|
+
<tr
|
|
154
|
+
class="pf-v5-c-table__tr"
|
|
155
|
+
data-ouia-component-id="TableExample-tr-2"
|
|
156
|
+
data-ouia-component-type="PF5/TableRow"
|
|
157
|
+
data-ouia-safe="true"
|
|
158
|
+
>
|
|
159
|
+
<td
|
|
160
|
+
class="pf-v5-c-table__td"
|
|
161
|
+
data-ouia-component-id="TableExample-td-2-0"
|
|
162
|
+
tabindex="-1"
|
|
163
|
+
>
|
|
164
|
+
Repository three
|
|
165
|
+
</td>
|
|
166
|
+
<td
|
|
167
|
+
class="pf-v5-c-table__td"
|
|
168
|
+
data-ouia-component-id="TableExample-td-2-1"
|
|
169
|
+
tabindex="-1"
|
|
170
|
+
>
|
|
171
|
+
Branch three
|
|
172
|
+
</td>
|
|
173
|
+
<td
|
|
174
|
+
class="pf-v5-c-table__td"
|
|
175
|
+
data-ouia-component-id="TableExample-td-2-2"
|
|
176
|
+
tabindex="-1"
|
|
177
|
+
>
|
|
178
|
+
Pull request three
|
|
179
|
+
</td>
|
|
180
|
+
<td
|
|
181
|
+
class="pf-v5-c-table__td"
|
|
182
|
+
data-ouia-component-id="TableExample-td-2-3"
|
|
183
|
+
tabindex="-1"
|
|
184
|
+
>
|
|
185
|
+
Workspace three
|
|
186
|
+
</td>
|
|
187
|
+
<td
|
|
188
|
+
class="pf-v5-c-table__td"
|
|
189
|
+
data-ouia-component-id="TableExample-td-2-4"
|
|
190
|
+
tabindex="-1"
|
|
191
|
+
>
|
|
192
|
+
Timestamp three
|
|
193
|
+
</td>
|
|
194
|
+
</tr>
|
|
195
|
+
<tr
|
|
196
|
+
class="pf-v5-c-table__tr"
|
|
197
|
+
data-ouia-component-id="TableExample-tr-3"
|
|
198
|
+
data-ouia-component-type="PF5/TableRow"
|
|
199
|
+
data-ouia-safe="true"
|
|
200
|
+
>
|
|
201
|
+
<td
|
|
202
|
+
class="pf-v5-c-table__td"
|
|
203
|
+
data-ouia-component-id="TableExample-td-3-0"
|
|
204
|
+
tabindex="-1"
|
|
205
|
+
>
|
|
206
|
+
Repository four
|
|
207
|
+
</td>
|
|
208
|
+
<td
|
|
209
|
+
class="pf-v5-c-table__td"
|
|
210
|
+
data-ouia-component-id="TableExample-td-3-1"
|
|
211
|
+
tabindex="-1"
|
|
212
|
+
>
|
|
213
|
+
Branch four
|
|
214
|
+
</td>
|
|
215
|
+
<td
|
|
216
|
+
class="pf-v5-c-table__td"
|
|
217
|
+
data-ouia-component-id="TableExample-td-3-2"
|
|
218
|
+
tabindex="-1"
|
|
219
|
+
>
|
|
220
|
+
Pull request four
|
|
221
|
+
</td>
|
|
222
|
+
<td
|
|
223
|
+
class="pf-v5-c-table__td"
|
|
224
|
+
data-ouia-component-id="TableExample-td-3-3"
|
|
225
|
+
tabindex="-1"
|
|
226
|
+
>
|
|
227
|
+
Workspace four
|
|
228
|
+
</td>
|
|
229
|
+
<td
|
|
230
|
+
class="pf-v5-c-table__td"
|
|
231
|
+
data-ouia-component-id="TableExample-td-3-4"
|
|
232
|
+
tabindex="-1"
|
|
233
|
+
>
|
|
234
|
+
Timestamp four
|
|
235
|
+
</td>
|
|
236
|
+
</tr>
|
|
237
|
+
<tr
|
|
238
|
+
class="pf-v5-c-table__tr"
|
|
239
|
+
data-ouia-component-id="TableExample-tr-4"
|
|
240
|
+
data-ouia-component-type="PF5/TableRow"
|
|
241
|
+
data-ouia-safe="true"
|
|
242
|
+
>
|
|
243
|
+
<td
|
|
244
|
+
class="pf-v5-c-table__td"
|
|
245
|
+
data-ouia-component-id="TableExample-td-4-0"
|
|
246
|
+
tabindex="-1"
|
|
247
|
+
>
|
|
248
|
+
Repository five
|
|
249
|
+
</td>
|
|
250
|
+
<td
|
|
251
|
+
class="pf-v5-c-table__td"
|
|
252
|
+
data-ouia-component-id="TableExample-td-4-1"
|
|
253
|
+
tabindex="-1"
|
|
254
|
+
>
|
|
255
|
+
Branch five
|
|
256
|
+
</td>
|
|
257
|
+
<td
|
|
258
|
+
class="pf-v5-c-table__td"
|
|
259
|
+
data-ouia-component-id="TableExample-td-4-2"
|
|
260
|
+
tabindex="-1"
|
|
261
|
+
>
|
|
262
|
+
Pull request five
|
|
263
|
+
</td>
|
|
264
|
+
<td
|
|
265
|
+
class="pf-v5-c-table__td"
|
|
266
|
+
data-ouia-component-id="TableExample-td-4-3"
|
|
267
|
+
tabindex="-1"
|
|
268
|
+
>
|
|
269
|
+
Workspace five
|
|
270
|
+
</td>
|
|
271
|
+
<td
|
|
272
|
+
class="pf-v5-c-table__td"
|
|
273
|
+
data-ouia-component-id="TableExample-td-4-4"
|
|
274
|
+
tabindex="-1"
|
|
275
|
+
>
|
|
276
|
+
Timestamp five
|
|
277
|
+
</td>
|
|
278
|
+
</tr>
|
|
279
|
+
<tr
|
|
280
|
+
class="pf-v5-c-table__tr"
|
|
281
|
+
data-ouia-component-id="TableExample-tr-5"
|
|
282
|
+
data-ouia-component-type="PF5/TableRow"
|
|
283
|
+
data-ouia-safe="true"
|
|
284
|
+
>
|
|
285
|
+
<td
|
|
286
|
+
class="pf-v5-c-table__td"
|
|
287
|
+
data-ouia-component-id="TableExample-td-5-0"
|
|
288
|
+
tabindex="-1"
|
|
289
|
+
>
|
|
290
|
+
Repository six
|
|
291
|
+
</td>
|
|
292
|
+
<td
|
|
293
|
+
class="pf-v5-c-table__td"
|
|
294
|
+
data-ouia-component-id="TableExample-td-5-1"
|
|
295
|
+
tabindex="-1"
|
|
296
|
+
>
|
|
297
|
+
Branch six
|
|
298
|
+
</td>
|
|
299
|
+
<td
|
|
300
|
+
class="pf-v5-c-table__td"
|
|
301
|
+
data-ouia-component-id="TableExample-td-5-2"
|
|
302
|
+
tabindex="-1"
|
|
303
|
+
>
|
|
304
|
+
Pull request six
|
|
305
|
+
</td>
|
|
306
|
+
<td
|
|
307
|
+
class="pf-v5-c-table__td"
|
|
308
|
+
data-ouia-component-id="TableExample-td-5-3"
|
|
309
|
+
tabindex="-1"
|
|
310
|
+
>
|
|
311
|
+
Workspace six
|
|
312
|
+
</td>
|
|
313
|
+
<td
|
|
314
|
+
class="pf-v5-c-table__td"
|
|
315
|
+
data-ouia-component-id="TableExample-td-5-4"
|
|
316
|
+
tabindex="-1"
|
|
317
|
+
>
|
|
318
|
+
Timestamp six
|
|
319
|
+
</td>
|
|
320
|
+
</tr>
|
|
321
|
+
</tbody>
|
|
322
|
+
</table>
|
|
323
|
+
</div>
|
|
324
|
+
`;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Table } from '@patternfly/react-table';
|
|
4
|
+
import { DataViewTableHeader } from './DataViewTableHeader';
|
|
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('DataViewTableHeader 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
|
+
<DataViewTableHeader 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
|
+
<DataViewTableHeader 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
|
+
<DataViewTableHeader columns={columns} ouiaId={ouiaId} />
|
|
44
|
+
</Table>
|
|
45
|
+
</DataView>
|
|
46
|
+
);
|
|
47
|
+
expect(container).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
@@ -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 DataViewTableHeaderProps 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 DataViewTableHeader: React.FC<DataViewTableHeaderProps> = ({
|
|
21
|
+
isTreeTable = false,
|
|
22
|
+
columns,
|
|
23
|
+
ouiaId = 'DataViewTableHeader',
|
|
24
|
+
...props
|
|
25
|
+
}: DataViewTableHeaderProps) => {
|
|
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 header 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 DataViewTableHeader;
|