@patternfly/react-data-view 5.1.1 → 5.1.2

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.
Files changed (76) hide show
  1. package/dist/cjs/DataViewTable/DataViewTable.d.ts +18 -14
  2. package/dist/cjs/DataViewTable/DataViewTable.js +3 -44
  3. package/dist/cjs/DataViewTable/DataViewTable.test.js +40 -10
  4. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  5. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +49 -0
  6. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  7. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +27 -0
  8. package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
  9. package/dist/cjs/DataViewTableBasic/index.js +23 -0
  10. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
  11. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.js +57 -0
  12. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
  13. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.js +36 -0
  14. package/dist/cjs/DataViewTableHeader/index.d.ts +2 -0
  15. package/dist/cjs/DataViewTableHeader/index.js +23 -0
  16. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +19 -0
  17. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +120 -0
  18. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  19. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +75 -0
  20. package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
  21. package/dist/cjs/DataViewTableTree/index.js +23 -0
  22. package/dist/cjs/InternalContext/InternalContext.test.js +4 -3
  23. package/dist/cjs/index.d.ts +6 -0
  24. package/dist/cjs/index.js +10 -1
  25. package/dist/dynamic/DataViewTableBasic/package.json +1 -0
  26. package/dist/dynamic/DataViewTableHeader/package.json +1 -0
  27. package/dist/dynamic/DataViewTableTree/package.json +1 -0
  28. package/dist/esm/DataViewTable/DataViewTable.d.ts +18 -14
  29. package/dist/esm/DataViewTable/DataViewTable.js +3 -44
  30. package/dist/esm/DataViewTable/DataViewTable.test.js +40 -10
  31. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  32. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +42 -0
  33. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  34. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +22 -0
  35. package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
  36. package/dist/esm/DataViewTableBasic/index.js +2 -0
  37. package/dist/esm/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
  38. package/dist/esm/DataViewTableHeader/DataViewTableHeader.js +30 -0
  39. package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
  40. package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.js +31 -0
  41. package/dist/esm/DataViewTableHeader/index.d.ts +2 -0
  42. package/dist/esm/DataViewTableHeader/index.js +2 -0
  43. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +19 -0
  44. package/dist/esm/DataViewTableTree/DataViewTableTree.js +93 -0
  45. package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  46. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +70 -0
  47. package/dist/esm/DataViewTableTree/index.d.ts +2 -0
  48. package/dist/esm/DataViewTableTree/index.js +2 -0
  49. package/dist/esm/InternalContext/InternalContext.test.js +5 -4
  50. package/dist/esm/index.d.ts +6 -0
  51. package/dist/esm/index.js +6 -0
  52. package/package.json +1 -1
  53. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +14 -2
  54. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +7 -7
  55. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
  56. package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +7 -7
  57. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +6 -6
  58. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +6 -6
  59. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +6 -6
  60. package/src/DataViewTable/DataViewTable.test.tsx +53 -10
  61. package/src/DataViewTable/DataViewTable.tsx +20 -79
  62. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +721 -31
  63. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +37 -0
  64. package/src/DataViewTableBasic/DataViewTableBasic.tsx +71 -0
  65. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +324 -0
  66. package/src/DataViewTableBasic/index.ts +2 -0
  67. package/src/DataViewTableHeader/DataViewTableHeader.test.tsx +52 -0
  68. package/src/DataViewTableHeader/DataViewTableHeader.tsx +53 -0
  69. package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +227 -0
  70. package/src/DataViewTableHeader/index.ts +2 -0
  71. package/src/DataViewTableTree/DataViewTableTree.test.tsx +85 -0
  72. package/src/DataViewTableTree/DataViewTableTree.tsx +144 -0
  73. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +937 -0
  74. package/src/DataViewTableTree/index.ts +2 -0
  75. package/src/InternalContext/InternalContext.test.tsx +8 -7
  76. package/src/index.ts +9 -0
@@ -0,0 +1,93 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { useMemo } from 'react';
13
+ import { Table, Tbody, Td, TreeRowWrapper, } from '@patternfly/react-table';
14
+ import { useInternalContext } from '../InternalContext';
15
+ import { DataViewTableHeader } from '../DataViewTableHeader';
16
+ import { isDataViewTdObject } from '../DataViewTable';
17
+ const getDescendants = (node) => (!node.children || !node.children.length) ? [node] : node.children.flatMap(getDescendants);
18
+ const isNodeChecked = (node, isSelected) => {
19
+ let allSelected = true;
20
+ let someSelected = false;
21
+ for (const descendant of getDescendants(node)) {
22
+ const selected = !!(isSelected === null || isSelected === void 0 ? void 0 : isSelected(descendant));
23
+ someSelected || (someSelected = selected);
24
+ allSelected && (allSelected = selected);
25
+ if (!allSelected && someSelected) {
26
+ return null;
27
+ }
28
+ }
29
+ return allSelected;
30
+ };
31
+ export const DataViewTableTree = (_a) => {
32
+ var { columns, rows, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
33
+ const { selection } = useInternalContext();
34
+ const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
35
+ const [expandedNodeIds, setExpandedNodeIds] = React.useState([]);
36
+ const [expandedDetailsNodeNames, setExpandedDetailsNodeIds] = React.useState([]);
37
+ const nodes = useMemo(() => {
38
+ const renderRows = ([node, ...remainingNodes], level = 1, posinset = 1, rowIndex = 0, isHidden = false) => {
39
+ var _a, _b, _c, _d;
40
+ if (!node) {
41
+ return [];
42
+ }
43
+ const isExpanded = expandedNodeIds.includes(node.id);
44
+ const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
45
+ const isChecked = isSelected && isNodeChecked(node, isSelected);
46
+ let icon = leafIcon;
47
+ if (node.children) {
48
+ icon = isExpanded ? expandedIcon : collapsedIcon;
49
+ }
50
+ const treeRow = {
51
+ onCollapse: () => setExpandedNodeIds(prevExpanded => {
52
+ const otherExpandedNodeIds = prevExpanded.filter(id => id !== node.id);
53
+ return isExpanded ? otherExpandedNodeIds : [...otherExpandedNodeIds, node.id];
54
+ }),
55
+ onToggleRowDetails: () => setExpandedDetailsNodeIds(prevDetailsExpanded => {
56
+ const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
57
+ return isDetailsExpanded ? otherDetailsExpandedNodeIds : [...otherDetailsExpandedNodeIds, node.id];
58
+ }),
59
+ onCheckChange: ((isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(node)) || !onSelect) ? undefined : (_event, isChecking) => onSelect === null || onSelect === void 0 ? void 0 : onSelect(isChecking, getDescendants(node)),
60
+ rowIndex,
61
+ props: {
62
+ isExpanded,
63
+ isDetailsExpanded,
64
+ isHidden,
65
+ 'aria-level': level,
66
+ 'aria-posinset': posinset,
67
+ 'aria-setsize': (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
68
+ isChecked,
69
+ ouiaId: `${ouiaId}-tree-toggle-${node.id}`,
70
+ checkboxId: `checkbox_id_${(_c = node.id) === null || _c === void 0 ? void 0 : _c.toLowerCase().replace(/\s+/g, '_')}`,
71
+ icon,
72
+ },
73
+ };
74
+ const childRows = ((_d = node.children) === null || _d === void 0 ? void 0 : _d.length)
75
+ ? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
76
+ : [];
77
+ return [
78
+ React.createElement(TreeRowWrapper, { key: node.id, row: { props: treeRow.props } }, node.row.map((cell, colIndex) => {
79
+ var _a;
80
+ const cellIsObject = isDataViewTdObject(cell);
81
+ return (React.createElement(Td, Object.assign({ key: colIndex, treeRow: colIndex === 0 ? treeRow : undefined }, (cellIsObject && ((_a = cell === null || cell === void 0 ? void 0 : cell.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-td-${rowIndex}-${colIndex}` }), cellIsObject ? cell.cell : cell));
82
+ })),
83
+ ...childRows,
84
+ ...renderRows(remainingNodes, level, posinset + 1, rowIndex + 1 + childRows.length, isHidden),
85
+ ];
86
+ };
87
+ return renderRows(rows);
88
+ }, [rows, expandedNodeIds, expandedDetailsNodeNames, leafIcon, expandedIcon, collapsedIcon, isSelected, onSelect, isSelectDisabled, ouiaId]);
89
+ return (React.createElement(Table, Object.assign({ isTreeTable: true, "aria-label": "Data table", ouiaId: ouiaId }, props),
90
+ React.createElement(DataViewTableHeader, { isTreeTable: true, columns: columns, ouiaId: ouiaId }),
91
+ React.createElement(Tbody, null, nodes)));
92
+ };
93
+ export default DataViewTableTree;
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
4
+ import { DataView } from '../DataView';
5
+ import { DataViewTable } from '../DataViewTable';
6
+ const repositories = [
7
+ {
8
+ name: 'Repository one',
9
+ branches: 'Branch one',
10
+ prs: 'Pull request one',
11
+ workspaces: 'Workspace one',
12
+ lastCommit: 'Timestamp one',
13
+ children: [
14
+ {
15
+ name: 'Repository two',
16
+ branches: 'Branch two',
17
+ prs: 'Pull request two',
18
+ workspaces: 'Workspace two',
19
+ lastCommit: 'Timestamp two',
20
+ },
21
+ {
22
+ name: 'Repository three',
23
+ branches: 'Branch three',
24
+ prs: 'Pull request three',
25
+ workspaces: 'Workspace three',
26
+ lastCommit: 'Timestamp three',
27
+ },
28
+ ],
29
+ },
30
+ {
31
+ name: 'Repository four',
32
+ branches: 'Branch four',
33
+ prs: 'Pull request four',
34
+ workspaces: 'Workspace four',
35
+ lastCommit: 'Timestamp four',
36
+ children: [
37
+ {
38
+ name: 'Repository five',
39
+ branches: 'Branch five',
40
+ prs: 'Pull request five',
41
+ workspaces: 'Workspace five',
42
+ lastCommit: 'Timestamp five',
43
+ },
44
+ ],
45
+ },
46
+ {
47
+ name: 'Repository six',
48
+ branches: 'Branch six',
49
+ prs: 'Pull request six',
50
+ workspaces: 'Workspace six',
51
+ lastCommit: 'Timestamp six',
52
+ },
53
+ ];
54
+ // Build rows for DataViewTable
55
+ const buildRows = (repositories) => repositories.map((repo) => (Object.assign({ row: [repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit], id: repo.name }, (repo.children ? { children: buildRows(repo.children) } : {}))));
56
+ const rows = buildRows(repositories);
57
+ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
58
+ const ouiaId = 'TreeTableExample';
59
+ describe('DataViewTableTree component', () => {
60
+ const mockSelection = {
61
+ onSelect: jest.fn(),
62
+ isSelected: jest.fn(),
63
+ isSelectDisabled: jest.fn(),
64
+ };
65
+ test('should render the tree table correctly', () => {
66
+ const { container } = render(React.createElement(DataView, { selection: mockSelection },
67
+ React.createElement(DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows, leafIcon: React.createElement(LeafIcon, null), expandedIcon: React.createElement(FolderOpenIcon, { "aria-hidden": true }), collapsedIcon: React.createElement(FolderIcon, { "aria-hidden": true }) })));
68
+ expect(container).toMatchSnapshot();
69
+ });
70
+ });
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableTree';
2
+ export * from './DataViewTableTree';
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableTree';
2
+ export * from './DataViewTableTree';
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { render, fireEvent } from '@testing-library/react';
3
3
  import '@testing-library/jest-dom';
4
- import { InternalContextProvider, useInternalContext } from './InternalContext';
4
+ import { useInternalContext } from './InternalContext';
5
+ import { DataView } from '../DataView';
5
6
  describe('InternalContext', () => {
6
7
  const mockSelection = {
7
8
  onSelect: jest.fn(),
@@ -15,7 +16,7 @@ describe('InternalContext', () => {
15
16
  React.createElement("button", { onClick: () => selection === null || selection === void 0 ? void 0 : selection.onSelect(true, ['item1']) }, "Select item"),
16
17
  React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Selected' : 'Not selected')));
17
18
  };
18
- const { getByText } = render(React.createElement(InternalContextProvider, { selection: mockSelection },
19
+ const { getByText } = render(React.createElement(DataView, { selection: mockSelection },
19
20
  React.createElement(TestComponent, null)));
20
21
  fireEvent.click(getByText('Select item'));
21
22
  expect(mockSelection.onSelect).toHaveBeenCalledWith(true, ['item1']);
@@ -28,7 +29,7 @@ describe('InternalContext', () => {
28
29
  React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Item 1 is selected' : 'Item 1 is not selected'),
29
30
  React.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item2')) ? 'Item 2 is selected' : 'Item 2 is not selected')));
30
31
  };
31
- const { getByText } = render(React.createElement(InternalContextProvider, { selection: mockSelectionState },
32
+ const { getByText } = render(React.createElement(DataView, { selection: mockSelectionState },
32
33
  React.createElement(TestComponent, null)));
33
34
  expect(getByText('Item 1 is selected')).toBeInTheDocument();
34
35
  expect(getByText('Item 2 is not selected')).toBeInTheDocument();
@@ -42,7 +43,7 @@ describe('InternalContext', () => {
42
43
  React.createElement("span", null, ((_a = selection === null || selection === void 0 ? void 0 : selection.isSelectDisabled) === null || _a === void 0 ? void 0 : _a.call(selection, 'item3')) ? 'Item 3 is disabled' : 'Item 3 is enabled'),
43
44
  React.createElement("span", null, ((_b = selection === null || selection === void 0 ? void 0 : selection.isSelectDisabled) === null || _b === void 0 ? void 0 : _b.call(selection, 'item1')) ? 'Item 1 is disabled' : 'Item 1 is enabled')));
44
45
  };
45
- const { getByText } = render(React.createElement(InternalContextProvider, { selection: mockSelectionWithDisabled },
46
+ const { getByText } = render(React.createElement(DataView, { selection: mockSelectionWithDisabled },
46
47
  React.createElement(TestComponent, null)));
47
48
  expect(getByText('Item 3 is disabled')).toBeInTheDocument();
48
49
  expect(getByText('Item 1 is enabled')).toBeInTheDocument();
@@ -3,6 +3,12 @@ export * from './InternalContext';
3
3
  export * from './Hooks';
4
4
  export { default as DataViewToolbar } from './DataViewToolbar';
5
5
  export * from './DataViewToolbar';
6
+ export { default as DataViewTableTree } from './DataViewTableTree';
7
+ export * from './DataViewTableTree';
8
+ export { default as DataViewTableHeader } from './DataViewTableHeader';
9
+ export * from './DataViewTableHeader';
10
+ export { default as DataViewTableBasic } from './DataViewTableBasic';
11
+ export * from './DataViewTableBasic';
6
12
  export { default as DataViewTable } from './DataViewTable';
7
13
  export * from './DataViewTable';
8
14
  export { default as DataViewEventsContext } from './DataViewEventsContext';
package/dist/esm/index.js CHANGED
@@ -4,6 +4,12 @@ export * from './InternalContext';
4
4
  export * from './Hooks';
5
5
  export { default as DataViewToolbar } from './DataViewToolbar';
6
6
  export * from './DataViewToolbar';
7
+ export { default as DataViewTableTree } from './DataViewTableTree';
8
+ export * from './DataViewTableTree';
9
+ export { default as DataViewTableHeader } from './DataViewTableHeader';
10
+ export * from './DataViewTableHeader';
11
+ export { default as DataViewTableBasic } from './DataViewTableBasic';
12
+ export * from './DataViewTableBasic';
7
13
  export { default as DataViewTable } from './DataViewTable';
8
14
  export * from './DataViewTable';
9
15
  export { default as DataViewEventsContext } from './DataViewEventsContext';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-data-view",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Data view used for Red Hat projects.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -11,13 +11,15 @@ source: react
11
11
  # If you use typescript, the name of the interface to display props for
12
12
  # These are found through the sourceProps function provided in patternfly-docs.source.js
13
13
  sortValue: 4
14
- propComponents: ['DataViewToolbar', 'DataViewTable']
14
+ propComponents: ['DataViewToolbar', 'DataViewTableBasic', 'DataViewTableTree']
15
15
  sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
16
16
  ---
17
+ import { FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
17
18
  import { BulkSelect } from '@patternfly/react-component-groups';
18
- import { ExclamationCircleIcon } from '@patternfly/react-icons';
19
19
  import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
20
20
  import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
21
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
22
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
21
23
 
22
24
  ## Data view toolbar
23
25
 
@@ -58,4 +60,14 @@ The `DataViewTable` component accepts the following props:
58
60
 
59
61
  - optional `props` (`TableProps`) that are passed down to the `<Table>` component, except for `onSelect`, which is managed internally.
60
62
 
63
+ ### Tree table example
64
+ This example shows the tree table variant with expandable rows, custom icons for leaf and parent nodes. Tree table is turned on by passing `isTreeTable` flag to the `DataViewTable` component. You can pass `collapsedIcon`, `expandedIcon` or `leafIcon` to be displayen rows with given status. The tree table rows have to be defined in a format of object with following keys:
65
+ - `row` (`DataViewTd[]`) defining the content for each cell in the row.
66
+ - `id` (`string`) for the row (used to match items in selection end expand the rows).
67
+ - optional `children` (`DataViewTrTree[]`) defining the children rows.
68
+
69
+ It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component.
61
70
 
71
+ ```js file="./DataViewTableTreeExample.tsx"
72
+
73
+ ```
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { DataViewTable, DataViewTh, DataViewTr } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3
3
  import { ExclamationCircleIcon } from '@patternfly/react-icons';
4
4
  import { Button } from '@patternfly/react-core';
5
5
 
@@ -13,12 +13,12 @@ interface Repository {
13
13
  }
14
14
 
15
15
  const repositories: Repository[] = [
16
- { id: 1, name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
17
- { id: 2, name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
18
- { id: 3, name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
19
- { id: 4, name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
20
- { id: 5, name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
21
- { id: 6, name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
16
+ { id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
17
+ { id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
18
+ { id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
19
+ { id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
20
+ { id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
21
+ { id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
22
22
  ];
23
23
 
24
24
  // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
3
+ import { DataViewTable, DataViewTh, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
5
+ import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
6
+
7
+ interface Repository {
8
+ name: string;
9
+ branches: string | null;
10
+ prs: string | null;
11
+ workspaces: string;
12
+ lastCommit: string;
13
+ children?: Repository[];
14
+ }
15
+
16
+ const repositories: Repository[] = [
17
+ {
18
+ name: 'Repository one',
19
+ branches: 'Branch one',
20
+ prs: 'Pull request one',
21
+ workspaces: 'Workspace one',
22
+ lastCommit: 'Timestamp one',
23
+ children: [
24
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
25
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
26
+ ]
27
+ },
28
+ {
29
+ name: 'Repository four',
30
+ branches: 'Branch four',
31
+ prs: 'Pull request four',
32
+ workspaces: 'Workspace four',
33
+ lastCommit: 'Timestamp four',
34
+ children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
35
+ },
36
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
37
+ ];
38
+
39
+ const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
40
+ row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
41
+ id: repo.name, // unique ID for each row
42
+ ...(repo.children
43
+ ? {
44
+ children: buildRows(repo.children) // build rows for children
45
+ }
46
+ : {})
47
+ }));
48
+
49
+ const rows: DataViewTrTree[] = buildRows(repositories);
50
+
51
+ const columns: DataViewTh[] = [
52
+ 'Repositories',
53
+ 'Branches',
54
+ 'Pull requests',
55
+ 'Workspaces',
56
+ 'Last commit'
57
+ ];
58
+
59
+ const ouiaId = 'TreeTableExample';
60
+
61
+ export const BasicExample: React.FunctionComponent = () => {
62
+ const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
63
+
64
+ return (
65
+ <DataView selection={selection}>
66
+ <DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
67
+ </DataView>
68
+ );
69
+ }
@@ -13,12 +13,12 @@ interface Repository {
13
13
  }
14
14
 
15
15
  const repositories: Repository[] = [
16
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
17
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
18
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
19
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
20
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
21
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
16
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
17
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
18
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
19
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
20
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
21
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
22
22
  ];
23
23
 
24
24
  const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
@@ -46,7 +46,7 @@ const RepositoryDetail: React.FunctionComponent<RepositoryDetailProps> = ({ sele
46
46
  <DrawerPanelContent>
47
47
  <DrawerHead>
48
48
  <Title className="pf-v5-u-mb-md" headingLevel="h2" ouiaId="detail-drawer-title">
49
- Detail of repository {selectedRepo?.name}
49
+ Detail of {selectedRepo?.name}
50
50
  </Title>
51
51
  <Text>Branches: {selectedRepo?.branches}</Text>
52
52
  <Text>Pull requests: {selectedRepo?.prs}</Text>
@@ -20,12 +20,12 @@ interface Repository {
20
20
  }
21
21
 
22
22
  const repositories: Repository[] = [
23
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
24
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
25
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
26
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
27
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
28
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
23
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
24
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
25
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
26
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
27
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
28
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
29
29
  ];
30
30
 
31
31
  const rows = repositories.map(item => Object.values(item));
@@ -14,12 +14,12 @@ interface Repository {
14
14
  }
15
15
 
16
16
  const repositories: Repository[] = [
17
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
18
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
19
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
20
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
21
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
22
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
17
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
18
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
19
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
20
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
21
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
22
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
23
23
  ];
24
24
 
25
25
  const rows = repositories.map(item => Object.values(item));
@@ -20,12 +20,12 @@ interface Repository {
20
20
  }
21
21
 
22
22
  const repositories: Repository[] = [
23
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
24
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
25
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
26
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
27
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
28
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
23
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
24
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
25
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
26
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
27
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
28
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
29
29
  ];
30
30
 
31
31
  const rows = repositories.map(item => Object.values(item));
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
- import { DataViewTable } from './DataViewTable';
3
+ import { DataViewTable, DataViewTrTree } from './DataViewTable';
4
4
 
5
5
  interface Repository {
6
6
  name: string;
@@ -8,30 +8,73 @@ interface Repository {
8
8
  prs: string | null;
9
9
  workspaces: string;
10
10
  lastCommit: string;
11
+ children?: Repository[];
11
12
  }
12
13
 
13
14
  const repositories: Repository[] = [
14
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
15
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
16
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
17
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
18
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
19
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
15
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
16
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
17
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
18
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
19
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
20
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
20
21
  ];
21
22
 
22
- const rows = repositories.map(repo => ({
23
- row: Object.values(repo),
23
+ const rows = repositories.map(repo => ({ row: Object.values(repo) }));
24
+
25
+ const repositoriesTree: Repository[] = [
26
+ {
27
+ name: 'Repository one',
28
+ branches: 'Branch one',
29
+ prs: 'Pull request one',
30
+ workspaces: 'Workspace one',
31
+ lastCommit: 'Timestamp one',
32
+ children: [
33
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
34
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
35
+ ]
36
+ },
37
+ {
38
+ name: 'Repository four',
39
+ branches: 'Branch four',
40
+ prs: 'Pull request four',
41
+ workspaces: 'Workspace four',
42
+ lastCommit: 'Timestamp four',
43
+ children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
44
+ },
45
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
46
+ ];
47
+
48
+
49
+
50
+ const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
51
+ row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
52
+ id: repo.name, // unique ID for each row
53
+ ...(repo.children
54
+ ? {
55
+ children: buildRows(repo.children) // build rows for children
56
+ }
57
+ : {})
24
58
  }));
25
59
 
60
+ const treeRows = buildRows(repositoriesTree);
61
+
26
62
  const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
27
63
 
28
64
  const ouiaId = 'TableExample';
29
65
 
30
66
  describe('DataViewTable component', () => {
31
- test('should render correctly', () => {
67
+ test('should render a basic table correctly', () => {
32
68
  const { container } = render(
33
69
  <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
34
70
  );
35
71
  expect(container).toMatchSnapshot();
36
72
  });
73
+
74
+ test('should render a tree table correctly', () => {
75
+ const { container } = render(
76
+ <DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={treeRows} />
77
+ );
78
+ expect(container).toMatchSnapshot();
79
+ });
37
80
  });