1
1
import React from 'react' ;
2
- import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable' ;
2
+ import { DataViewTable , DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable' ;
3
3
4
4
interface Repository {
5
5
name : string ;
6
6
branches : string | null ;
7
7
prs : string | null ;
8
8
workspaces : string ;
9
9
lastCommit : string ;
10
+ children ?: Repository [ ] ;
10
11
}
11
12
12
13
const repositories : Repository [ ] = [
13
- { name : 'one' , branches : 'two ' , prs : 'three ' , workspaces : 'four ' , lastCommit : 'five ' } ,
14
- { name : 'one - 2 ' , branches : null , prs : null , workspaces : 'four - 2 ' , lastCommit : 'five - 2 ' } ,
15
- { name : 'one - 3 ' , branches : 'two - 3 ' , prs : 'three - 3 ' , workspaces : 'four - 3 ' , lastCommit : 'five - 3 ' } ,
16
- { name : 'one - 4 ' , branches : 'two - 4 ' , prs : 'null ' , workspaces : 'four - 4 ' , lastCommit : 'five - 4 ' } ,
17
- { name : 'one - 5 ' , branches : 'two - 5 ' , prs : 'three - 5 ' , workspaces : 'four - 5 ' , lastCommit : 'five - 5 ' } ,
18
- { name : 'one - 6 ' , branches : 'two - 6 ' , prs : 'three - 6 ' , workspaces : 'four - 6 ' , lastCommit : 'five - 6 ' }
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 ' }
19
20
] ;
20
21
const rows = repositories . map ( item => Object . values ( item ) ) ;
21
22
23
+ const repositoriesTree : Repository [ ] = [
24
+ {
25
+ name : 'Repository one' ,
26
+ branches : 'Branch one' ,
27
+ prs : 'Pull request one' ,
28
+ workspaces : 'Workspace one' ,
29
+ lastCommit : 'Timestamp one' ,
30
+ children : [
31
+ { name : 'Repository two' , branches : 'Branch two' , prs : 'Pull request two' , workspaces : 'Workspace two' , lastCommit : 'Timestamp two' } ,
32
+ { name : 'Repository three' , branches : 'Branch three' , prs : 'Pull request three' , workspaces : 'Workspace three' , lastCommit : 'Timestamp three' } ,
33
+ ]
34
+ } ,
35
+ {
36
+ name : 'Repository four' ,
37
+ branches : 'Branch four' ,
38
+ prs : 'Pull request four' ,
39
+ workspaces : 'Workspace four' ,
40
+ lastCommit : 'Timestamp four' ,
41
+ children : [ { name : 'Repository five' , branches : 'Branch five' , prs : 'Pull request five' , workspaces : 'Workspace five' , lastCommit : 'Timestamp five' } ]
42
+ } ,
43
+ { name : 'Repository six' , branches : 'Branch six' , prs : 'Pull request six' , workspaces : 'Workspace six' , lastCommit : 'Timestamp six' }
44
+ ] ;
45
+
46
+
47
+
48
+ const buildRows = ( repositories : Repository [ ] ) : DataViewTrTree [ ] => repositories . map ( ( repo ) => ( {
49
+ row : [ repo . name , repo . branches , repo . prs , repo . workspaces , repo . lastCommit ] ,
50
+ id : repo . name , // unique ID for each row
51
+ ...( repo . children
52
+ ? {
53
+ children : buildRows ( repo . children ) // build rows for children
54
+ }
55
+ : { } )
56
+ } ) ) ;
57
+
58
+ const treeRows = buildRows ( repositoriesTree ) ;
59
+
22
60
const columns = [ 'Repositories' , 'Branches' , 'Pull requests' , 'Workspaces' , 'Last commit' ] ;
23
61
24
62
describe ( 'DataViewTable' , ( ) => {
25
63
26
- it ( 'renders the data view table' , ( ) => {
64
+ it ( 'renders a basic data view table' , ( ) => {
27
65
const ouiaId = 'data' ;
28
66
29
67
cy . mount (
@@ -36,10 +74,49 @@ describe('DataViewTable', () => {
36
74
cy . get ( '[data-ouia-component-id="data-th-3"]' ) . contains ( 'Workspaces' ) ;
37
75
cy . get ( '[data-ouia-component-id="data-th-4"]' ) . contains ( 'Last commit' ) ;
38
76
39
- cy . get ( '[data-ouia-component-id="data-td-0-0"]' ) . contains ( 'one' ) ;
40
- cy . get ( '[data-ouia-component-id="data-td-2-1"]' ) . contains ( 'two - 3' ) ;
41
- cy . get ( '[data-ouia-component-id="data-td-3-2"]' ) . contains ( 'null' ) ;
42
- cy . get ( '[data-ouia-component-id="data-td-4-3"]' ) . contains ( 'four - 5' ) ;
43
- cy . get ( '[data-ouia-component-id="data-td-5-4"]' ) . contains ( 'five - 6' ) ;
77
+ cy . get ( '[data-ouia-component-id="data-td-0-0"]' ) . contains ( 'Repository one' ) ;
78
+ cy . get ( '[data-ouia-component-id="data-td-2-1"]' ) . contains ( 'Branch three' ) ;
79
+ cy . get ( '[data-ouia-component-id="data-td-3-2"]' ) . contains ( 'Pull request four' ) ;
80
+ cy . get ( '[data-ouia-component-id="data-td-4-3"]' ) . contains ( 'Workspace five' ) ;
81
+ cy . get ( '[data-ouia-component-id="data-td-5-4"]' ) . contains ( 'Timestamp six' ) ;
82
+ } ) ;
83
+
84
+ it ( 'renders a tree data view table' , ( ) => {
85
+ const ouiaId = 'tree' ;
86
+
87
+ cy . mount (
88
+ < DataViewTable isTreeTable aria-label = 'Repositories table' ouiaId = { ouiaId } columns = { columns } rows = { treeRows } />
89
+ ) ;
90
+
91
+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' )
92
+ . should ( 'exist' )
93
+ . find ( 'button' )
94
+ . should ( 'have.length' , 2 ) ;
95
+
96
+ cy . get ( '[data-ouia-component-id="tree-td-3-0"]' )
97
+ . should ( 'exist' )
98
+ . find ( 'button' )
99
+ . should ( 'have.length' , 2 ) ;
100
+
101
+ cy . get ( '[data-ouia-component-id="tree-td-5-0"]' )
102
+ . should ( 'exist' )
103
+ . find ( 'button' )
104
+ . should ( 'have.length' , 1 ) ;
105
+
106
+ cy . get ( '[data-ouia-component-id="tree-th-0"]' ) . contains ( 'Repositories' ) ;
107
+ cy . get ( '[data-ouia-component-id="tree-th-1"]' ) . contains ( 'Branches' ) ;
108
+ cy . get ( '[data-ouia-component-id="tree-th-2"]' ) . contains ( 'Pull requests' ) ;
109
+ cy . get ( '[data-ouia-component-id="tree-th-3"]' ) . contains ( 'Workspaces' ) ;
110
+ cy . get ( '[data-ouia-component-id="tree-th-4"]' ) . contains ( 'Last commit' ) ;
111
+
112
+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' ) . contains ( 'Repository one' ) ;
113
+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' ) . should ( 'be.visible' ) ;
114
+ cy . get ( '[data-ouia-component-id="tree-td-2-1"]' ) . contains ( 'Branch three' ) ;
115
+ cy . get ( '[data-ouia-component-id="tree-td-2-1"]' ) . should ( 'not.be.visible' ) ;
116
+ cy . get ( '[data-ouia-component-id="tree-td-3-2"]' ) . contains ( 'Pull request four' ) ;
117
+ cy . get ( '[data-ouia-component-id="tree-td-4-3"]' ) . contains ( 'Workspace five' ) ;
118
+ cy . get ( '[data-ouia-component-id="tree-td-4-3"]' ) . should ( 'not.be.visible' ) ;
119
+ cy . get ( '[data-ouia-component-id="tree-td-5-4"]' ) . contains ( 'Timestamp six' ) ;
120
+ cy . get ( '[data-ouia-component-id="tree-td-5-4"]' ) . should ( 'not.be.visible' ) ;
44
121
} ) ;
45
122
} ) ;
0 commit comments