forked from patternfly/react-data-view
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataViewTableTreeExample.tsx
More file actions
72 lines (63 loc) · 2.5 KB
/
DataViewTableTreeExample.tsx
File metadata and controls
72 lines (63 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { FunctionComponent } from 'react';
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
import { DataViewTable, DataViewTh, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
interface Repository {
name: string;
branches: string | null;
prs: string | null;
workspaces: string;
lastCommit: string;
children?: Repository[];
}
const repositories: Repository[] = [
{
name: 'Repository one',
branches: 'Branch one',
prs: 'Pull request one',
workspaces: 'Workspace one',
lastCommit: 'Timestamp one',
children: [
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
]
},
{
name: 'Repository four',
branches: 'Branch four',
prs: 'Pull request four',
workspaces: 'Workspace four',
lastCommit: 'Timestamp four',
children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
},
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
];
const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
id: repo.name, // unique ID for each row
...(repo.children
? {
children: buildRows(repo.children) // build rows for children
}
: {})
}));
const rows: DataViewTrTree[] = buildRows(repositories);
const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
const ouiaId = 'TreeTableExample';
export const BasicExample: FunctionComponent = () => {
const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
return (
<DataView selection={selection}>
<DataViewTable
isTreeTable
ouiaId={ouiaId}
columns={columns}
rows={rows}
leafIcon={<LeafIcon/>}
expandedIcon={<FolderOpenIcon aria-hidden />}
collapsedIcon={<FolderIcon aria-hidden />}
/>
</DataView>
);
}