@patternfly/react-data-view 5.1.3 → 5.2.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/dist/cjs/DataView/DataView.d.ts +8 -0
- package/dist/cjs/DataView/DataView.js +9 -4
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +3 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +32 -11
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +11 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +3 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +17 -6
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +10 -0
- package/dist/cjs/InternalContext/InternalContext.d.ts +2 -0
- package/dist/cjs/InternalContext/InternalContext.js +3 -2
- package/dist/esm/DataView/DataView.d.ts +8 -0
- package/dist/esm/DataView/DataView.js +8 -3
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +3 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +9 -8
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +11 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +3 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +18 -7
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +10 -0
- package/dist/esm/InternalContext/InternalContext.d.ts +2 -0
- package/dist/esm/InternalContext/InternalContext.js +3 -2
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +18 -3
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +51 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +38 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +11 -9
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +1 -1
- package/src/DataView/DataView.tsx +14 -4
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +6 -6
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +19 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +45 -32
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +190 -0
- package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +2 -2
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +19 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +30 -6
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +197 -7
- package/src/InternalContext/InternalContext.tsx +7 -3
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DataViewSelection } from '../InternalContext';
|
|
3
|
+
export declare const DataViewState: {
|
|
4
|
+
readonly empty: "empty";
|
|
5
|
+
readonly loading: "loading";
|
|
6
|
+
readonly error: "error";
|
|
7
|
+
};
|
|
8
|
+
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
3
9
|
export interface DataViewProps {
|
|
4
10
|
/** Content rendered inside the data view */
|
|
5
11
|
children: React.ReactNode;
|
|
@@ -7,6 +13,8 @@ export interface DataViewProps {
|
|
|
7
13
|
ouiaId?: string;
|
|
8
14
|
/** Selection context configuration */
|
|
9
15
|
selection?: DataViewSelection;
|
|
16
|
+
/** Currently active state */
|
|
17
|
+
activeState?: DataViewState;
|
|
10
18
|
}
|
|
11
19
|
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
12
20
|
export declare const DataView: React.FC<DataViewProps>;
|
|
@@ -14,17 +14,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.DataView = void 0;
|
|
17
|
+
exports.DataView = exports.DataViewState = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const react_core_1 = require("@patternfly/react-core");
|
|
20
20
|
const InternalContext_1 = require("../InternalContext");
|
|
21
|
+
exports.DataViewState = {
|
|
22
|
+
empty: 'empty',
|
|
23
|
+
loading: 'loading',
|
|
24
|
+
error: 'error'
|
|
25
|
+
};
|
|
21
26
|
const DataViewImplementation = (_a) => {
|
|
22
27
|
var { children, ouiaId = 'DataView' } = _a, props = __rest(_a, ["children", "ouiaId"]);
|
|
23
|
-
return (react_1.default.createElement(react_core_1.Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack
|
|
28
|
+
return (react_1.default.createElement(react_core_1.Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack` }, props), react_1.default.Children.map(children, (child, index) => (react_1.default.createElement(react_core_1.StackItem, { "data-ouia-component-id": `${ouiaId}-stack-item-${index}` }, child)))));
|
|
24
29
|
};
|
|
25
30
|
const DataView = (_a) => {
|
|
26
|
-
var { children, selection } = _a, props = __rest(_a, ["children", "selection"]);
|
|
27
|
-
return (react_1.default.createElement(InternalContext_1.InternalContextProvider, { selection: selection },
|
|
31
|
+
var { children, selection, activeState } = _a, props = __rest(_a, ["children", "selection", "activeState"]);
|
|
32
|
+
return (react_1.default.createElement(InternalContext_1.InternalContextProvider, { selection: selection, activeState: activeState },
|
|
28
33
|
react_1.default.createElement(DataViewImplementation, Object.assign({}, props), children)));
|
|
29
34
|
};
|
|
30
35
|
exports.DataView = DataView;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTr } from '../DataViewTable';
|
|
4
|
+
import { DataViewState } from '../DataView/DataView';
|
|
4
5
|
export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
5
6
|
/** Columns definition */
|
|
6
7
|
columns: DataViewTh[];
|
|
7
8
|
/** Current page rows */
|
|
8
9
|
rows: DataViewTr[];
|
|
10
|
+
/** States to be displayed when active */
|
|
11
|
+
states?: Partial<Record<DataViewState, React.ReactNode>>;
|
|
9
12
|
/** Custom OUIA ID */
|
|
10
13
|
ouiaId?: string;
|
|
11
14
|
}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
26
|
var t = {};
|
|
4
27
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -10,27 +33,25 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
33
|
}
|
|
11
34
|
return t;
|
|
12
35
|
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
37
|
exports.DataViewTableBasic = void 0;
|
|
18
|
-
const react_1 =
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
19
39
|
const react_table_1 = require("@patternfly/react-table");
|
|
20
40
|
const InternalContext_1 = require("../InternalContext");
|
|
21
41
|
const DataViewTableHeader_1 = require("../DataViewTableHeader");
|
|
22
42
|
const DataViewTable_1 = require("../DataViewTable");
|
|
23
43
|
const DataViewTableBasic = (_a) => {
|
|
24
|
-
var { columns, rows, ouiaId = 'DataViewTableBasic' } = _a, props = __rest(_a, ["columns", "rows", "ouiaId"]);
|
|
25
|
-
const { selection } = (0, InternalContext_1.useInternalContext)();
|
|
44
|
+
var { columns, rows, ouiaId = 'DataViewTableBasic', states = {} } = _a, props = __rest(_a, ["columns", "rows", "ouiaId", "states"]);
|
|
45
|
+
const { selection, activeState } = (0, InternalContext_1.useInternalContext)();
|
|
26
46
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
47
|
+
const isSelectable = (0, react_1.useMemo)(() => Boolean(onSelect && isSelected), [onSelect, isSelected]);
|
|
27
48
|
return (react_1.default.createElement(react_table_1.Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
28
49
|
react_1.default.createElement(DataViewTableHeader_1.DataViewTableHeader, { columns: columns, ouiaId: ouiaId }),
|
|
29
|
-
react_1.default.createElement(react_table_1.Tbody, null,
|
|
30
|
-
|
|
50
|
+
react_1.default.createElement(react_table_1.Tbody, null, activeState && Object.keys(states).includes(activeState) ? (react_1.default.createElement(react_table_1.Tr, { key: activeState, ouiaId: `${ouiaId}-tr-${activeState}` },
|
|
51
|
+
react_1.default.createElement(react_table_1.Td, { colSpan: columns.length + Number(isSelectable) }, states[activeState]))) : (rows.map((row, rowIndex) => {
|
|
31
52
|
const rowIsObject = (0, DataViewTable_1.isDataViewTrObject)(row);
|
|
32
|
-
return (react_1.default.createElement(react_table_1.Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (
|
|
33
|
-
|
|
53
|
+
return (react_1.default.createElement(react_table_1.Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props))),
|
|
54
|
+
isSelectable && (react_1.default.createElement(react_table_1.Td, { key: `select-${rowIndex}`, select: {
|
|
34
55
|
rowIndex,
|
|
35
56
|
onSelect: (_event, isSelecting) => {
|
|
36
57
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
@@ -43,7 +64,7 @@ const DataViewTableBasic = (_a) => {
|
|
|
43
64
|
const cellIsObject = (0, DataViewTable_1.isDataViewTdObject)(cell);
|
|
44
65
|
return (react_1.default.createElement(react_table_1.Td, Object.assign({ key: colIndex }, (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));
|
|
45
66
|
})));
|
|
46
|
-
}))));
|
|
67
|
+
})))));
|
|
47
68
|
};
|
|
48
69
|
exports.DataViewTableBasic = DataViewTableBasic;
|
|
49
70
|
exports.default = exports.DataViewTableBasic;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
const react_2 = require("@testing-library/react");
|
|
8
8
|
const DataViewTableBasic_1 = require("./DataViewTableBasic");
|
|
9
|
+
const DataView_1 = __importDefault(require("../DataView/DataView"));
|
|
9
10
|
const repositories = [
|
|
10
11
|
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
11
12
|
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
@@ -24,4 +25,14 @@ describe('DataViewTable component', () => {
|
|
|
24
25
|
const { container } = (0, react_2.render)(react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
|
|
25
26
|
expect(container).toMatchSnapshot();
|
|
26
27
|
});
|
|
28
|
+
test('should render with an empty state', () => {
|
|
29
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.default, { activeState: "empty" },
|
|
30
|
+
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { empty: "No data found" }, rows: [] })));
|
|
31
|
+
expect(container).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
test('should render with an error state', () => {
|
|
34
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.default, { activeState: "error" },
|
|
35
|
+
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { error: "Some error" }, rows: [] })));
|
|
36
|
+
expect(container).toMatchSnapshot();
|
|
37
|
+
});
|
|
27
38
|
});
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTrTree } from '../DataViewTable';
|
|
4
|
+
import { DataViewState } from '../DataView/DataView';
|
|
4
5
|
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
5
6
|
/** Columns definition */
|
|
6
7
|
columns: DataViewTh[];
|
|
7
8
|
/** Current page rows */
|
|
8
9
|
rows: DataViewTrTree[];
|
|
10
|
+
/** States to be displayed when active */
|
|
11
|
+
states?: Partial<Record<DataViewState, React.ReactNode>>;
|
|
9
12
|
/** Optional icon for the leaf rows */
|
|
10
13
|
leafIcon?: React.ReactNode;
|
|
11
14
|
/** Optional icon for the expanded parent rows */
|
|
@@ -55,8 +55,8 @@ const isNodeChecked = (node, isSelected) => {
|
|
|
55
55
|
return allSelected;
|
|
56
56
|
};
|
|
57
57
|
const DataViewTableTree = (_a) => {
|
|
58
|
-
var { columns, rows, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
59
|
-
const { selection } = (0, InternalContext_1.useInternalContext)();
|
|
58
|
+
var { columns, rows, states = {}, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "states", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
59
|
+
const { selection, activeState } = (0, InternalContext_1.useInternalContext)();
|
|
60
60
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
61
61
|
const [expandedNodeIds, setExpandedNodeIds] = react_1.default.useState([]);
|
|
62
62
|
const [expandedDetailsNodeNames, setExpandedDetailsNodeIds] = react_1.default.useState([]);
|
|
@@ -92,7 +92,6 @@ const DataViewTableTree = (_a) => {
|
|
|
92
92
|
'aria-posinset': posinset,
|
|
93
93
|
'aria-setsize': (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
94
94
|
isChecked,
|
|
95
|
-
ouiaId: `${ouiaId}-tree-toggle-${node.id}`,
|
|
96
95
|
checkboxId: `checkbox_id_${(_c = node.id) === null || _c === void 0 ? void 0 : _c.toLowerCase().replace(/\s+/g, '_')}`,
|
|
97
96
|
icon,
|
|
98
97
|
},
|
|
@@ -101,7 +100,7 @@ const DataViewTableTree = (_a) => {
|
|
|
101
100
|
? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
|
|
102
101
|
: [];
|
|
103
102
|
return [
|
|
104
|
-
react_1.default.createElement(react_table_1.TreeRowWrapper, { key: node.id, row: { props: treeRow.props } }, node.row.map((cell, colIndex) => {
|
|
103
|
+
react_1.default.createElement(react_table_1.TreeRowWrapper, { key: node.id, row: { props: treeRow.props }, ouiaId: `${ouiaId}-tr-${rowIndex}` }, node.row.map((cell, colIndex) => {
|
|
105
104
|
var _a;
|
|
106
105
|
const cellIsObject = (0, DataViewTable_1.isDataViewTdObject)(cell);
|
|
107
106
|
return (react_1.default.createElement(react_table_1.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));
|
|
@@ -111,10 +110,22 @@ const DataViewTableTree = (_a) => {
|
|
|
111
110
|
];
|
|
112
111
|
};
|
|
113
112
|
return renderRows(rows);
|
|
114
|
-
}, [
|
|
113
|
+
}, [
|
|
114
|
+
rows,
|
|
115
|
+
expandedNodeIds,
|
|
116
|
+
expandedDetailsNodeNames,
|
|
117
|
+
leafIcon,
|
|
118
|
+
expandedIcon,
|
|
119
|
+
collapsedIcon,
|
|
120
|
+
isSelected,
|
|
121
|
+
onSelect,
|
|
122
|
+
isSelectDisabled,
|
|
123
|
+
ouiaId
|
|
124
|
+
]);
|
|
115
125
|
return (react_1.default.createElement(react_table_1.Table, Object.assign({ isTreeTable: true, "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
116
126
|
react_1.default.createElement(DataViewTableHeader_1.DataViewTableHeader, { isTreeTable: true, columns: columns, ouiaId: ouiaId }),
|
|
117
|
-
react_1.default.createElement(react_table_1.Tbody, null,
|
|
127
|
+
react_1.default.createElement(react_table_1.Tbody, null, activeState && Object.keys(states).includes(activeState) ? (react_1.default.createElement(react_table_1.Tr, { key: activeState, ouiaId: `${ouiaId}-tr-${activeState}` },
|
|
128
|
+
react_1.default.createElement(react_table_1.Td, { colSpan: columns.length }, states[activeState]))) : nodes)));
|
|
118
129
|
};
|
|
119
130
|
exports.DataViewTableTree = DataViewTableTree;
|
|
120
131
|
exports.default = exports.DataViewTableTree;
|
|
@@ -72,4 +72,14 @@ describe('DataViewTableTree component', () => {
|
|
|
72
72
|
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows, leafIcon: react_1.default.createElement(react_icons_1.LeafIcon, null), expandedIcon: react_1.default.createElement(react_icons_1.FolderOpenIcon, { "aria-hidden": true }), collapsedIcon: react_1.default.createElement(react_icons_1.FolderIcon, { "aria-hidden": true }) })));
|
|
73
73
|
expect(container).toMatchSnapshot();
|
|
74
74
|
});
|
|
75
|
+
test('should render tree table with an empty state', () => {
|
|
76
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "empty" },
|
|
77
|
+
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { empty: "No data found" }, rows: [] })));
|
|
78
|
+
expect(container).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
test('should render tree table with an error state', () => {
|
|
81
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "error" },
|
|
82
|
+
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { error: "Some error" }, rows: [] })));
|
|
83
|
+
expect(container).toMatchSnapshot();
|
|
84
|
+
});
|
|
75
85
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { DataViewState } from '../DataView';
|
|
2
3
|
export interface DataViewSelection {
|
|
3
4
|
/** Called when the selection of items changes */
|
|
4
5
|
onSelect: (isSelecting: boolean, items?: any[] | any) => void;
|
|
@@ -9,6 +10,7 @@ export interface DataViewSelection {
|
|
|
9
10
|
}
|
|
10
11
|
export interface InternalContextValue {
|
|
11
12
|
selection?: DataViewSelection;
|
|
13
|
+
activeState?: DataViewState;
|
|
12
14
|
}
|
|
13
15
|
export declare const InternalContext: React.Context<InternalContextValue>;
|
|
14
16
|
export type InternalProviderProps = PropsWithChildren<InternalContextValue>;
|
|
@@ -26,9 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.useInternalContext = exports.InternalContextProvider = exports.InternalContext = void 0;
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
exports.InternalContext = (0, react_1.createContext)({
|
|
29
|
-
selection: undefined
|
|
29
|
+
selection: undefined,
|
|
30
|
+
activeState: undefined
|
|
30
31
|
});
|
|
31
|
-
const InternalContextProvider = ({ children, selection }) => (react_1.default.createElement(exports.InternalContext.Provider, { value: { selection } }, children));
|
|
32
|
+
const InternalContextProvider = ({ children, selection, activeState }) => (react_1.default.createElement(exports.InternalContext.Provider, { value: { selection, activeState } }, children));
|
|
32
33
|
exports.InternalContextProvider = InternalContextProvider;
|
|
33
34
|
const useInternalContext = () => (0, react_1.useContext)(exports.InternalContext);
|
|
34
35
|
exports.useInternalContext = useInternalContext;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DataViewSelection } from '../InternalContext';
|
|
3
|
+
export declare const DataViewState: {
|
|
4
|
+
readonly empty: "empty";
|
|
5
|
+
readonly loading: "loading";
|
|
6
|
+
readonly error: "error";
|
|
7
|
+
};
|
|
8
|
+
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
3
9
|
export interface DataViewProps {
|
|
4
10
|
/** Content rendered inside the data view */
|
|
5
11
|
children: React.ReactNode;
|
|
@@ -7,6 +13,8 @@ export interface DataViewProps {
|
|
|
7
13
|
ouiaId?: string;
|
|
8
14
|
/** Selection context configuration */
|
|
9
15
|
selection?: DataViewSelection;
|
|
16
|
+
/** Currently active state */
|
|
17
|
+
activeState?: DataViewState;
|
|
10
18
|
}
|
|
11
19
|
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
12
20
|
export declare const DataView: React.FC<DataViewProps>;
|
|
@@ -12,13 +12,18 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { Stack, StackItem } from '@patternfly/react-core';
|
|
14
14
|
import { InternalContextProvider } from '../InternalContext';
|
|
15
|
+
export const DataViewState = {
|
|
16
|
+
empty: 'empty',
|
|
17
|
+
loading: 'loading',
|
|
18
|
+
error: 'error'
|
|
19
|
+
};
|
|
15
20
|
const DataViewImplementation = (_a) => {
|
|
16
21
|
var { children, ouiaId = 'DataView' } = _a, props = __rest(_a, ["children", "ouiaId"]);
|
|
17
|
-
return (React.createElement(Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack
|
|
22
|
+
return (React.createElement(Stack, Object.assign({ "data-ouia-component-id": `${ouiaId}-stack` }, props), React.Children.map(children, (child, index) => (React.createElement(StackItem, { "data-ouia-component-id": `${ouiaId}-stack-item-${index}` }, child)))));
|
|
18
23
|
};
|
|
19
24
|
export const DataView = (_a) => {
|
|
20
|
-
var { children, selection } = _a, props = __rest(_a, ["children", "selection"]);
|
|
21
|
-
return (React.createElement(InternalContextProvider, { selection: selection },
|
|
25
|
+
var { children, selection, activeState } = _a, props = __rest(_a, ["children", "selection", "activeState"]);
|
|
26
|
+
return (React.createElement(InternalContextProvider, { selection: selection, activeState: activeState },
|
|
22
27
|
React.createElement(DataViewImplementation, Object.assign({}, props), children)));
|
|
23
28
|
};
|
|
24
29
|
export default DataView;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTr } from '../DataViewTable';
|
|
4
|
+
import { DataViewState } from '../DataView/DataView';
|
|
4
5
|
export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
5
6
|
/** Columns definition */
|
|
6
7
|
columns: DataViewTh[];
|
|
7
8
|
/** Current page rows */
|
|
8
9
|
rows: DataViewTr[];
|
|
10
|
+
/** States to be displayed when active */
|
|
11
|
+
states?: Partial<Record<DataViewState, React.ReactNode>>;
|
|
9
12
|
/** Custom OUIA ID */
|
|
10
13
|
ouiaId?: string;
|
|
11
14
|
}
|
|
@@ -9,22 +9,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React from 'react';
|
|
12
|
+
import React, { useMemo } from 'react';
|
|
13
13
|
import { Table, Tbody, Td, Tr, } from '@patternfly/react-table';
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
15
|
import { DataViewTableHeader } from '../DataViewTableHeader';
|
|
16
16
|
import { isDataViewTdObject, isDataViewTrObject } from '../DataViewTable';
|
|
17
17
|
export const DataViewTableBasic = (_a) => {
|
|
18
|
-
var { columns, rows, ouiaId = 'DataViewTableBasic' } = _a, props = __rest(_a, ["columns", "rows", "ouiaId"]);
|
|
19
|
-
const { selection } = useInternalContext();
|
|
18
|
+
var { columns, rows, ouiaId = 'DataViewTableBasic', states = {} } = _a, props = __rest(_a, ["columns", "rows", "ouiaId", "states"]);
|
|
19
|
+
const { selection, activeState } = useInternalContext();
|
|
20
20
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
21
|
+
const isSelectable = useMemo(() => Boolean(onSelect && isSelected), [onSelect, isSelected]);
|
|
21
22
|
return (React.createElement(Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
22
23
|
React.createElement(DataViewTableHeader, { columns: columns, ouiaId: ouiaId }),
|
|
23
|
-
React.createElement(Tbody, null,
|
|
24
|
-
|
|
24
|
+
React.createElement(Tbody, null, activeState && Object.keys(states).includes(activeState) ? (React.createElement(Tr, { key: activeState, ouiaId: `${ouiaId}-tr-${activeState}` },
|
|
25
|
+
React.createElement(Td, { colSpan: columns.length + Number(isSelectable) }, states[activeState]))) : (rows.map((row, rowIndex) => {
|
|
25
26
|
const rowIsObject = isDataViewTrObject(row);
|
|
26
|
-
return (React.createElement(Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (
|
|
27
|
-
|
|
27
|
+
return (React.createElement(Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props))),
|
|
28
|
+
isSelectable && (React.createElement(Td, { key: `select-${rowIndex}`, select: {
|
|
28
29
|
rowIndex,
|
|
29
30
|
onSelect: (_event, isSelecting) => {
|
|
30
31
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
@@ -37,6 +38,6 @@ export const DataViewTableBasic = (_a) => {
|
|
|
37
38
|
const cellIsObject = isDataViewTdObject(cell);
|
|
38
39
|
return (React.createElement(Td, Object.assign({ key: colIndex }, (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));
|
|
39
40
|
})));
|
|
40
|
-
}))));
|
|
41
|
+
})))));
|
|
41
42
|
};
|
|
42
43
|
export default DataViewTableBasic;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { DataViewTableBasic } from './DataViewTableBasic';
|
|
4
|
+
import DataView from '../DataView/DataView';
|
|
4
5
|
const repositories = [
|
|
5
6
|
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
6
7
|
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
@@ -19,4 +20,14 @@ describe('DataViewTable component', () => {
|
|
|
19
20
|
const { container } = render(React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
|
|
20
21
|
expect(container).toMatchSnapshot();
|
|
21
22
|
});
|
|
23
|
+
test('should render with an empty state', () => {
|
|
24
|
+
const { container } = render(React.createElement(DataView, { activeState: "empty" },
|
|
25
|
+
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { empty: "No data found" }, rows: [] })));
|
|
26
|
+
expect(container).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
test('should render with an error state', () => {
|
|
29
|
+
const { container } = render(React.createElement(DataView, { activeState: "error" },
|
|
30
|
+
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { error: "Some error" }, rows: [] })));
|
|
31
|
+
expect(container).toMatchSnapshot();
|
|
32
|
+
});
|
|
22
33
|
});
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh, DataViewTrTree } from '../DataViewTable';
|
|
4
|
+
import { DataViewState } from '../DataView/DataView';
|
|
4
5
|
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
5
6
|
/** Columns definition */
|
|
6
7
|
columns: DataViewTh[];
|
|
7
8
|
/** Current page rows */
|
|
8
9
|
rows: DataViewTrTree[];
|
|
10
|
+
/** States to be displayed when active */
|
|
11
|
+
states?: Partial<Record<DataViewState, React.ReactNode>>;
|
|
9
12
|
/** Optional icon for the leaf rows */
|
|
10
13
|
leafIcon?: React.ReactNode;
|
|
11
14
|
/** Optional icon for the expanded parent rows */
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { useMemo } from 'react';
|
|
13
|
-
import { Table, Tbody, Td, TreeRowWrapper, } from '@patternfly/react-table';
|
|
13
|
+
import { Table, Tbody, Td, Tr, TreeRowWrapper, } from '@patternfly/react-table';
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
15
|
import { DataViewTableHeader } from '../DataViewTableHeader';
|
|
16
16
|
import { isDataViewTdObject } from '../DataViewTable';
|
|
@@ -29,8 +29,8 @@ const isNodeChecked = (node, isSelected) => {
|
|
|
29
29
|
return allSelected;
|
|
30
30
|
};
|
|
31
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();
|
|
32
|
+
var { columns, rows, states = {}, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "states", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
33
|
+
const { selection, activeState } = useInternalContext();
|
|
34
34
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
35
35
|
const [expandedNodeIds, setExpandedNodeIds] = React.useState([]);
|
|
36
36
|
const [expandedDetailsNodeNames, setExpandedDetailsNodeIds] = React.useState([]);
|
|
@@ -66,7 +66,6 @@ export const DataViewTableTree = (_a) => {
|
|
|
66
66
|
'aria-posinset': posinset,
|
|
67
67
|
'aria-setsize': (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
68
68
|
isChecked,
|
|
69
|
-
ouiaId: `${ouiaId}-tree-toggle-${node.id}`,
|
|
70
69
|
checkboxId: `checkbox_id_${(_c = node.id) === null || _c === void 0 ? void 0 : _c.toLowerCase().replace(/\s+/g, '_')}`,
|
|
71
70
|
icon,
|
|
72
71
|
},
|
|
@@ -75,7 +74,7 @@ export const DataViewTableTree = (_a) => {
|
|
|
75
74
|
? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
|
|
76
75
|
: [];
|
|
77
76
|
return [
|
|
78
|
-
React.createElement(TreeRowWrapper, { key: node.id, row: { props: treeRow.props } }, node.row.map((cell, colIndex) => {
|
|
77
|
+
React.createElement(TreeRowWrapper, { key: node.id, row: { props: treeRow.props }, ouiaId: `${ouiaId}-tr-${rowIndex}` }, node.row.map((cell, colIndex) => {
|
|
79
78
|
var _a;
|
|
80
79
|
const cellIsObject = isDataViewTdObject(cell);
|
|
81
80
|
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));
|
|
@@ -85,9 +84,21 @@ export const DataViewTableTree = (_a) => {
|
|
|
85
84
|
];
|
|
86
85
|
};
|
|
87
86
|
return renderRows(rows);
|
|
88
|
-
}, [
|
|
87
|
+
}, [
|
|
88
|
+
rows,
|
|
89
|
+
expandedNodeIds,
|
|
90
|
+
expandedDetailsNodeNames,
|
|
91
|
+
leafIcon,
|
|
92
|
+
expandedIcon,
|
|
93
|
+
collapsedIcon,
|
|
94
|
+
isSelected,
|
|
95
|
+
onSelect,
|
|
96
|
+
isSelectDisabled,
|
|
97
|
+
ouiaId
|
|
98
|
+
]);
|
|
89
99
|
return (React.createElement(Table, Object.assign({ isTreeTable: true, "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
90
100
|
React.createElement(DataViewTableHeader, { isTreeTable: true, columns: columns, ouiaId: ouiaId }),
|
|
91
|
-
React.createElement(Tbody, null,
|
|
101
|
+
React.createElement(Tbody, null, activeState && Object.keys(states).includes(activeState) ? (React.createElement(Tr, { key: activeState, ouiaId: `${ouiaId}-tr-${activeState}` },
|
|
102
|
+
React.createElement(Td, { colSpan: columns.length }, states[activeState]))) : nodes)));
|
|
92
103
|
};
|
|
93
104
|
export default DataViewTableTree;
|
|
@@ -67,4 +67,14 @@ describe('DataViewTableTree component', () => {
|
|
|
67
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
68
|
expect(container).toMatchSnapshot();
|
|
69
69
|
});
|
|
70
|
+
test('should render tree table with an empty state', () => {
|
|
71
|
+
const { container } = render(React.createElement(DataView, { activeState: "empty" },
|
|
72
|
+
React.createElement(DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { empty: "No data found" }, rows: [] })));
|
|
73
|
+
expect(container).toMatchSnapshot();
|
|
74
|
+
});
|
|
75
|
+
test('should render tree table with an error state', () => {
|
|
76
|
+
const { container } = render(React.createElement(DataView, { activeState: "error" },
|
|
77
|
+
React.createElement(DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, states: { error: "Some error" }, rows: [] })));
|
|
78
|
+
expect(container).toMatchSnapshot();
|
|
79
|
+
});
|
|
70
80
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { DataViewState } from '../DataView';
|
|
2
3
|
export interface DataViewSelection {
|
|
3
4
|
/** Called when the selection of items changes */
|
|
4
5
|
onSelect: (isSelecting: boolean, items?: any[] | any) => void;
|
|
@@ -9,6 +10,7 @@ export interface DataViewSelection {
|
|
|
9
10
|
}
|
|
10
11
|
export interface InternalContextValue {
|
|
11
12
|
selection?: DataViewSelection;
|
|
13
|
+
activeState?: DataViewState;
|
|
12
14
|
}
|
|
13
15
|
export declare const InternalContext: React.Context<InternalContextValue>;
|
|
14
16
|
export type InternalProviderProps = PropsWithChildren<InternalContextValue>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { createContext, useContext } from 'react';
|
|
2
2
|
export const InternalContext = createContext({
|
|
3
|
-
selection: undefined
|
|
3
|
+
selection: undefined,
|
|
4
|
+
activeState: undefined
|
|
4
5
|
});
|
|
5
|
-
export const InternalContextProvider = ({ children, selection }) => (React.createElement(InternalContext.Provider, { value: { selection } }, children));
|
|
6
|
+
export const InternalContextProvider = ({ children, selection, activeState }) => (React.createElement(InternalContext.Provider, { value: { selection, activeState } }, children));
|
|
6
7
|
export const useInternalContext = () => useContext(InternalContext);
|
|
7
8
|
export default InternalContext;
|
package/package.json
CHANGED
|
@@ -14,12 +14,13 @@ sortValue: 4
|
|
|
14
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 {
|
|
18
|
-
import {
|
|
17
|
+
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateIcon } from '@patternfly/react-core';
|
|
18
|
+
import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
|
|
19
|
+
import { BulkSelect, ErrorState } from '@patternfly/react-component-groups';
|
|
19
20
|
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
20
21
|
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
21
22
|
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
22
|
-
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
23
|
+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
23
24
|
|
|
24
25
|
## Data view toolbar
|
|
25
26
|
|
|
@@ -71,3 +72,17 @@ It is also possible to disable row selection using the `isSelectDisabled` functi
|
|
|
71
72
|
```js file="./DataViewTableTreeExample.tsx"
|
|
72
73
|
|
|
73
74
|
```
|
|
75
|
+
|
|
76
|
+
### Empty state example
|
|
77
|
+
The data view table supports displaying a custom empty state. You can pass it using the `states` property and `empty` key. It will be automatically displayed in case there are no rows to be rendered.
|
|
78
|
+
|
|
79
|
+
```js file="./DataViewTableEmptyExample.tsx"
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Error state example
|
|
84
|
+
The data view table also supports displaying an error state. You can pass it using the `states` property and `error` key. It will be displayed in case the data view recieves its `state` property set to `error`.
|
|
85
|
+
|
|
86
|
+
```js file="./DataViewTableErrorExample.tsx"
|
|
87
|
+
|
|
88
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
3
|
+
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
4
|
+
import { CubesIcon } from '@patternfly/react-icons';
|
|
5
|
+
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateIcon } from '@patternfly/react-core';
|
|
6
|
+
|
|
7
|
+
interface Repository {
|
|
8
|
+
id: number;
|
|
9
|
+
name: string;
|
|
10
|
+
branches: string | null;
|
|
11
|
+
prs: string | null;
|
|
12
|
+
workspaces: string;
|
|
13
|
+
lastCommit: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const repositories: Repository[] = [];
|
|
17
|
+
|
|
18
|
+
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
|
|
19
|
+
const rows: DataViewTr[] = repositories.map((repository) => Object.values(repository));
|
|
20
|
+
|
|
21
|
+
const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
22
|
+
|
|
23
|
+
const ouiaId = 'TableExample';
|
|
24
|
+
|
|
25
|
+
const empty = (
|
|
26
|
+
<EmptyState>
|
|
27
|
+
<EmptyStateHeader titleText="No data found" headingLevel="h4" icon={<EmptyStateIcon icon={CubesIcon} />} />
|
|
28
|
+
<EmptyStateBody>There are no matching data to be displayed.</EmptyStateBody>
|
|
29
|
+
<EmptyStateFooter>
|
|
30
|
+
<EmptyStateActions>
|
|
31
|
+
<Button variant="primary">Primary action</Button>
|
|
32
|
+
</EmptyStateActions>
|
|
33
|
+
<EmptyStateActions>
|
|
34
|
+
<Button variant="link">Multiple</Button>
|
|
35
|
+
<Button variant="link">Action Buttons</Button>
|
|
36
|
+
</EmptyStateActions>
|
|
37
|
+
</EmptyStateFooter>
|
|
38
|
+
</EmptyState>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
42
|
+
<DataView activeState={DataViewState.empty}>
|
|
43
|
+
<DataViewTable
|
|
44
|
+
aria-label='Repositories table'
|
|
45
|
+
ouiaId={ouiaId}
|
|
46
|
+
columns={columns}
|
|
47
|
+
rows={rows}
|
|
48
|
+
states={{ empty }}
|
|
49
|
+
/>
|
|
50
|
+
</DataView>
|
|
51
|
+
);
|