@patternfly/react-data-view 5.3.0 → 5.4.1
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 +4 -2
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +4 -2
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +24 -23
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +10 -5
- package/dist/cjs/{DataViewTableHeader/DataViewTableHeader.d.ts → DataViewTableHead/DataViewTableHead.d.ts} +3 -3
- package/dist/cjs/{DataViewTableHeader/DataViewTableHeader.js → DataViewTableHead/DataViewTableHead.js} +6 -6
- package/dist/cjs/{DataViewTableHeader/DataViewTableHeader.test.js → DataViewTableHead/DataViewTableHead.test.js} +5 -5
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/{DataViewTableHeader → DataViewTableHead}/index.js +3 -3
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +4 -2
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +6 -5
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +7 -2
- package/dist/cjs/InternalContext/InternalContext.d.ts +9 -3
- package/dist/cjs/InternalContext/InternalContext.js +6 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +4 -4
- package/dist/dynamic/DataViewTableHead/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +4 -2
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +4 -2
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +24 -23
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +8 -3
- package/dist/esm/{DataViewTableHeader/DataViewTableHeader.d.ts → DataViewTableHead/DataViewTableHead.d.ts} +3 -3
- package/dist/esm/{DataViewTableHeader/DataViewTableHeader.js → DataViewTableHead/DataViewTableHead.js} +4 -4
- package/dist/esm/{DataViewTableHeader/DataViewTableHeader.test.js → DataViewTableHead/DataViewTableHead.test.js} +5 -5
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +4 -2
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +7 -6
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +7 -2
- package/dist/esm/InternalContext/InternalContext.d.ts +9 -3
- package/dist/esm/InternalContext/InternalContext.js +7 -3
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +17 -8
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +21 -14
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +9 -2
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +1 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +27 -5
- package/src/DataView/DataView.tsx +4 -3
- package/src/DataViewTable/DataViewTable.tsx +1 -1
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +12 -3
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +46 -48
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +71 -30
- package/src/{DataViewTableHeader/DataViewTableHeader.test.tsx → DataViewTableHead/DataViewTableHead.test.tsx} +5 -7
- package/src/{DataViewTableHeader/DataViewTableHeader.tsx → DataViewTableHead/DataViewTableHead.tsx} +6 -6
- package/src/{DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap → DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap} +4 -4
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +11 -2
- package/src/DataViewTableTree/DataViewTableTree.tsx +12 -16
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +71 -30
- package/src/InternalContext/InternalContext.tsx +24 -12
- package/src/index.ts +2 -2
- package/dist/cjs/DataViewTableHeader/index.d.ts +0 -2
- package/dist/dynamic/DataViewTableHeader/package.json +0 -1
- package/dist/esm/DataViewTableHeader/index.d.ts +0 -2
- package/dist/esm/DataViewTableHeader/index.js +0 -2
- package/src/DataViewTableHeader/index.ts +0 -2
- /package/dist/cjs/{DataViewTableHeader/DataViewTableHeader.test.d.ts → DataViewTableHead/DataViewTableHead.test.d.ts} +0 -0
- /package/dist/esm/{DataViewTableHeader/DataViewTableHeader.test.d.ts → DataViewTableHead/DataViewTableHead.test.d.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { StackProps } from '@patternfly/react-core';
|
|
2
3
|
import { DataViewSelection } from '../InternalContext';
|
|
3
4
|
export declare const DataViewState: {
|
|
4
5
|
readonly empty: "empty";
|
|
@@ -6,7 +7,8 @@ export declare const DataViewState: {
|
|
|
6
7
|
readonly error: "error";
|
|
7
8
|
};
|
|
8
9
|
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
9
|
-
|
|
10
|
+
/** extends StackProps */
|
|
11
|
+
export interface DataViewProps extends StackProps {
|
|
10
12
|
/** Content rendered inside the data view */
|
|
11
13
|
children: React.ReactNode;
|
|
12
14
|
/** Custom OUIA ID */
|
|
@@ -14,7 +16,7 @@ export interface DataViewProps {
|
|
|
14
16
|
/** Selection context configuration */
|
|
15
17
|
selection?: DataViewSelection;
|
|
16
18
|
/** Currently active state */
|
|
17
|
-
activeState?: DataViewState;
|
|
19
|
+
activeState?: DataViewState | string;
|
|
18
20
|
}
|
|
19
21
|
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
20
22
|
export declare const DataView: React.FC<DataViewProps>;
|
|
@@ -7,8 +7,10 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
|
|
|
7
7
|
columns: DataViewTh[];
|
|
8
8
|
/** Current page rows */
|
|
9
9
|
rows: DataViewTr[];
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Table head states to be displayed when active */
|
|
11
|
+
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
|
+
/** Table body states to be displayed when active */
|
|
13
|
+
bodyStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
14
|
/** Custom OUIA ID */
|
|
13
15
|
ouiaId?: string;
|
|
14
16
|
}
|
|
@@ -38,33 +38,34 @@ exports.DataViewTableBasic = void 0;
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const react_table_1 = require("@patternfly/react-table");
|
|
40
40
|
const InternalContext_1 = require("../InternalContext");
|
|
41
|
-
const
|
|
41
|
+
const DataViewTableHead_1 = require("../DataViewTableHead");
|
|
42
42
|
const DataViewTable_1 = require("../DataViewTable");
|
|
43
43
|
const DataViewTableBasic = (_a) => {
|
|
44
|
-
var { columns, rows, ouiaId = 'DataViewTableBasic',
|
|
45
|
-
const { selection, activeState } = (0, InternalContext_1.useInternalContext)();
|
|
44
|
+
var { columns, rows, ouiaId = 'DataViewTableBasic', headStates, bodyStates } = _a, props = __rest(_a, ["columns", "rows", "ouiaId", "headStates", "bodyStates"]);
|
|
45
|
+
const { selection, activeState, isSelectable } = (0, InternalContext_1.useInternalContext)();
|
|
46
46
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
47
|
-
const
|
|
47
|
+
const activeHeadState = (0, react_1.useMemo)(() => activeState ? headStates === null || headStates === void 0 ? void 0 : headStates[activeState] : undefined, [activeState, headStates]);
|
|
48
|
+
const activeBodyState = (0, react_1.useMemo)(() => activeState ? bodyStates === null || bodyStates === void 0 ? void 0 : bodyStates[activeState] : undefined, [activeState, bodyStates]);
|
|
49
|
+
const renderedRows = (0, react_1.useMemo)(() => rows.map((row, rowIndex) => {
|
|
50
|
+
const rowIsObject = (0, DataViewTable_1.isDataViewTrObject)(row);
|
|
51
|
+
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))),
|
|
52
|
+
isSelectable && (react_1.default.createElement(react_table_1.Td, { key: `select-${rowIndex}`, select: {
|
|
53
|
+
rowIndex,
|
|
54
|
+
onSelect: (_event, isSelecting) => {
|
|
55
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
56
|
+
},
|
|
57
|
+
isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
|
|
58
|
+
isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
|
|
59
|
+
} })),
|
|
60
|
+
(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
61
|
+
var _a;
|
|
62
|
+
const cellIsObject = (0, DataViewTable_1.isDataViewTdObject)(cell);
|
|
63
|
+
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));
|
|
64
|
+
})));
|
|
65
|
+
}), [rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId]);
|
|
48
66
|
return (react_1.default.createElement(react_table_1.Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
49
|
-
react_1.default.createElement(
|
|
50
|
-
react_1.default.createElement(react_table_1.Tbody, null,
|
|
51
|
-
react_1.default.createElement(react_table_1.Td, { colSpan: columns.length + Number(isSelectable) }, states[activeState]))) : (rows.map((row, rowIndex) => {
|
|
52
|
-
const rowIsObject = (0, DataViewTable_1.isDataViewTrObject)(row);
|
|
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: {
|
|
55
|
-
rowIndex,
|
|
56
|
-
onSelect: (_event, isSelecting) => {
|
|
57
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
58
|
-
},
|
|
59
|
-
isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
|
|
60
|
-
isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
|
|
61
|
-
} })),
|
|
62
|
-
(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
63
|
-
var _a;
|
|
64
|
-
const cellIsObject = (0, DataViewTable_1.isDataViewTdObject)(cell);
|
|
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));
|
|
66
|
-
})));
|
|
67
|
-
})))));
|
|
67
|
+
activeHeadState || react_1.default.createElement(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId }),
|
|
68
|
+
activeBodyState || react_1.default.createElement(react_table_1.Tbody, null, renderedRows)));
|
|
68
69
|
};
|
|
69
70
|
exports.DataViewTableBasic = DataViewTableBasic;
|
|
70
71
|
exports.default = exports.DataViewTableBasic;
|
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
const react_2 = require("@testing-library/react");
|
|
8
|
+
const DataView_1 = require("../DataView");
|
|
8
9
|
const DataViewTableBasic_1 = require("./DataViewTableBasic");
|
|
9
|
-
const DataView_1 = __importDefault(require("../DataView/DataView"));
|
|
10
10
|
const repositories = [
|
|
11
11
|
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
12
12
|
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
@@ -26,13 +26,18 @@ describe('DataViewTable component', () => {
|
|
|
26
26
|
expect(container).toMatchSnapshot();
|
|
27
27
|
});
|
|
28
28
|
test('should render with an empty state', () => {
|
|
29
|
-
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.
|
|
30
|
-
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns,
|
|
29
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "empty" },
|
|
30
|
+
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { empty: "No data found" }, rows: [] })));
|
|
31
31
|
expect(container).toMatchSnapshot();
|
|
32
32
|
});
|
|
33
33
|
test('should render with an error state', () => {
|
|
34
|
-
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.
|
|
35
|
-
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns,
|
|
34
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "error" },
|
|
35
|
+
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { error: "Some error" }, rows: [] })));
|
|
36
|
+
expect(container).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
test('should render with a loading state', () => {
|
|
39
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "loading" },
|
|
40
|
+
react_1.default.createElement(DataViewTableBasic_1.DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] })));
|
|
36
41
|
expect(container).toMatchSnapshot();
|
|
37
42
|
});
|
|
38
43
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TheadProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh } from '../DataViewTable';
|
|
4
|
-
export interface
|
|
4
|
+
export interface DataViewTableHeadProps extends TheadProps {
|
|
5
5
|
/** Indicates whether table is a tree */
|
|
6
6
|
isTreeTable?: boolean;
|
|
7
7
|
/** Columns definition */
|
|
@@ -9,5 +9,5 @@ export interface DataViewTableHeaderProps extends TheadProps {
|
|
|
9
9
|
/** Custom OUIA ID */
|
|
10
10
|
ouiaId?: string;
|
|
11
11
|
}
|
|
12
|
-
export declare const
|
|
13
|
-
export default
|
|
12
|
+
export declare const DataViewTableHead: React.FC<DataViewTableHeadProps>;
|
|
13
|
+
export default DataViewTableHead;
|
|
@@ -34,17 +34,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.
|
|
37
|
+
exports.DataViewTableHead = void 0;
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const react_table_1 = require("@patternfly/react-table");
|
|
40
40
|
const InternalContext_1 = require("../InternalContext");
|
|
41
41
|
const DataViewTable_1 = require("../DataViewTable");
|
|
42
|
-
const
|
|
43
|
-
var { isTreeTable = false, columns, ouiaId = '
|
|
42
|
+
const DataViewTableHead = (_a) => {
|
|
43
|
+
var { isTreeTable = false, columns, ouiaId = 'DataViewTableHead' } = _a, props = __rest(_a, ["isTreeTable", "columns", "ouiaId"]);
|
|
44
44
|
const { selection } = (0, InternalContext_1.useInternalContext)();
|
|
45
45
|
const { onSelect, isSelected } = selection !== null && selection !== void 0 ? selection : {};
|
|
46
46
|
const cells = (0, react_1.useMemo)(() => [
|
|
47
|
-
onSelect && isSelected && !isTreeTable ? (react_1.default.createElement(react_table_1.Th, { key: "row-select", screenReaderText: 'Data selection table
|
|
47
|
+
onSelect && isSelected && !isTreeTable ? (react_1.default.createElement(react_table_1.Th, { key: "row-select", screenReaderText: 'Data selection table head cell' })) : null,
|
|
48
48
|
...columns.map((column, index) => {
|
|
49
49
|
var _a;
|
|
50
50
|
return (react_1.default.createElement(react_table_1.Th, Object.assign({ key: index }, ((0, DataViewTable_1.isDataViewThObject)(column) && ((_a = column === null || column === void 0 ? void 0 : column.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-th-${index}` }), (0, DataViewTable_1.isDataViewThObject)(column) ? column.cell : column));
|
|
@@ -53,5 +53,5 @@ const DataViewTableHeader = (_a) => {
|
|
|
53
53
|
return (react_1.default.createElement(react_table_1.Thead, Object.assign({ "data-ouia-component-id": `${ouiaId}-thead` }, props),
|
|
54
54
|
react_1.default.createElement(react_table_1.Tr, { ouiaId: `${ouiaId}-tr-head` }, cells)));
|
|
55
55
|
};
|
|
56
|
-
exports.
|
|
57
|
-
exports.default = exports.
|
|
56
|
+
exports.DataViewTableHead = DataViewTableHead;
|
|
57
|
+
exports.default = exports.DataViewTableHead;
|
|
@@ -6,11 +6,11 @@ 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 react_table_1 = require("@patternfly/react-table");
|
|
9
|
-
const
|
|
9
|
+
const DataViewTableHead_1 = require("./DataViewTableHead");
|
|
10
10
|
const DataView_1 = require("../DataView");
|
|
11
11
|
const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
|
|
12
12
|
const ouiaId = 'HeaderExample';
|
|
13
|
-
describe('
|
|
13
|
+
describe('DataViewTableHead component', () => {
|
|
14
14
|
const mockSelection = {
|
|
15
15
|
onSelect: jest.fn(),
|
|
16
16
|
isSelected: jest.fn(),
|
|
@@ -18,19 +18,19 @@ describe('DataViewTableHeader component', () => {
|
|
|
18
18
|
};
|
|
19
19
|
test('should render correctly', () => {
|
|
20
20
|
const { container } = (0, react_2.render)(react_1.default.createElement(react_table_1.Table, null,
|
|
21
|
-
react_1.default.createElement(
|
|
21
|
+
react_1.default.createElement(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId })));
|
|
22
22
|
expect(container).toMatchSnapshot();
|
|
23
23
|
});
|
|
24
24
|
test('should render the tree table correctly when isTreeTable is true', () => {
|
|
25
25
|
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelection },
|
|
26
26
|
react_1.default.createElement(react_table_1.Table, null,
|
|
27
|
-
react_1.default.createElement(
|
|
27
|
+
react_1.default.createElement(DataViewTableHead_1.DataViewTableHead, { isTreeTable: true, columns: columns, ouiaId: ouiaId }))));
|
|
28
28
|
expect(container).toMatchSnapshot();
|
|
29
29
|
});
|
|
30
30
|
test('should render selection column when selection is provided', () => {
|
|
31
31
|
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelection },
|
|
32
32
|
react_1.default.createElement(react_table_1.Table, null,
|
|
33
|
-
react_1.default.createElement(
|
|
33
|
+
react_1.default.createElement(DataViewTableHead_1.DataViewTableHead, { columns: columns, ouiaId: ouiaId }))));
|
|
34
34
|
expect(container).toMatchSnapshot();
|
|
35
35
|
});
|
|
36
36
|
});
|
|
@@ -18,6 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.default = void 0;
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(
|
|
23
|
-
__exportStar(require("./
|
|
21
|
+
var DataViewTableHead_1 = require("./DataViewTableHead");
|
|
22
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(DataViewTableHead_1).default; } });
|
|
23
|
+
__exportStar(require("./DataViewTableHead"), exports);
|
|
@@ -7,8 +7,10 @@ export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'r
|
|
|
7
7
|
columns: DataViewTh[];
|
|
8
8
|
/** Current page rows */
|
|
9
9
|
rows: DataViewTrTree[];
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Table head states to be displayed when active */
|
|
11
|
+
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
|
+
/** Table body states to be displayed when active */
|
|
13
|
+
bodyStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
14
|
/** Optional icon for the leaf rows */
|
|
13
15
|
leafIcon?: React.ReactNode;
|
|
14
16
|
/** Optional icon for the expanded parent rows */
|
|
@@ -38,7 +38,7 @@ exports.DataViewTableTree = void 0;
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const react_table_1 = require("@patternfly/react-table");
|
|
40
40
|
const InternalContext_1 = require("../InternalContext");
|
|
41
|
-
const
|
|
41
|
+
const DataViewTableHead_1 = require("../DataViewTableHead");
|
|
42
42
|
const DataViewTable_1 = require("../DataViewTable");
|
|
43
43
|
const getDescendants = (node) => (!node.children || !node.children.length) ? [node] : node.children.flatMap(getDescendants);
|
|
44
44
|
const isNodeChecked = (node, isSelected) => {
|
|
@@ -55,11 +55,13 @@ const isNodeChecked = (node, isSelected) => {
|
|
|
55
55
|
return allSelected;
|
|
56
56
|
};
|
|
57
57
|
const DataViewTableTree = (_a) => {
|
|
58
|
-
var { columns, rows,
|
|
58
|
+
var { columns, rows, headStates, bodyStates, leafIcon = null, expandedIcon = null, collapsedIcon = null, ouiaId = 'DataViewTableTree' } = _a, props = __rest(_a, ["columns", "rows", "headStates", "bodyStates", "leafIcon", "expandedIcon", "collapsedIcon", "ouiaId"]);
|
|
59
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([]);
|
|
63
|
+
const activeHeadState = (0, react_1.useMemo)(() => activeState ? headStates === null || headStates === void 0 ? void 0 : headStates[activeState] : undefined, [activeState, headStates]);
|
|
64
|
+
const activeBodyState = (0, react_1.useMemo)(() => activeState ? bodyStates === null || bodyStates === void 0 ? void 0 : bodyStates[activeState] : undefined, [activeState, bodyStates]);
|
|
63
65
|
const nodes = (0, react_1.useMemo)(() => {
|
|
64
66
|
const renderRows = ([node, ...remainingNodes], level = 1, posinset = 1, rowIndex = 0, isHidden = false) => {
|
|
65
67
|
var _a, _b, _c, _d;
|
|
@@ -123,9 +125,8 @@ const DataViewTableTree = (_a) => {
|
|
|
123
125
|
ouiaId
|
|
124
126
|
]);
|
|
125
127
|
return (react_1.default.createElement(react_table_1.Table, Object.assign({ isTreeTable: true, "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
126
|
-
react_1.default.createElement(
|
|
127
|
-
react_1.default.createElement(react_table_1.Tbody, null,
|
|
128
|
-
react_1.default.createElement(react_table_1.Td, { colSpan: columns.length }, states[activeState]))) : nodes)));
|
|
128
|
+
activeHeadState || react_1.default.createElement(DataViewTableHead_1.DataViewTableHead, { isTreeTable: true, columns: columns, ouiaId: ouiaId }),
|
|
129
|
+
activeBodyState || react_1.default.createElement(react_table_1.Tbody, null, nodes)));
|
|
129
130
|
};
|
|
130
131
|
exports.DataViewTableTree = DataViewTableTree;
|
|
131
132
|
exports.default = exports.DataViewTableTree;
|
|
@@ -74,12 +74,17 @@ describe('DataViewTableTree component', () => {
|
|
|
74
74
|
});
|
|
75
75
|
test('should render tree table with an empty state', () => {
|
|
76
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,
|
|
77
|
+
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { empty: "No data found" }, rows: [] })));
|
|
78
78
|
expect(container).toMatchSnapshot();
|
|
79
79
|
});
|
|
80
80
|
test('should render tree table with an error state', () => {
|
|
81
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,
|
|
82
|
+
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { error: "Some error" }, rows: [] })));
|
|
83
|
+
expect(container).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
test('should render tree table with a loading state', () => {
|
|
86
|
+
const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { activeState: "loading" },
|
|
87
|
+
react_1.default.createElement(DataViewTable_1.DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] })));
|
|
83
88
|
expect(container).toMatchSnapshot();
|
|
84
89
|
});
|
|
85
90
|
});
|
|
@@ -8,12 +8,18 @@ export interface DataViewSelection {
|
|
|
8
8
|
/** Determines if selection is disabled for a given item */
|
|
9
9
|
isSelectDisabled?: (item: any) => boolean;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
11
|
+
export interface InternalContextProps {
|
|
12
|
+
/** Data selection props */
|
|
12
13
|
selection?: DataViewSelection;
|
|
13
|
-
|
|
14
|
+
/** Currently active state */
|
|
15
|
+
activeState?: DataViewState | string;
|
|
16
|
+
}
|
|
17
|
+
export interface InternalContextValue extends InternalContextProps {
|
|
18
|
+
/** Flag indicating if data view is selectable (auto-calculated) */
|
|
19
|
+
isSelectable: boolean;
|
|
14
20
|
}
|
|
15
21
|
export declare const InternalContext: React.Context<InternalContextValue>;
|
|
16
|
-
export type InternalProviderProps = PropsWithChildren<
|
|
22
|
+
export type InternalProviderProps = PropsWithChildren<InternalContextProps>;
|
|
17
23
|
export declare const InternalContextProvider: React.FC<InternalProviderProps>;
|
|
18
24
|
export declare const useInternalContext: () => InternalContextValue;
|
|
19
25
|
export default InternalContext;
|
|
@@ -27,9 +27,13 @@ exports.useInternalContext = exports.InternalContextProvider = exports.InternalC
|
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
exports.InternalContext = (0, react_1.createContext)({
|
|
29
29
|
selection: undefined,
|
|
30
|
-
activeState: undefined
|
|
30
|
+
activeState: undefined,
|
|
31
|
+
isSelectable: false,
|
|
31
32
|
});
|
|
32
|
-
const InternalContextProvider = ({ children, selection, activeState }) =>
|
|
33
|
+
const InternalContextProvider = ({ children, selection, activeState }) => {
|
|
34
|
+
const isSelectable = (0, react_1.useMemo)(() => Boolean((selection === null || selection === void 0 ? void 0 : selection.onSelect) && (selection === null || selection === void 0 ? void 0 : selection.isSelected)), [selection === null || selection === void 0 ? void 0 : selection.onSelect, selection === null || selection === void 0 ? void 0 : selection.isSelected]);
|
|
35
|
+
return (react_1.default.createElement(exports.InternalContext.Provider, { value: { selection, activeState, isSelectable } }, children));
|
|
36
|
+
};
|
|
33
37
|
exports.InternalContextProvider = InternalContextProvider;
|
|
34
38
|
const useInternalContext = () => (0, react_1.useContext)(exports.InternalContext);
|
|
35
39
|
exports.useInternalContext = useInternalContext;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export { default as DataViewToolbar } from './DataViewToolbar';
|
|
|
5
5
|
export * from './DataViewToolbar';
|
|
6
6
|
export { default as DataViewTableTree } from './DataViewTableTree';
|
|
7
7
|
export * from './DataViewTableTree';
|
|
8
|
-
export { default as
|
|
9
|
-
export * from './
|
|
8
|
+
export { default as DataViewTableHead } from './DataViewTableHead';
|
|
9
|
+
export * from './DataViewTableHead';
|
|
10
10
|
export { default as DataViewTableBasic } from './DataViewTableBasic';
|
|
11
11
|
export * from './DataViewTableBasic';
|
|
12
12
|
export { default as DataViewTable } from './DataViewTable';
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.DataView = exports.DataViewEventsContext = exports.DataViewTable = exports.DataViewTableBasic = exports.
|
|
21
|
+
exports.DataView = exports.DataViewEventsContext = exports.DataViewTable = exports.DataViewTableBasic = exports.DataViewTableHead = exports.DataViewTableTree = exports.DataViewToolbar = exports.InternalContext = void 0;
|
|
22
22
|
var InternalContext_1 = require("./InternalContext");
|
|
23
23
|
Object.defineProperty(exports, "InternalContext", { enumerable: true, get: function () { return __importDefault(InternalContext_1).default; } });
|
|
24
24
|
__exportStar(require("./InternalContext"), exports);
|
|
@@ -29,9 +29,9 @@ __exportStar(require("./DataViewToolbar"), exports);
|
|
|
29
29
|
var DataViewTableTree_1 = require("./DataViewTableTree");
|
|
30
30
|
Object.defineProperty(exports, "DataViewTableTree", { enumerable: true, get: function () { return __importDefault(DataViewTableTree_1).default; } });
|
|
31
31
|
__exportStar(require("./DataViewTableTree"), exports);
|
|
32
|
-
var
|
|
33
|
-
Object.defineProperty(exports, "
|
|
34
|
-
__exportStar(require("./
|
|
32
|
+
var DataViewTableHead_1 = require("./DataViewTableHead");
|
|
33
|
+
Object.defineProperty(exports, "DataViewTableHead", { enumerable: true, get: function () { return __importDefault(DataViewTableHead_1).default; } });
|
|
34
|
+
__exportStar(require("./DataViewTableHead"), exports);
|
|
35
35
|
var DataViewTableBasic_1 = require("./DataViewTableBasic");
|
|
36
36
|
Object.defineProperty(exports, "DataViewTableBasic", { enumerable: true, get: function () { return __importDefault(DataViewTableBasic_1).default; } });
|
|
37
37
|
__exportStar(require("./DataViewTableBasic"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"main":"../../cjs/DataViewTableHead/index.js","module":"../../esm/DataViewTableHead/index.js","typings":"../../esm/DataViewTableHead/index.d.ts"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { StackProps } from '@patternfly/react-core';
|
|
2
3
|
import { DataViewSelection } from '../InternalContext';
|
|
3
4
|
export declare const DataViewState: {
|
|
4
5
|
readonly empty: "empty";
|
|
@@ -6,7 +7,8 @@ export declare const DataViewState: {
|
|
|
6
7
|
readonly error: "error";
|
|
7
8
|
};
|
|
8
9
|
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
9
|
-
|
|
10
|
+
/** extends StackProps */
|
|
11
|
+
export interface DataViewProps extends StackProps {
|
|
10
12
|
/** Content rendered inside the data view */
|
|
11
13
|
children: React.ReactNode;
|
|
12
14
|
/** Custom OUIA ID */
|
|
@@ -14,7 +16,7 @@ export interface DataViewProps {
|
|
|
14
16
|
/** Selection context configuration */
|
|
15
17
|
selection?: DataViewSelection;
|
|
16
18
|
/** Currently active state */
|
|
17
|
-
activeState?: DataViewState;
|
|
19
|
+
activeState?: DataViewState | string;
|
|
18
20
|
}
|
|
19
21
|
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
20
22
|
export declare const DataView: React.FC<DataViewProps>;
|
|
@@ -7,8 +7,10 @@ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | '
|
|
|
7
7
|
columns: DataViewTh[];
|
|
8
8
|
/** Current page rows */
|
|
9
9
|
rows: DataViewTr[];
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Table head states to be displayed when active */
|
|
11
|
+
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
|
+
/** Table body states to be displayed when active */
|
|
13
|
+
bodyStates?: Partial<Record<DataViewState | string, React.ReactNode>>;
|
|
12
14
|
/** Custom OUIA ID */
|
|
13
15
|
ouiaId?: string;
|
|
14
16
|
}
|
|
@@ -12,32 +12,33 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React, { useMemo } from 'react';
|
|
13
13
|
import { Table, Tbody, Td, Tr, } from '@patternfly/react-table';
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
|
-
import {
|
|
15
|
+
import { DataViewTableHead } from '../DataViewTableHead';
|
|
16
16
|
import { isDataViewTdObject, isDataViewTrObject } from '../DataViewTable';
|
|
17
17
|
export const DataViewTableBasic = (_a) => {
|
|
18
|
-
var { columns, rows, ouiaId = 'DataViewTableBasic',
|
|
19
|
-
const { selection, activeState } = useInternalContext();
|
|
18
|
+
var { columns, rows, ouiaId = 'DataViewTableBasic', headStates, bodyStates } = _a, props = __rest(_a, ["columns", "rows", "ouiaId", "headStates", "bodyStates"]);
|
|
19
|
+
const { selection, activeState, isSelectable } = useInternalContext();
|
|
20
20
|
const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
|
|
21
|
-
const
|
|
21
|
+
const activeHeadState = useMemo(() => activeState ? headStates === null || headStates === void 0 ? void 0 : headStates[activeState] : undefined, [activeState, headStates]);
|
|
22
|
+
const activeBodyState = useMemo(() => activeState ? bodyStates === null || bodyStates === void 0 ? void 0 : bodyStates[activeState] : undefined, [activeState, bodyStates]);
|
|
23
|
+
const renderedRows = useMemo(() => rows.map((row, rowIndex) => {
|
|
24
|
+
const rowIsObject = isDataViewTrObject(row);
|
|
25
|
+
return (React.createElement(Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && (row === null || row === void 0 ? void 0 : row.props))),
|
|
26
|
+
isSelectable && (React.createElement(Td, { key: `select-${rowIndex}`, select: {
|
|
27
|
+
rowIndex,
|
|
28
|
+
onSelect: (_event, isSelecting) => {
|
|
29
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
30
|
+
},
|
|
31
|
+
isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
|
|
32
|
+
isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
|
|
33
|
+
} })),
|
|
34
|
+
(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
37
|
+
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));
|
|
38
|
+
})));
|
|
39
|
+
}), [rows, isSelectable, isSelected, isSelectDisabled, onSelect, ouiaId]);
|
|
22
40
|
return (React.createElement(Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
|
|
23
|
-
React.createElement(
|
|
24
|
-
React.createElement(Tbody, null,
|
|
25
|
-
React.createElement(Td, { colSpan: columns.length + Number(isSelectable) }, states[activeState]))) : (rows.map((row, rowIndex) => {
|
|
26
|
-
const rowIsObject = isDataViewTrObject(row);
|
|
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: {
|
|
29
|
-
rowIndex,
|
|
30
|
-
onSelect: (_event, isSelecting) => {
|
|
31
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
|
|
32
|
-
},
|
|
33
|
-
isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
|
|
34
|
-
isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
|
|
35
|
-
} })),
|
|
36
|
-
(rowIsObject ? row.row : row).map((cell, colIndex) => {
|
|
37
|
-
var _a;
|
|
38
|
-
const cellIsObject = isDataViewTdObject(cell);
|
|
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));
|
|
40
|
-
})));
|
|
41
|
-
})))));
|
|
41
|
+
activeHeadState || React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId }),
|
|
42
|
+
activeBodyState || React.createElement(Tbody, null, renderedRows)));
|
|
42
43
|
};
|
|
43
44
|
export default DataViewTableBasic;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
|
+
import { DataView } from '../DataView';
|
|
3
4
|
import { DataViewTableBasic } from './DataViewTableBasic';
|
|
4
|
-
import DataView from '../DataView/DataView';
|
|
5
5
|
const repositories = [
|
|
6
6
|
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
7
7
|
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
@@ -22,12 +22,17 @@ describe('DataViewTable component', () => {
|
|
|
22
22
|
});
|
|
23
23
|
test('should render with an empty state', () => {
|
|
24
24
|
const { container } = render(React.createElement(DataView, { activeState: "empty" },
|
|
25
|
-
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns,
|
|
25
|
+
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { empty: "No data found" }, rows: [] })));
|
|
26
26
|
expect(container).toMatchSnapshot();
|
|
27
27
|
});
|
|
28
28
|
test('should render with an error state', () => {
|
|
29
29
|
const { container } = render(React.createElement(DataView, { activeState: "error" },
|
|
30
|
-
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns,
|
|
30
|
+
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { error: "Some error" }, rows: [] })));
|
|
31
|
+
expect(container).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
test('should render with a loading state', () => {
|
|
34
|
+
const { container } = render(React.createElement(DataView, { activeState: "loading" },
|
|
35
|
+
React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, bodyStates: { loading: "Data is loading" }, rows: [] })));
|
|
31
36
|
expect(container).toMatchSnapshot();
|
|
32
37
|
});
|
|
33
38
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TheadProps } from '@patternfly/react-table';
|
|
3
3
|
import { DataViewTh } from '../DataViewTable';
|
|
4
|
-
export interface
|
|
4
|
+
export interface DataViewTableHeadProps extends TheadProps {
|
|
5
5
|
/** Indicates whether table is a tree */
|
|
6
6
|
isTreeTable?: boolean;
|
|
7
7
|
/** Columns definition */
|
|
@@ -9,5 +9,5 @@ export interface DataViewTableHeaderProps extends TheadProps {
|
|
|
9
9
|
/** Custom OUIA ID */
|
|
10
10
|
ouiaId?: string;
|
|
11
11
|
}
|
|
12
|
-
export declare const
|
|
13
|
-
export default
|
|
12
|
+
export declare const DataViewTableHead: React.FC<DataViewTableHeadProps>;
|
|
13
|
+
export default DataViewTableHead;
|
|
@@ -13,12 +13,12 @@ import React, { useMemo } from 'react';
|
|
|
13
13
|
import { Th, Thead, Tr } from '@patternfly/react-table';
|
|
14
14
|
import { useInternalContext } from '../InternalContext';
|
|
15
15
|
import { isDataViewThObject } from '../DataViewTable';
|
|
16
|
-
export const
|
|
17
|
-
var { isTreeTable = false, columns, ouiaId = '
|
|
16
|
+
export const DataViewTableHead = (_a) => {
|
|
17
|
+
var { isTreeTable = false, columns, ouiaId = 'DataViewTableHead' } = _a, props = __rest(_a, ["isTreeTable", "columns", "ouiaId"]);
|
|
18
18
|
const { selection } = useInternalContext();
|
|
19
19
|
const { onSelect, isSelected } = selection !== null && selection !== void 0 ? selection : {};
|
|
20
20
|
const cells = useMemo(() => [
|
|
21
|
-
onSelect && isSelected && !isTreeTable ? (React.createElement(Th, { key: "row-select", screenReaderText: 'Data selection table
|
|
21
|
+
onSelect && isSelected && !isTreeTable ? (React.createElement(Th, { key: "row-select", screenReaderText: 'Data selection table head cell' })) : null,
|
|
22
22
|
...columns.map((column, index) => {
|
|
23
23
|
var _a;
|
|
24
24
|
return (React.createElement(Th, Object.assign({ key: index }, (isDataViewThObject(column) && ((_a = column === null || column === void 0 ? void 0 : column.props) !== null && _a !== void 0 ? _a : {})), { "data-ouia-component-id": `${ouiaId}-th-${index}` }), isDataViewThObject(column) ? column.cell : column));
|
|
@@ -27,4 +27,4 @@ export const DataViewTableHeader = (_a) => {
|
|
|
27
27
|
return (React.createElement(Thead, Object.assign({ "data-ouia-component-id": `${ouiaId}-thead` }, props),
|
|
28
28
|
React.createElement(Tr, { ouiaId: `${ouiaId}-tr-head` }, cells)));
|
|
29
29
|
};
|
|
30
|
-
export default
|
|
30
|
+
export default DataViewTableHead;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { Table } from '@patternfly/react-table';
|
|
4
|
-
import {
|
|
4
|
+
import { DataViewTableHead } from './DataViewTableHead';
|
|
5
5
|
import { DataView } from '../DataView';
|
|
6
6
|
const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
|
|
7
7
|
const ouiaId = 'HeaderExample';
|
|
8
|
-
describe('
|
|
8
|
+
describe('DataViewTableHead component', () => {
|
|
9
9
|
const mockSelection = {
|
|
10
10
|
onSelect: jest.fn(),
|
|
11
11
|
isSelected: jest.fn(),
|
|
@@ -13,19 +13,19 @@ describe('DataViewTableHeader component', () => {
|
|
|
13
13
|
};
|
|
14
14
|
test('should render correctly', () => {
|
|
15
15
|
const { container } = render(React.createElement(Table, null,
|
|
16
|
-
React.createElement(
|
|
16
|
+
React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId })));
|
|
17
17
|
expect(container).toMatchSnapshot();
|
|
18
18
|
});
|
|
19
19
|
test('should render the tree table correctly when isTreeTable is true', () => {
|
|
20
20
|
const { container } = render(React.createElement(DataView, { selection: mockSelection },
|
|
21
21
|
React.createElement(Table, null,
|
|
22
|
-
React.createElement(
|
|
22
|
+
React.createElement(DataViewTableHead, { isTreeTable: true, columns: columns, ouiaId: ouiaId }))));
|
|
23
23
|
expect(container).toMatchSnapshot();
|
|
24
24
|
});
|
|
25
25
|
test('should render selection column when selection is provided', () => {
|
|
26
26
|
const { container } = render(React.createElement(DataView, { selection: mockSelection },
|
|
27
27
|
React.createElement(Table, null,
|
|
28
|
-
React.createElement(
|
|
28
|
+
React.createElement(DataViewTableHead, { columns: columns, ouiaId: ouiaId }))));
|
|
29
29
|
expect(container).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
31
|
});
|