@patternfly/react-data-view 5.1.1 → 5.1.3
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/dist/cjs/DataViewTable/DataViewTable.d.ts +18 -14
- package/dist/cjs/DataViewTable/DataViewTable.js +3 -44
- package/dist/cjs/DataViewTable/DataViewTable.test.js +40 -10
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +49 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +27 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.js +57 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.js +36 -0
- package/dist/cjs/DataViewTableHeader/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHeader/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +120 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +75 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/InternalContext/InternalContext.test.js +4 -3
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +10 -1
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHeader/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +18 -14
- package/dist/esm/DataViewTable/DataViewTable.js +3 -44
- package/dist/esm/DataViewTable/DataViewTable.test.js +40 -10
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +42 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +22 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.js +30 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
- package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.js +31 -0
- package/dist/esm/DataViewTableHeader/index.d.ts +2 -0
- package/dist/esm/DataViewTableHeader/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +19 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +93 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +70 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/InternalContext/InternalContext.test.js +5 -4
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +14 -2
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +29 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +7 -7
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +6 -6
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +6 -6
- package/src/DataViewTable/DataViewTable.test.tsx +53 -10
- package/src/DataViewTable/DataViewTable.tsx +20 -79
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +721 -31
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +37 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +71 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +324 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHeader/DataViewTableHeader.test.tsx +52 -0
- package/src/DataViewTableHeader/DataViewTableHeader.tsx +53 -0
- package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +227 -0
- package/src/DataViewTableHeader/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +85 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +144 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +937 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +4 -1
- package/src/InternalContext/InternalContext.test.tsx +8 -7
- 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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|
|
@@ -8,6 +8,8 @@ export interface DataViewToolbarProps extends PropsWithChildren {
|
|
|
8
8
|
bulkSelect?: React.ReactNode;
|
|
9
9
|
/** React component to display pagination */
|
|
10
10
|
pagination?: React.ReactNode;
|
|
11
|
+
/** React component to display actions */
|
|
12
|
+
actions?: React.ReactNode;
|
|
11
13
|
}
|
|
12
14
|
export declare const DataViewToolbar: React.FC<DataViewToolbarProps>;
|
|
13
15
|
export default DataViewToolbar;
|
|
@@ -12,10 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
|
|
14
14
|
export const DataViewToolbar = (_a) => {
|
|
15
|
-
var { className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "pagination", "children"]);
|
|
15
|
+
var { className, ouiaId = 'DataViewToolbar', bulkSelect, actions = null, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "actions", "pagination", "children"]);
|
|
16
16
|
return (React.createElement(Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
|
|
17
17
|
React.createElement(ToolbarContent, null,
|
|
18
18
|
bulkSelect && (React.createElement(ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
|
|
19
|
+
actions,
|
|
19
20
|
pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
|
|
20
21
|
children)));
|
|
21
22
|
};
|
|
@@ -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 {
|
|
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(
|
|
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(
|
|
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(
|
|
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();
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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
|
@@ -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', '
|
|
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
|
+
```
|
package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { 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
|
+
import { ActionsColumn } from '@patternfly/react-table';
|
|
5
6
|
|
|
6
7
|
interface Repository {
|
|
7
8
|
id: number;
|
|
@@ -13,12 +14,30 @@ interface Repository {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const repositories: Repository[] = [
|
|
16
|
-
{ id: 1, name: 'one', branches: '
|
|
17
|
-
{ id: 2, name: '
|
|
18
|
-
{ id: 3, name: '
|
|
19
|
-
{ id: 4, name: '
|
|
20
|
-
{ id: 5, name: '
|
|
21
|
-
{ id: 6, name: '
|
|
17
|
+
{ id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
18
|
+
{ id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
19
|
+
{ id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
20
|
+
{ id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
21
|
+
{ id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
22
|
+
{ id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const rowActions = [
|
|
26
|
+
{
|
|
27
|
+
title: 'Some action',
|
|
28
|
+
onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: <div>Another action</div>,
|
|
32
|
+
onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
isSeparator: true
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: 'Third action',
|
|
39
|
+
onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
|
|
40
|
+
}
|
|
22
41
|
];
|
|
23
42
|
|
|
24
43
|
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
|
|
@@ -28,7 +47,8 @@ const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspac
|
|
|
28
47
|
branches,
|
|
29
48
|
prs,
|
|
30
49
|
workspaces,
|
|
31
|
-
lastCommit
|
|
50
|
+
lastCommit,
|
|
51
|
+
{ cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } },
|
|
32
52
|
]);
|
|
33
53
|
|
|
34
54
|
const columns: DataViewTh[] = [
|
|
@@ -37,7 +57,7 @@ const columns: DataViewTh[] = [
|
|
|
37
57
|
{ cell: <>Branches<ExclamationCircleIcon className='pf-v5-u-ml-sm' color='var(--pf-v5-global--danger-color--100)'/></> },
|
|
38
58
|
'Pull requests',
|
|
39
59
|
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
|
|
40
|
-
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
|
|
60
|
+
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } },
|
|
41
61
|
];
|
|
42
62
|
|
|
43
63
|
const ouiaId = 'TableExample';
|
|
@@ -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
|
+
}
|
package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx
CHANGED
|
@@ -13,12 +13,12 @@ interface Repository {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const repositories: Repository[] = [
|
|
16
|
-
{ name: 'one', branches: '
|
|
17
|
-
{ name: '
|
|
18
|
-
{ name: '
|
|
19
|
-
{ name: '
|
|
20
|
-
{ name: '
|
|
21
|
-
{ name: '
|
|
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
|
|
49
|
+
Detail of {selectedRepo?.name}
|
|
50
50
|
</Title>
|
|
51
51
|
<Text>Branches: {selectedRepo?.branches}</Text>
|
|
52
52
|
<Text>Pull requests: {selectedRepo?.prs}</Text>
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx
CHANGED
|
@@ -20,12 +20,12 @@ interface Repository {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const repositories: Repository[] = [
|
|
23
|
-
{ name: 'one', branches: '
|
|
24
|
-
{ name: '
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
28
|
-
{ name: '
|
|
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));
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx
CHANGED
|
@@ -14,12 +14,12 @@ interface Repository {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const repositories: Repository[] = [
|
|
17
|
-
{ name: 'one', branches: '
|
|
18
|
-
{ name: '
|
|
19
|
-
{ name: '
|
|
20
|
-
{ name: '
|
|
21
|
-
{ name: '
|
|
22
|
-
{ name: '
|
|
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));
|
package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx
CHANGED
|
@@ -20,12 +20,12 @@ interface Repository {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const repositories: Repository[] = [
|
|
23
|
-
{ name: 'one', branches: '
|
|
24
|
-
{ name: '
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
28
|
-
{ name: '
|
|
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));
|