@patternfly/react-table 4.65.0 → 4.67.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/CHANGELOG.md +38 -0
- package/dist/esm/components/Table/CollapseColumn.d.ts +1 -0
- package/dist/esm/components/Table/CollapseColumn.d.ts.map +1 -1
- package/dist/esm/components/Table/CollapseColumn.js +1 -1
- package/dist/esm/components/Table/CollapseColumn.js.map +1 -1
- package/dist/esm/components/Table/Table.d.ts +6 -1
- package/dist/esm/components/Table/Table.d.ts.map +1 -1
- package/dist/esm/components/Table/Table.js +12 -1
- package/dist/esm/components/Table/Table.js.map +1 -1
- package/dist/esm/components/Table/TableTypes.d.ts +2 -0
- package/dist/esm/components/Table/TableTypes.d.ts.map +1 -1
- package/dist/esm/components/Table/base/provider.d.ts +2 -2
- package/dist/esm/components/Table/base/types.d.ts +10 -2
- package/dist/esm/components/Table/base/types.d.ts.map +1 -1
- package/dist/esm/components/Table/base/types.js.map +1 -1
- package/dist/esm/components/Table/utils/decorators/collapsible.d.ts.map +1 -1
- package/dist/esm/components/Table/utils/decorators/collapsible.js +16 -5
- package/dist/esm/components/Table/utils/decorators/collapsible.js.map +1 -1
- package/dist/esm/components/Table/utils/headerUtils.d.ts +5 -1
- package/dist/esm/components/Table/utils/headerUtils.d.ts.map +1 -1
- package/dist/esm/components/Table/utils/headerUtils.js +2 -2
- package/dist/esm/components/Table/utils/headerUtils.js.map +1 -1
- package/dist/esm/components/TableComposable/Td.d.ts +1 -1
- package/dist/esm/components/TableComposable/Th.d.ts +4 -2
- package/dist/esm/components/TableComposable/Th.d.ts.map +1 -1
- package/dist/esm/components/TableComposable/Th.js +15 -3
- package/dist/esm/components/TableComposable/Th.js.map +1 -1
- package/dist/js/components/Table/CollapseColumn.d.ts +1 -0
- package/dist/js/components/Table/CollapseColumn.d.ts.map +1 -1
- package/dist/js/components/Table/CollapseColumn.js +1 -1
- package/dist/js/components/Table/CollapseColumn.js.map +1 -1
- package/dist/js/components/Table/Table.d.ts +6 -1
- package/dist/js/components/Table/Table.d.ts.map +1 -1
- package/dist/js/components/Table/Table.js +12 -1
- package/dist/js/components/Table/Table.js.map +1 -1
- package/dist/js/components/Table/TableTypes.d.ts +2 -0
- package/dist/js/components/Table/TableTypes.d.ts.map +1 -1
- package/dist/js/components/Table/base/provider.d.ts +2 -2
- package/dist/js/components/Table/base/types.d.ts +10 -2
- package/dist/js/components/Table/base/types.d.ts.map +1 -1
- package/dist/js/components/Table/base/types.js.map +1 -1
- package/dist/js/components/Table/utils/decorators/collapsible.d.ts.map +1 -1
- package/dist/js/components/Table/utils/decorators/collapsible.js +16 -5
- package/dist/js/components/Table/utils/decorators/collapsible.js.map +1 -1
- package/dist/js/components/Table/utils/headerUtils.d.ts +5 -1
- package/dist/js/components/Table/utils/headerUtils.d.ts.map +1 -1
- package/dist/js/components/Table/utils/headerUtils.js +2 -2
- package/dist/js/components/Table/utils/headerUtils.js.map +1 -1
- package/dist/js/components/TableComposable/Td.d.ts +1 -1
- package/dist/js/components/TableComposable/Th.d.ts +4 -2
- package/dist/js/components/TableComposable/Th.d.ts.map +1 -1
- package/dist/js/components/TableComposable/Th.js +15 -3
- package/dist/js/components/TableComposable/Th.js.map +1 -1
- package/dist/umd/react-table.css +194 -10
- package/dist/umd/react-table.js +88 -55
- package/dist/umd/react-table.min.css +194 -10
- package/dist/umd/react-table.min.js +4 -4
- package/package.json +6 -6
- package/src/components/Table/CollapseColumn.tsx +2 -1
- package/src/components/Table/Table.tsx +19 -1
- package/src/components/Table/TableTypes.tsx +2 -0
- package/src/components/Table/__snapshots__/Table.test.tsx.snap +5115 -23
- package/src/components/Table/base/types.tsx +9 -0
- package/src/components/Table/utils/decorators/collapsible.tsx +28 -7
- package/src/components/Table/utils/headerUtils.test.tsx +1 -1
- package/src/components/Table/utils/headerUtils.tsx +8 -2
- package/src/components/TableComposable/Th.tsx +18 -3
- package/src/components/TableComposable/examples/ComposableTable.md +1 -0
- package/src/components/TableComposable/examples/ComposableTableExpandable.tsx +1 -0
- package/src/demos/Table.md +12 -208
- package/src/demos/table-demos/ExpandCollapseAll.jsx +139 -0
|
@@ -163,6 +163,15 @@ export interface ThSelectType {
|
|
|
163
163
|
isHeaderSelectDisabled?: boolean;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
export interface ThExpandType {
|
|
167
|
+
/** On toggling the expansion */
|
|
168
|
+
onToggle?: OnCollapse;
|
|
169
|
+
/** Whether all are expanded */
|
|
170
|
+
areAllExpanded: boolean;
|
|
171
|
+
/** Alternative aria label */
|
|
172
|
+
collapseAllAriaLabel: '';
|
|
173
|
+
}
|
|
174
|
+
|
|
166
175
|
// Rows Types
|
|
167
176
|
export type RowsType = RowType[] | [][];
|
|
168
177
|
export type RowKeyType = Function | string;
|
|
@@ -10,7 +10,13 @@ export const collapsible: IFormatter = (
|
|
|
10
10
|
{ rowIndex, columnIndex, rowData, column, property }: IExtra
|
|
11
11
|
) => {
|
|
12
12
|
const {
|
|
13
|
-
extraParams: {
|
|
13
|
+
extraParams: {
|
|
14
|
+
onCollapse,
|
|
15
|
+
rowLabeledBy = 'simple-node',
|
|
16
|
+
expandId = 'expand-toggle',
|
|
17
|
+
allRowsExpanded,
|
|
18
|
+
collapseAllAriaLabel
|
|
19
|
+
}
|
|
14
20
|
} = column;
|
|
15
21
|
const extraData = {
|
|
16
22
|
rowIndex,
|
|
@@ -19,23 +25,38 @@ export const collapsible: IFormatter = (
|
|
|
19
25
|
property
|
|
20
26
|
};
|
|
21
27
|
|
|
28
|
+
const rowId = rowIndex !== undefined ? rowIndex : -1;
|
|
29
|
+
|
|
30
|
+
const customProps = {
|
|
31
|
+
...(rowId !== -1
|
|
32
|
+
? {
|
|
33
|
+
isOpen: rowData?.isOpen,
|
|
34
|
+
'aria-labelledby': `${rowLabeledBy}${rowId} ${expandId}${rowId}`
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
isOpen: allRowsExpanded,
|
|
38
|
+
'aria-label': collapseAllAriaLabel || 'Expand all rows'
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
|
|
22
42
|
/**
|
|
23
43
|
* @param {React.MouseEvent} event - Mouse event
|
|
24
44
|
*/
|
|
25
45
|
function onToggle(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
|
|
46
|
+
const open = rowData ? !rowData.isOpen : !allRowsExpanded;
|
|
26
47
|
// tslint:disable-next-line:no-unused-expression
|
|
27
|
-
onCollapse && onCollapse(event, rowIndex,
|
|
48
|
+
onCollapse && onCollapse(event, rowIndex, open, rowData, extraData);
|
|
28
49
|
}
|
|
29
50
|
|
|
30
51
|
return {
|
|
31
|
-
className: rowData
|
|
32
|
-
isVisible: !rowData
|
|
52
|
+
className: (rowData?.isOpen !== undefined || rowId === -1) && css(styles.tableToggle),
|
|
53
|
+
isVisible: !rowData?.fullWidth,
|
|
33
54
|
children: (
|
|
34
55
|
<CollapseColumn
|
|
35
|
-
aria-labelledby={`${rowLabeledBy}${
|
|
56
|
+
aria-labelledby={`${rowLabeledBy}${rowId} ${expandId}${rowId}`}
|
|
36
57
|
onToggle={onToggle}
|
|
37
|
-
id={expandId +
|
|
38
|
-
|
|
58
|
+
id={expandId + rowId}
|
|
59
|
+
{...customProps}
|
|
39
60
|
>
|
|
40
61
|
{value}
|
|
41
62
|
</CollapseColumn>
|
|
@@ -9,7 +9,7 @@ describe('headerUtils', () => {
|
|
|
9
9
|
expect(collapsibleTransfroms[0].cell.formatters[0].name).toBe('defaultTitle');
|
|
10
10
|
expect(collapsibleTransfroms[0].cell.transforms).toHaveLength(3);
|
|
11
11
|
expect(collapsibleTransfroms[0].extraParams.onCollapse).toBeDefined();
|
|
12
|
-
expect(collapsibleTransfroms[0].header.transforms).toHaveLength(
|
|
12
|
+
expect(collapsibleTransfroms[0].header.transforms).toHaveLength(2);
|
|
13
13
|
expect(collapsibleTransfroms[1].cell.transforms).toHaveLength(3);
|
|
14
14
|
expect(collapsibleTransfroms[1].cell.transforms.find(transform => transform.name === 'parentId')).toBeDefined();
|
|
15
15
|
expect(
|
|
@@ -97,6 +97,7 @@ const mapHeader = (column: ICell, extra: any, key: number, ...props: any) => {
|
|
|
97
97
|
} else if (typeof title === 'string') {
|
|
98
98
|
dataLabel = title;
|
|
99
99
|
}
|
|
100
|
+
|
|
100
101
|
return {
|
|
101
102
|
property:
|
|
102
103
|
(typeof title === 'string' &&
|
|
@@ -207,6 +208,11 @@ const actionsTransforms = ({
|
|
|
207
208
|
: [])
|
|
208
209
|
];
|
|
209
210
|
|
|
211
|
+
export interface ICollapseTranform {
|
|
212
|
+
onCollapse: OnCollapse;
|
|
213
|
+
canCollapseAll: boolean;
|
|
214
|
+
}
|
|
215
|
+
|
|
210
216
|
/**
|
|
211
217
|
* Function to define collapsible in first column.
|
|
212
218
|
*
|
|
@@ -214,12 +220,12 @@ const actionsTransforms = ({
|
|
|
214
220
|
* @param {*} extraObject with onCollapse callback.
|
|
215
221
|
* @returns {*} object with empty title, tranforms - Array, cellTransforms - Array.
|
|
216
222
|
*/
|
|
217
|
-
const collapsibleTransforms = (header: (ICell | string)[], { onCollapse }:
|
|
223
|
+
const collapsibleTransforms = (header: (ICell | string)[], { onCollapse, canCollapseAll }: ICollapseTranform) => [
|
|
218
224
|
...(onCollapse
|
|
219
225
|
? [
|
|
220
226
|
{
|
|
221
227
|
title: '',
|
|
222
|
-
transforms: [
|
|
228
|
+
transforms: (canCollapseAll && [collapsible]) || null,
|
|
223
229
|
cellTransforms: [collapsible, expandedRow(header.length)]
|
|
224
230
|
}
|
|
225
231
|
]
|
|
@@ -5,9 +5,10 @@ import scrollStyles from '@patternfly/react-styles/css/components/Table/table-sc
|
|
|
5
5
|
import { info } from '../Table/utils/decorators/info';
|
|
6
6
|
import { sortable, sortableFavorites } from '../Table/utils/decorators/sortable';
|
|
7
7
|
import { selectable } from '../Table/utils/decorators/selectable';
|
|
8
|
+
import { collapsible } from '../Table/utils/decorators/collapsible';
|
|
8
9
|
import { cellWidth } from './../Table/utils/decorators/cellWidth';
|
|
9
10
|
import { Visibility, classNames } from './../Table/utils/decorators/classNames';
|
|
10
|
-
import { ThInfoType, ThSelectType, ThSortType, formatterValueType } from '../Table/base/types';
|
|
11
|
+
import { ThInfoType, ThSelectType, ThExpandType, ThSortType, formatterValueType } from '../Table/base/types';
|
|
11
12
|
import { mergeProps } from '../Table/base/merge-props';
|
|
12
13
|
import { IVisibility } from '../Table/utils/decorators/classNames';
|
|
13
14
|
import { Tooltip } from '@patternfly/react-core/dist/esm/components/Tooltip/Tooltip';
|
|
@@ -24,6 +25,8 @@ export interface ThProps
|
|
|
24
25
|
dataLabel?: string;
|
|
25
26
|
/** Renders a checkbox select so that all row checkboxes can be selected/deselected */
|
|
26
27
|
select?: ThSelectType;
|
|
28
|
+
/** Renders a chevron so that all row chevrons can be expanded/collapsed */
|
|
29
|
+
expand?: ThExpandType;
|
|
27
30
|
/** Formats the header so that its column will be sortable */
|
|
28
31
|
sort?: ThSortType;
|
|
29
32
|
/**
|
|
@@ -61,6 +64,7 @@ const ThBase: React.FunctionComponent<ThProps> = ({
|
|
|
61
64
|
sort = null,
|
|
62
65
|
modifier,
|
|
63
66
|
select = null,
|
|
67
|
+
expand: collapse = null,
|
|
64
68
|
tooltip = '',
|
|
65
69
|
onMouseEnter: onMouseEnterProp = () => {},
|
|
66
70
|
width,
|
|
@@ -115,18 +119,29 @@ const ThBase: React.FunctionComponent<ThProps> = ({
|
|
|
115
119
|
}
|
|
116
120
|
})
|
|
117
121
|
: null;
|
|
122
|
+
const collapseParams = collapse
|
|
123
|
+
? collapsible(children as IFormatterValueType, {
|
|
124
|
+
column: {
|
|
125
|
+
extraParams: {
|
|
126
|
+
onCollapse: collapse?.onToggle,
|
|
127
|
+
allRowsExpanded: !collapse.areAllExpanded,
|
|
128
|
+
collapseAllAriaLabel: ''
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
: null;
|
|
118
133
|
const widthParams = width ? cellWidth(width)() : null;
|
|
119
134
|
const visibilityParams = visibility
|
|
120
135
|
? classNames(...visibility.map((vis: keyof IVisibility) => Visibility[vis]))()
|
|
121
136
|
: null;
|
|
122
|
-
let transformedChildren = sortParams?.children || selectParams?.children || children;
|
|
137
|
+
let transformedChildren = sortParams?.children || selectParams?.children || collapseParams?.children || children;
|
|
123
138
|
// info can wrap other transformedChildren
|
|
124
139
|
let infoParams = null;
|
|
125
140
|
if (infoProps) {
|
|
126
141
|
infoParams = info(infoProps)(transformedChildren as formatterValueType);
|
|
127
142
|
transformedChildren = infoParams.children;
|
|
128
143
|
}
|
|
129
|
-
const merged = mergeProps(sortParams, selectParams, widthParams, visibilityParams, infoParams);
|
|
144
|
+
const merged = mergeProps(sortParams, selectParams, collapseParams, widthParams, visibilityParams, infoParams);
|
|
130
145
|
const {
|
|
131
146
|
// ignore the merged children since we transform them ourselves so we can wrap it with info
|
|
132
147
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -16,6 +16,7 @@ interface Repository {
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
20
|
export const ComposableTableExpandable: React.FunctionComponent = () => {
|
|
20
21
|
// In real usage, this data would come from some external source like an API via props.
|
|
21
22
|
const repositories: Repository[] = [
|
package/src/demos/Table.md
CHANGED
|
@@ -264,194 +264,7 @@ class BulkSelectTableDemo extends React.Component {
|
|
|
264
264
|
|
|
265
265
|
### Expand/collapse all
|
|
266
266
|
|
|
267
|
-
```js
|
|
268
|
-
import React from 'react';
|
|
269
|
-
import { Table, TableHeader, TableBody, expandable } from '@patternfly/react-table';
|
|
270
|
-
import {
|
|
271
|
-
Button,
|
|
272
|
-
Checkbox,
|
|
273
|
-
Toolbar,
|
|
274
|
-
ToolbarGroup,
|
|
275
|
-
ToolbarItem,
|
|
276
|
-
ToolbarExpandIconWrapper,
|
|
277
|
-
ToolbarContent
|
|
278
|
-
} from '@patternfly/react-core';
|
|
279
|
-
import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon';
|
|
280
|
-
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
|
|
281
|
-
|
|
282
|
-
class ExpandCollapseAllTableDemo extends React.Component {
|
|
283
|
-
constructor(props) {
|
|
284
|
-
super(props);
|
|
285
|
-
this.state = {
|
|
286
|
-
isChecked: false,
|
|
287
|
-
selectedRows: 0,
|
|
288
|
-
expandedRows: 0,
|
|
289
|
-
expandCollapseToggle: 'expand',
|
|
290
|
-
columns: [
|
|
291
|
-
{
|
|
292
|
-
title: 'Header cell',
|
|
293
|
-
cellFormatters: [expandable]
|
|
294
|
-
},
|
|
295
|
-
'Branches',
|
|
296
|
-
'Pull requests',
|
|
297
|
-
'Workspaces',
|
|
298
|
-
'Last Commit'
|
|
299
|
-
],
|
|
300
|
-
rows: [
|
|
301
|
-
{
|
|
302
|
-
cells: ['one', 'two', 'three', 'four', 'five']
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
isOpen: false,
|
|
306
|
-
cells: ['parent - 1', 'two', 'three', 'four', 'five']
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
parent: 1,
|
|
310
|
-
cells: ['child - 1']
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
isOpen: false,
|
|
314
|
-
cells: ['parent - 2', 'two', 'three', 'four', 'five']
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
parent: 3,
|
|
318
|
-
cells: ['child - 2']
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
isOpen: false,
|
|
322
|
-
cells: ['parent - 3', 'two', 'three', 'four', 'five']
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
parent: 5,
|
|
326
|
-
cells: ['child - 3']
|
|
327
|
-
}
|
|
328
|
-
]
|
|
329
|
-
};
|
|
330
|
-
this.onCollapse = this.onCollapse.bind(this);
|
|
331
|
-
this.toggleCollapseAll = this.toggleCollapseAll.bind(this);
|
|
332
|
-
this.onSelect = this.onSelect.bind(this);
|
|
333
|
-
this.toggleSelectAll = this.toggleSelectAll.bind(this);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
onCollapse(event, rowIndex, isOpen) {
|
|
337
|
-
const { rows, expandedRows, expandCollapseToggle } = this.state;
|
|
338
|
-
const expandableRowLength = this.state.rows.filter(row => row.isOpen !== undefined).length;
|
|
339
|
-
/**
|
|
340
|
-
* Please do not use rowKey as row index for more complex tables.
|
|
341
|
-
* Rather use some kind of identifier like ID passed with each row.
|
|
342
|
-
*/
|
|
343
|
-
const newRows = Array.from(rows);
|
|
344
|
-
newRows[rowIndex] = { ...newRows[rowIndex], isOpen };
|
|
345
|
-
const updatedExpandedRows = isOpen ? expandedRows + 1 : expandedRows - 1;
|
|
346
|
-
this.setState({
|
|
347
|
-
rows: newRows,
|
|
348
|
-
expandedRows: updatedExpandedRows,
|
|
349
|
-
expandCollapseToggle:
|
|
350
|
-
updatedExpandedRows === expandableRowLength
|
|
351
|
-
? 'collapse'
|
|
352
|
-
: updatedExpandedRows === 0
|
|
353
|
-
? 'expand'
|
|
354
|
-
: expandCollapseToggle
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
toggleCollapseAll(collapse) {
|
|
359
|
-
const expandableRowLength = this.state.rows.filter(row => row.isOpen !== undefined).length;
|
|
360
|
-
const updatedRows = this.state.rows.map(row =>
|
|
361
|
-
row.isOpen !== undefined
|
|
362
|
-
? {
|
|
363
|
-
...row,
|
|
364
|
-
isOpen: !collapse
|
|
365
|
-
}
|
|
366
|
-
: row
|
|
367
|
-
);
|
|
368
|
-
this.setState({
|
|
369
|
-
rows: updatedRows,
|
|
370
|
-
expandedRows: collapse ? 0 : expandableRowLength,
|
|
371
|
-
expandCollapseToggle: collapse === false ? 'collapse' : 'expand'
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
onSelect(event, isSelected, rowId) {
|
|
376
|
-
let isChecked = null;
|
|
377
|
-
let selectedRows = this.state.selectedRows;
|
|
378
|
-
const selectableRowLength = this.state.rows.filter(row => row.parent === undefined).length;
|
|
379
|
-
let rows;
|
|
380
|
-
if (rowId === -1) {
|
|
381
|
-
rows = this.state.rows.map(row => {
|
|
382
|
-
row.selected = isSelected;
|
|
383
|
-
return row;
|
|
384
|
-
});
|
|
385
|
-
isChecked = isSelected;
|
|
386
|
-
selectedRows = isSelected ? selectableRowLength : 0;
|
|
387
|
-
} else {
|
|
388
|
-
rows = [...this.state.rows];
|
|
389
|
-
rows[rowId] = { ...rows[rowId], selected: isSelected };
|
|
390
|
-
selectedRows = isSelected ? selectedRows + 1 : selectedRows - 1;
|
|
391
|
-
isChecked = selectedRows === 0 ? false : selectedRows === selectableRowLength ? true : null;
|
|
392
|
-
}
|
|
393
|
-
this.setState({
|
|
394
|
-
rows,
|
|
395
|
-
isChecked,
|
|
396
|
-
selectedRows
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
toggleSelectAll(checked) {
|
|
401
|
-
this.onSelect(null, checked, -1);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
render() {
|
|
405
|
-
const { columns, rows, expandCollapseToggle, isChecked } = this.state;
|
|
406
|
-
|
|
407
|
-
return (
|
|
408
|
-
<React.Fragment>
|
|
409
|
-
<Toolbar>
|
|
410
|
-
<ToolbarContent>
|
|
411
|
-
<ToolbarGroup variant="icon-button-group">
|
|
412
|
-
<ToolbarItem variant="expand-all" isAllExpanded={expandCollapseToggle !== 'expand'}>
|
|
413
|
-
{expandCollapseToggle === 'expand' ? (
|
|
414
|
-
<Button variant="plain" aria-label="Expand all" onClick={() => this.toggleCollapseAll(false)}>
|
|
415
|
-
<ToolbarExpandIconWrapper>
|
|
416
|
-
<AngleRightIcon />
|
|
417
|
-
</ToolbarExpandIconWrapper>
|
|
418
|
-
</Button>
|
|
419
|
-
) : (
|
|
420
|
-
<Button variant="plain" aria-label="Collapse all" onClick={() => this.toggleCollapseAll(true)}>
|
|
421
|
-
<ToolbarExpandIconWrapper>
|
|
422
|
-
<AngleRightIcon />
|
|
423
|
-
</ToolbarExpandIconWrapper>
|
|
424
|
-
</Button>
|
|
425
|
-
)}
|
|
426
|
-
</ToolbarItem>
|
|
427
|
-
<ToolbarItem>
|
|
428
|
-
<Checkbox
|
|
429
|
-
isChecked={isChecked}
|
|
430
|
-
onChange={this.toggleSelectAll}
|
|
431
|
-
aria-label="toggle select all checkbox"
|
|
432
|
-
id="toggle-select-all"
|
|
433
|
-
name="toggle-select-all"
|
|
434
|
-
label={isChecked ? 'Deselect all' : 'Select all'}
|
|
435
|
-
/>
|
|
436
|
-
</ToolbarItem>
|
|
437
|
-
</ToolbarGroup>
|
|
438
|
-
</ToolbarContent>
|
|
439
|
-
</Toolbar>
|
|
440
|
-
<Table
|
|
441
|
-
aria-label="Collapsible table"
|
|
442
|
-
onSelect={this.onSelect}
|
|
443
|
-
onCollapse={this.onCollapse}
|
|
444
|
-
rows={rows}
|
|
445
|
-
cells={columns}
|
|
446
|
-
canSelectAll={false}
|
|
447
|
-
>
|
|
448
|
-
<TableHeader />
|
|
449
|
-
<TableBody />
|
|
450
|
-
</Table>
|
|
451
|
-
</React.Fragment>
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
267
|
+
```js file="table-demos/ExpandCollapseAll.jsx"
|
|
455
268
|
```
|
|
456
269
|
|
|
457
270
|
### Column management
|
|
@@ -1886,7 +1699,7 @@ import {
|
|
|
1886
1699
|
Select,
|
|
1887
1700
|
SelectOption,
|
|
1888
1701
|
SelectVariant,
|
|
1889
|
-
|
|
1702
|
+
SearchInput,
|
|
1890
1703
|
EmptyState,
|
|
1891
1704
|
EmptyStateIcon,
|
|
1892
1705
|
EmptyStateBody,
|
|
@@ -2109,25 +1922,16 @@ class FilterTableDemo extends React.Component {
|
|
|
2109
1922
|
categoryName="Name"
|
|
2110
1923
|
showToolbarItem={currentCategory === 'Name'}
|
|
2111
1924
|
>
|
|
2112
|
-
<
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
/>
|
|
2123
|
-
<Button
|
|
2124
|
-
variant={ButtonVariant.control}
|
|
2125
|
-
aria-label="search button for search input"
|
|
2126
|
-
onClick={this.onNameInput}
|
|
2127
|
-
>
|
|
2128
|
-
<SearchIcon />
|
|
2129
|
-
</Button>
|
|
2130
|
-
</InputGroup>
|
|
1925
|
+
<SearchInput
|
|
1926
|
+
aria-label="name filter"
|
|
1927
|
+
placeholder="Filter by name..."
|
|
1928
|
+
onChange={this.onInputChange}
|
|
1929
|
+
value={inputValue}
|
|
1930
|
+
onClear={() => {
|
|
1931
|
+
this.onInputChange('');
|
|
1932
|
+
}}
|
|
1933
|
+
onSearch={this.onNameInput}
|
|
1934
|
+
/>
|
|
2131
1935
|
</ToolbarFilter>
|
|
2132
1936
|
<ToolbarFilter
|
|
2133
1937
|
chips={filters.status}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Table, TableHeader, TableBody, expandable } from '@patternfly/react-table';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
class ExpandCollapseAllTableDemo extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.state = {
|
|
9
|
+
isChecked: false,
|
|
10
|
+
selectedRows: 0,
|
|
11
|
+
expandedRows: 0,
|
|
12
|
+
expandCollapseToggle: 'expand',
|
|
13
|
+
collapseAllAriaLabel: 'Expand all',
|
|
14
|
+
columns: [
|
|
15
|
+
{
|
|
16
|
+
title: 'Header cell1',
|
|
17
|
+
cellFormatters: [expandable]
|
|
18
|
+
},
|
|
19
|
+
'Branches',
|
|
20
|
+
'Pull requests',
|
|
21
|
+
'Workspaces',
|
|
22
|
+
'Last Commit'
|
|
23
|
+
],
|
|
24
|
+
rows: [
|
|
25
|
+
{
|
|
26
|
+
cells: ['one', 'two', 'three', 'four', 'five']
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
isOpen: false,
|
|
30
|
+
cells: ['parent - 1', 'two', 'three', 'four', 'five']
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
parent: 1,
|
|
34
|
+
cells: ['child - 1']
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
isOpen: false,
|
|
38
|
+
cells: ['parent - 2', 'two', 'three', 'four', 'five']
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
parent: 3,
|
|
42
|
+
cells: ['child - 2']
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
isOpen: false,
|
|
46
|
+
cells: ['parent - 3', 'two', 'three', 'four', 'five']
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
parent: 5,
|
|
50
|
+
cells: ['child - 3']
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
this.onCollapse = this.onCollapse.bind(this);
|
|
55
|
+
this.onSelect = this.onSelect.bind(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onCollapse(event, rowIndex, isOpen) {
|
|
59
|
+
const { rows, expandedRows, expandCollapseToggle } = this.state;
|
|
60
|
+
const expandableRowLength = this.state.rows.filter(row => row.isOpen !== undefined).length;
|
|
61
|
+
/**
|
|
62
|
+
* Please do not use rowKey as row index for more complex tables.
|
|
63
|
+
* Rather use some kind of identifier like ID passed with each row.
|
|
64
|
+
*/
|
|
65
|
+
const collapseAll = rowIndex === undefined;
|
|
66
|
+
let newRows = Array.from(rows);
|
|
67
|
+
let newExpandedRows = expandedRows;
|
|
68
|
+
if (collapseAll) {
|
|
69
|
+
newRows = newRows.map(r => (r.isOpen === undefined ? r : { ...r, isOpen }));
|
|
70
|
+
newExpandedRows = isOpen ? expandableRowLength : 0;
|
|
71
|
+
} else {
|
|
72
|
+
newRows[rowIndex] = { ...newRows[rowIndex], isOpen };
|
|
73
|
+
newExpandedRows = isOpen ? newExpandedRows + 1 : newExpandedRows - 1;
|
|
74
|
+
}
|
|
75
|
+
let toggle = expandCollapseToggle;
|
|
76
|
+
if (newExpandedRows === expandableRowLength) {
|
|
77
|
+
toggle = 'collapse';
|
|
78
|
+
} else if (newExpandedRows === 0) {
|
|
79
|
+
toggle = 'expand';
|
|
80
|
+
}
|
|
81
|
+
this.setState({
|
|
82
|
+
rows: newRows,
|
|
83
|
+
expandedRows: newExpandedRows,
|
|
84
|
+
expandCollapseToggle: toggle,
|
|
85
|
+
collapseAllAriaLabel: toggle === 'expand' ? 'Expand All' : 'Collapse All'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onSelect(event, isSelected, rowId) {
|
|
90
|
+
let isChecked = null;
|
|
91
|
+
let selectedRows = this.state.selectedRows;
|
|
92
|
+
const selectableRowLength = this.state.rows.filter(row => row.parent === undefined).length;
|
|
93
|
+
let rows;
|
|
94
|
+
if (rowId === -1) {
|
|
95
|
+
rows = this.state.rows.map(row => {
|
|
96
|
+
row.selected = isSelected;
|
|
97
|
+
return row;
|
|
98
|
+
});
|
|
99
|
+
isChecked = isSelected;
|
|
100
|
+
selectedRows = isSelected ? selectableRowLength : 0;
|
|
101
|
+
} else {
|
|
102
|
+
rows = [...this.state.rows];
|
|
103
|
+
rows[rowId] = { ...rows[rowId], selected: isSelected };
|
|
104
|
+
selectedRows = isSelected ? selectedRows + 1 : selectedRows - 1;
|
|
105
|
+
if (selectedRows === 0) {
|
|
106
|
+
isChecked = false;
|
|
107
|
+
} else if (selectedRows === selectableRowLength) {
|
|
108
|
+
isChecked = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.setState({
|
|
112
|
+
rows,
|
|
113
|
+
isChecked,
|
|
114
|
+
selectedRows
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
render() {
|
|
119
|
+
const { columns, rows, collapseAllAriaLabel } = this.state;
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<React.Fragment>
|
|
123
|
+
<Table
|
|
124
|
+
aria-label="Collapsible table"
|
|
125
|
+
onSelect={this.onSelect}
|
|
126
|
+
onCollapse={this.onCollapse}
|
|
127
|
+
rows={rows}
|
|
128
|
+
cells={columns}
|
|
129
|
+
canSelectAll={true}
|
|
130
|
+
canCollapseAll={true}
|
|
131
|
+
collapseAllAriaLabel={collapseAllAriaLabel}
|
|
132
|
+
>
|
|
133
|
+
<TableHeader />
|
|
134
|
+
<TableBody />
|
|
135
|
+
</Table>
|
|
136
|
+
</React.Fragment>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|