@patternfly/react-table 4.54.0 → 4.56.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.54.0",
3
+ "version": "4.56.0",
4
4
  "description": "This library provides a set of React table components for use with the PatternFly 4",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,10 +31,10 @@
31
31
  "clean": "rimraf dist"
32
32
  },
33
33
  "dependencies": {
34
- "@patternfly/react-core": "^4.185.0",
35
- "@patternfly/react-icons": "^4.36.0",
36
- "@patternfly/react-styles": "^4.35.0",
37
- "@patternfly/react-tokens": "^4.37.0",
34
+ "@patternfly/react-core": "^4.187.0",
35
+ "@patternfly/react-icons": "^4.38.0",
36
+ "@patternfly/react-styles": "^4.37.0",
37
+ "@patternfly/react-tokens": "^4.39.0",
38
38
  "lodash": "^4.17.19",
39
39
  "tslib": "^2.0.0"
40
40
  },
@@ -46,5 +46,5 @@
46
46
  "react": "^16.8.0 || ^17.0.0",
47
47
  "react-dom": "^16.8.0 || ^17.0.0"
48
48
  },
49
- "gitHead": "ef19da8ae08dfd6581f25f116e43687cc9f0ce67"
49
+ "gitHead": "b30c7c3f64a443451b47ca5ab30a8a13de521bdd"
50
50
  }
@@ -344,3 +344,8 @@ The second `Tr` represents the second level of sub columns. The `Th` in this row
344
344
 
345
345
  ```ts file="ComposableTableNestedExpandable.tsx"
346
346
  ```
347
+
348
+ ### Composable: Expandable with nested table
349
+
350
+ ```ts file="ComposableTableNestedTableExpandable.tsx"
351
+ ```
@@ -0,0 +1,189 @@
1
+ /* eslint-disable no-console */
2
+ import React from 'react';
3
+ import {
4
+ TableComposable,
5
+ Thead,
6
+ Tr,
7
+ Th,
8
+ Tbody,
9
+ Td,
10
+ ExpandableRowContent,
11
+ ActionsColumn,
12
+ IAction
13
+ } from '@patternfly/react-table';
14
+
15
+ interface Repository {
16
+ name: string;
17
+ branches: string;
18
+ prs: string;
19
+ nestedComponent?: React.ReactNode;
20
+ link?: React.ReactNode;
21
+ noPadding?: boolean;
22
+ }
23
+ interface NestedRepository {
24
+ name: string;
25
+ branches: string | null;
26
+ prs: string | null;
27
+ workspaces: string | null;
28
+ lastCommit: string | null;
29
+ }
30
+
31
+ const NestedReposTable: React.FunctionComponent = () => {
32
+ // In real usage, this data would come from some external source like an API via props.
33
+ const prs: NestedRepository[] = [
34
+ { name: 'Repository 1', branches: '25', prs: '25', workspaces: '5', lastCommit: '2 days ago' },
35
+ { name: 'Repository 2', branches: '25', prs: '25', workspaces: '5', lastCommit: '2 days ago' },
36
+ { name: 'Repository 3', branches: '25', prs: '25', workspaces: '5', lastCommit: '2 days ago' },
37
+ { name: 'Repository 4', branches: '25', prs: '25', workspaces: '5', lastCommit: '2 days ago' }
38
+ ];
39
+
40
+ const columnNames = {
41
+ name: 'Repositories',
42
+ branches: 'Branches',
43
+ prs: 'Pull requests',
44
+ workspaces: 'Workspaces',
45
+ lastCommit: 'Last commit'
46
+ };
47
+
48
+ return (
49
+ <TableComposable aria-label="Simple table" variant="compact">
50
+ <Thead>
51
+ <Tr>
52
+ <Th>{columnNames.name}</Th>
53
+ <Th>{columnNames.branches}</Th>
54
+ <Th>{columnNames.prs}</Th>
55
+ <Th>{columnNames.workspaces}</Th>
56
+ <Th>{columnNames.lastCommit}</Th>
57
+ </Tr>
58
+ </Thead>
59
+ <Tbody>
60
+ {prs.map(repo => (
61
+ <Tr key={repo.name}>
62
+ <Td dataLabel={columnNames.name}>{repo.name}</Td>
63
+ <Td dataLabel={columnNames.branches}>{repo.branches}</Td>
64
+ <Td dataLabel={columnNames.prs}>{repo.prs}</Td>
65
+ <Td dataLabel={columnNames.workspaces}>{repo.workspaces}</Td>
66
+ <Td dataLabel={columnNames.lastCommit}>{repo.lastCommit}</Td>
67
+ </Tr>
68
+ ))}
69
+ </Tbody>
70
+ </TableComposable>
71
+ );
72
+ };
73
+
74
+ export const ComposableTableExpandable: React.FunctionComponent = () => {
75
+ // In real usage, this data would come from some external source like an API via props.
76
+ const repositories: Repository[] = [
77
+ { name: 'Node 1', branches: '10', prs: '2', nestedComponent: <NestedReposTable />, link: <a>Link 1</a> },
78
+ { name: 'Node 2', branches: '3', prs: '4', link: <a>Link 2</a> },
79
+ {
80
+ name: 'Node 3',
81
+ branches: '11',
82
+ prs: '7',
83
+ nestedComponent: (
84
+ <p>
85
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
86
+ magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
87
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
88
+ pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
89
+ est laborum.
90
+ </p>
91
+ ),
92
+ link: <a>Link 3</a>
93
+ },
94
+ {
95
+ name: 'Node 4',
96
+ branches: '11',
97
+ prs: '7',
98
+ nestedComponent: 'Expandable row content has no padding.',
99
+ link: <a>Link 4</a>,
100
+ noPadding: true
101
+ }
102
+ ];
103
+
104
+ const columnNames = {
105
+ name: 'Repositories',
106
+ branches: 'Branches',
107
+ prs: 'Pull requests',
108
+ link: 'Link',
109
+ action: 'Action'
110
+ };
111
+ // In this example, expanded rows are tracked by the repo names from each row. This could be any unique identifier.
112
+ // This is to prevent state from being based on row order index in case we later add sorting.
113
+ // Note that this behavior is very similar to selection state.
114
+ const initialExpandedRepoNames = repositories.filter(repo => !!repo.nestedComponent).map(repo => repo.name); // Default to all expanded
115
+ const [expandedRepoNames, setExpandedRepoNames] = React.useState<string[]>(initialExpandedRepoNames);
116
+ const setRepoExpanded = (repo: Repository, isExpanding = true) =>
117
+ setExpandedRepoNames(prevExpanded => {
118
+ const otherExpandedRepoNames = prevExpanded.filter(r => r !== repo.name);
119
+ return isExpanding ? [...otherExpandedRepoNames, repo.name] : otherExpandedRepoNames;
120
+ });
121
+ const isRepoExpanded = (repo: Repository) => expandedRepoNames.includes(repo.name);
122
+
123
+ const defaultActions = (repo: Repository): IAction[] => [
124
+ {
125
+ title: 'Some action',
126
+ onClick: () => console.log(`clicked on Some action, on row ${repo.name}`)
127
+ },
128
+ {
129
+ title: <a href="https://www.patternfly.org">Link action</a>
130
+ },
131
+ {
132
+ isSeparator: true
133
+ },
134
+ {
135
+ title: 'Third action',
136
+ onClick: () => console.log(`clicked on Third action, on row ${repo.name}`)
137
+ }
138
+ ];
139
+
140
+ return (
141
+ <TableComposable aria-label="Simple table">
142
+ <Thead>
143
+ <Tr>
144
+ <Td />
145
+ <Th>{columnNames.name}</Th>
146
+ <Th>{columnNames.branches}</Th>
147
+ <Th>{columnNames.prs}</Th>
148
+ <Th>{columnNames.link}</Th>
149
+ <Th>{columnNames.action}</Th>
150
+ </Tr>
151
+ </Thead>
152
+ {repositories.map((repo, rowIndex) => (
153
+ <Tbody key={repo.name} isExpanded={isRepoExpanded(repo)}>
154
+ <Tr>
155
+ <Td
156
+ expand={
157
+ repo.nestedComponent
158
+ ? {
159
+ rowIndex,
160
+ isExpanded: isRepoExpanded(repo),
161
+ onToggle: () => setRepoExpanded(repo, !isRepoExpanded(repo))
162
+ }
163
+ : undefined
164
+ }
165
+ />
166
+ <Td dataLabel={columnNames.name}>{repo.name}</Td>
167
+ <Td dataLabel={columnNames.branches}>{repo.branches}</Td>
168
+ <Td dataLabel={columnNames.prs}>{repo.prs}</Td>
169
+ <Td dataLabel={columnNames.link}>{repo.link}</Td>
170
+ <Td dataLabel={columnNames.action}>
171
+ <ActionsColumn items={defaultActions(repo)} />
172
+ </Td>
173
+ </Tr>
174
+ {repo.nestedComponent ? (
175
+ <Tr isExpanded={isRepoExpanded(repo)}>
176
+ <Td
177
+ noPadding={repo.noPadding}
178
+ dataLabel={`${columnNames.name} expended`}
179
+ colSpan={Object.keys(columnNames).length + 1}
180
+ >
181
+ <ExpandableRowContent>{repo.nestedComponent}</ExpandableRowContent>
182
+ </Td>
183
+ </Tr>
184
+ ) : null}
185
+ </Tbody>
186
+ ))}
187
+ </TableComposable>
188
+ );
189
+ };