@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.
Files changed (81) hide show
  1. package/dist/cjs/DataViewTable/DataViewTable.d.ts +18 -14
  2. package/dist/cjs/DataViewTable/DataViewTable.js +3 -44
  3. package/dist/cjs/DataViewTable/DataViewTable.test.js +40 -10
  4. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  5. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +49 -0
  6. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  7. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +27 -0
  8. package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
  9. package/dist/cjs/DataViewTableBasic/index.js +23 -0
  10. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
  11. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.js +57 -0
  12. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
  13. package/dist/cjs/DataViewTableHeader/DataViewTableHeader.test.js +36 -0
  14. package/dist/cjs/DataViewTableHeader/index.d.ts +2 -0
  15. package/dist/cjs/DataViewTableHeader/index.js +23 -0
  16. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +19 -0
  17. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +120 -0
  18. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  19. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +75 -0
  20. package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
  21. package/dist/cjs/DataViewTableTree/index.js +23 -0
  22. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
  23. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
  24. package/dist/cjs/InternalContext/InternalContext.test.js +4 -3
  25. package/dist/cjs/index.d.ts +6 -0
  26. package/dist/cjs/index.js +10 -1
  27. package/dist/dynamic/DataViewTableBasic/package.json +1 -0
  28. package/dist/dynamic/DataViewTableHeader/package.json +1 -0
  29. package/dist/dynamic/DataViewTableTree/package.json +1 -0
  30. package/dist/esm/DataViewTable/DataViewTable.d.ts +18 -14
  31. package/dist/esm/DataViewTable/DataViewTable.js +3 -44
  32. package/dist/esm/DataViewTable/DataViewTable.test.js +40 -10
  33. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  34. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +42 -0
  35. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  36. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +22 -0
  37. package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
  38. package/dist/esm/DataViewTableBasic/index.js +2 -0
  39. package/dist/esm/DataViewTableHeader/DataViewTableHeader.d.ts +13 -0
  40. package/dist/esm/DataViewTableHeader/DataViewTableHeader.js +30 -0
  41. package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.d.ts +1 -0
  42. package/dist/esm/DataViewTableHeader/DataViewTableHeader.test.js +31 -0
  43. package/dist/esm/DataViewTableHeader/index.d.ts +2 -0
  44. package/dist/esm/DataViewTableHeader/index.js +2 -0
  45. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +19 -0
  46. package/dist/esm/DataViewTableTree/DataViewTableTree.js +93 -0
  47. package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  48. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +70 -0
  49. package/dist/esm/DataViewTableTree/index.d.ts +2 -0
  50. package/dist/esm/DataViewTableTree/index.js +2 -0
  51. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
  52. package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
  53. package/dist/esm/InternalContext/InternalContext.test.js +5 -4
  54. package/dist/esm/index.d.ts +6 -0
  55. package/dist/esm/index.js +6 -0
  56. package/package.json +1 -1
  57. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +14 -2
  58. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +29 -9
  59. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +69 -0
  60. package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +7 -7
  61. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +6 -6
  62. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +6 -6
  63. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +6 -6
  64. package/src/DataViewTable/DataViewTable.test.tsx +53 -10
  65. package/src/DataViewTable/DataViewTable.tsx +20 -79
  66. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +721 -31
  67. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +37 -0
  68. package/src/DataViewTableBasic/DataViewTableBasic.tsx +71 -0
  69. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +324 -0
  70. package/src/DataViewTableBasic/index.ts +2 -0
  71. package/src/DataViewTableHeader/DataViewTableHeader.test.tsx +52 -0
  72. package/src/DataViewTableHeader/DataViewTableHeader.tsx +53 -0
  73. package/src/DataViewTableHeader/__snapshots__/DataViewTableHeader.test.tsx.snap +227 -0
  74. package/src/DataViewTableHeader/index.ts +2 -0
  75. package/src/DataViewTableTree/DataViewTableTree.test.tsx +85 -0
  76. package/src/DataViewTableTree/DataViewTableTree.tsx +144 -0
  77. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +937 -0
  78. package/src/DataViewTableTree/index.ts +2 -0
  79. package/src/DataViewToolbar/DataViewToolbar.tsx +4 -1
  80. package/src/InternalContext/InternalContext.test.tsx +8 -7
  81. package/src/index.ts +9 -0
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const react_2 = require("@testing-library/react");
8
+ const react_icons_1 = require("@patternfly/react-icons");
9
+ const DataView_1 = require("../DataView");
10
+ const DataViewTable_1 = require("../DataViewTable");
11
+ const repositories = [
12
+ {
13
+ name: 'Repository one',
14
+ branches: 'Branch one',
15
+ prs: 'Pull request one',
16
+ workspaces: 'Workspace one',
17
+ lastCommit: 'Timestamp one',
18
+ children: [
19
+ {
20
+ name: 'Repository two',
21
+ branches: 'Branch two',
22
+ prs: 'Pull request two',
23
+ workspaces: 'Workspace two',
24
+ lastCommit: 'Timestamp two',
25
+ },
26
+ {
27
+ name: 'Repository three',
28
+ branches: 'Branch three',
29
+ prs: 'Pull request three',
30
+ workspaces: 'Workspace three',
31
+ lastCommit: 'Timestamp three',
32
+ },
33
+ ],
34
+ },
35
+ {
36
+ name: 'Repository four',
37
+ branches: 'Branch four',
38
+ prs: 'Pull request four',
39
+ workspaces: 'Workspace four',
40
+ lastCommit: 'Timestamp four',
41
+ children: [
42
+ {
43
+ name: 'Repository five',
44
+ branches: 'Branch five',
45
+ prs: 'Pull request five',
46
+ workspaces: 'Workspace five',
47
+ lastCommit: 'Timestamp five',
48
+ },
49
+ ],
50
+ },
51
+ {
52
+ name: 'Repository six',
53
+ branches: 'Branch six',
54
+ prs: 'Pull request six',
55
+ workspaces: 'Workspace six',
56
+ lastCommit: 'Timestamp six',
57
+ },
58
+ ];
59
+ // Build rows for DataViewTable
60
+ 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) } : {}))));
61
+ const rows = buildRows(repositories);
62
+ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
63
+ const ouiaId = 'TreeTableExample';
64
+ describe('DataViewTableTree component', () => {
65
+ const mockSelection = {
66
+ onSelect: jest.fn(),
67
+ isSelected: jest.fn(),
68
+ isSelectDisabled: jest.fn(),
69
+ };
70
+ test('should render the tree table correctly', () => {
71
+ const { container } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelection },
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
+ expect(container).toMatchSnapshot();
74
+ });
75
+ });
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableTree';
2
+ export * from './DataViewTableTree';
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.default = void 0;
21
+ var DataViewTableTree_1 = require("./DataViewTableTree");
22
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(DataViewTableTree_1).default; } });
23
+ __exportStar(require("./DataViewTableTree"), exports);
@@ -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;
@@ -18,10 +18,11 @@ exports.DataViewToolbar = void 0;
18
18
  const react_1 = __importDefault(require("react"));
19
19
  const react_core_1 = require("@patternfly/react-core");
20
20
  const DataViewToolbar = (_a) => {
21
- var { className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "pagination", "children"]);
21
+ var { className, ouiaId = 'DataViewToolbar', bulkSelect, actions = null, pagination, children } = _a, props = __rest(_a, ["className", "ouiaId", "bulkSelect", "actions", "pagination", "children"]);
22
22
  return (react_1.default.createElement(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className }, props),
23
23
  react_1.default.createElement(react_core_1.ToolbarContent, null,
24
24
  bulkSelect && (react_1.default.createElement(react_core_1.ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
25
+ actions,
25
26
  pagination && (react_1.default.createElement(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
26
27
  children)));
27
28
  };
@@ -7,6 +7,7 @@ const react_1 = __importDefault(require("react"));
7
7
  const react_2 = require("@testing-library/react");
8
8
  require("@testing-library/jest-dom");
9
9
  const InternalContext_1 = require("./InternalContext");
10
+ const DataView_1 = require("../DataView");
10
11
  describe('InternalContext', () => {
11
12
  const mockSelection = {
12
13
  onSelect: jest.fn(),
@@ -20,7 +21,7 @@ describe('InternalContext', () => {
20
21
  react_1.default.createElement("button", { onClick: () => selection === null || selection === void 0 ? void 0 : selection.onSelect(true, ['item1']) }, "Select item"),
21
22
  react_1.default.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Selected' : 'Not selected')));
22
23
  };
23
- const { getByText } = (0, react_2.render)(react_1.default.createElement(InternalContext_1.InternalContextProvider, { selection: mockSelection },
24
+ const { getByText } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelection },
24
25
  react_1.default.createElement(TestComponent, null)));
25
26
  react_2.fireEvent.click(getByText('Select item'));
26
27
  expect(mockSelection.onSelect).toHaveBeenCalledWith(true, ['item1']);
@@ -33,7 +34,7 @@ describe('InternalContext', () => {
33
34
  react_1.default.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item1')) ? 'Item 1 is selected' : 'Item 1 is not selected'),
34
35
  react_1.default.createElement("span", null, (selection === null || selection === void 0 ? void 0 : selection.isSelected('item2')) ? 'Item 2 is selected' : 'Item 2 is not selected')));
35
36
  };
36
- const { getByText } = (0, react_2.render)(react_1.default.createElement(InternalContext_1.InternalContextProvider, { selection: mockSelectionState },
37
+ const { getByText } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelectionState },
37
38
  react_1.default.createElement(TestComponent, null)));
38
39
  expect(getByText('Item 1 is selected')).toBeInTheDocument();
39
40
  expect(getByText('Item 2 is not selected')).toBeInTheDocument();
@@ -47,7 +48,7 @@ describe('InternalContext', () => {
47
48
  react_1.default.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'),
48
49
  react_1.default.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')));
49
50
  };
50
- const { getByText } = (0, react_2.render)(react_1.default.createElement(InternalContext_1.InternalContextProvider, { selection: mockSelectionWithDisabled },
51
+ const { getByText } = (0, react_2.render)(react_1.default.createElement(DataView_1.DataView, { selection: mockSelectionWithDisabled },
51
52
  react_1.default.createElement(TestComponent, null)));
52
53
  expect(getByText('Item 3 is disabled')).toBeInTheDocument();
53
54
  expect(getByText('Item 1 is enabled')).toBeInTheDocument();
@@ -3,6 +3,12 @@ export * from './InternalContext';
3
3
  export * from './Hooks';
4
4
  export { default as DataViewToolbar } from './DataViewToolbar';
5
5
  export * from './DataViewToolbar';
6
+ export { default as DataViewTableTree } from './DataViewTableTree';
7
+ export * from './DataViewTableTree';
8
+ export { default as DataViewTableHeader } from './DataViewTableHeader';
9
+ export * from './DataViewTableHeader';
10
+ export { default as DataViewTableBasic } from './DataViewTableBasic';
11
+ export * from './DataViewTableBasic';
6
12
  export { default as DataViewTable } from './DataViewTable';
7
13
  export * from './DataViewTable';
8
14
  export { default as DataViewEventsContext } from './DataViewEventsContext';
package/dist/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.DataViewToolbar = exports.InternalContext = void 0;
21
+ exports.DataView = exports.DataViewEventsContext = exports.DataViewTable = exports.DataViewTableBasic = exports.DataViewTableHeader = 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);
@@ -26,6 +26,15 @@ __exportStar(require("./Hooks"), exports);
26
26
  var DataViewToolbar_1 = require("./DataViewToolbar");
27
27
  Object.defineProperty(exports, "DataViewToolbar", { enumerable: true, get: function () { return __importDefault(DataViewToolbar_1).default; } });
28
28
  __exportStar(require("./DataViewToolbar"), exports);
29
+ var DataViewTableTree_1 = require("./DataViewTableTree");
30
+ Object.defineProperty(exports, "DataViewTableTree", { enumerable: true, get: function () { return __importDefault(DataViewTableTree_1).default; } });
31
+ __exportStar(require("./DataViewTableTree"), exports);
32
+ var DataViewTableHeader_1 = require("./DataViewTableHeader");
33
+ Object.defineProperty(exports, "DataViewTableHeader", { enumerable: true, get: function () { return __importDefault(DataViewTableHeader_1).default; } });
34
+ __exportStar(require("./DataViewTableHeader"), exports);
35
+ var DataViewTableBasic_1 = require("./DataViewTableBasic");
36
+ Object.defineProperty(exports, "DataViewTableBasic", { enumerable: true, get: function () { return __importDefault(DataViewTableBasic_1).default; } });
37
+ __exportStar(require("./DataViewTableBasic"), exports);
29
38
  var DataViewTable_1 = require("./DataViewTable");
30
39
  Object.defineProperty(exports, "DataViewTable", { enumerable: true, get: function () { return __importDefault(DataViewTable_1).default; } });
31
40
  __exportStar(require("./DataViewTable"), exports);
@@ -0,0 +1 @@
1
+ {"main":"../../cjs/DataViewTableBasic/index.js","module":"../../esm/DataViewTableBasic/index.js","typings":"../../esm/DataViewTableBasic/index.d.ts"}
@@ -0,0 +1 @@
1
+ {"main":"../../cjs/DataViewTableHeader/index.js","module":"../../esm/DataViewTableHeader/index.js","typings":"../../esm/DataViewTableHeader/index.d.ts"}
@@ -0,0 +1 @@
1
+ {"main":"../../cjs/DataViewTableTree/index.js","module":"../../esm/DataViewTableTree/index.js","typings":"../../esm/DataViewTableTree/index.d.ts"}
@@ -1,22 +1,25 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { TableProps, TdProps, ThProps, TrProps } from '@patternfly/react-table';
2
+ import { TdProps, ThProps, TrProps } from '@patternfly/react-table';
3
+ import { DataViewTableTreeProps } from '../DataViewTableTree';
4
+ import { DataViewTableBasicProps } from '../DataViewTableBasic';
3
5
  export type DataViewTh = ReactNode | {
4
6
  cell: ReactNode;
5
7
  props?: ThProps;
6
8
  };
7
- export type DataViewTd = ReactNode | {
9
+ export declare const isDataViewThObject: (value: DataViewTh) => value is {
8
10
  cell: ReactNode;
9
- props?: TdProps;
11
+ props?: ThProps | undefined;
10
12
  };
11
- export type DataViewTr = DataViewTd[] | {
13
+ export interface DataViewTrObject {
12
14
  row: DataViewTd[];
13
15
  id?: string;
14
16
  props?: TrProps;
15
- };
16
- export declare const isDataViewThObject: (value: DataViewTh) => value is {
17
+ }
18
+ export type DataViewTd = ReactNode | {
17
19
  cell: ReactNode;
18
- props?: ThProps | undefined;
20
+ props?: TdProps;
19
21
  };
22
+ export type DataViewTr = DataViewTd[] | DataViewTrObject;
20
23
  export declare const isDataViewTdObject: (value: DataViewTd) => value is {
21
24
  cell: ReactNode;
22
25
  props?: TdProps | undefined;
@@ -25,13 +28,14 @@ export declare const isDataViewTrObject: (value: DataViewTr) => value is {
25
28
  row: DataViewTd[];
26
29
  id?: string | undefined;
27
30
  };
28
- export interface DataViewTableProps extends Omit<TableProps, 'onSelect' | 'rows'> {
29
- /** Columns definition */
30
- columns: DataViewTh[];
31
- /** Current page rows */
32
- rows: DataViewTr[];
33
- /** Custom OUIA ID */
34
- ouiaId?: string;
31
+ export interface DataViewTrTree extends DataViewTrObject {
32
+ id: string;
33
+ children?: DataViewTrTree[];
35
34
  }
35
+ export type DataViewTableProps = ({
36
+ isTreeTable: true;
37
+ } & DataViewTableTreeProps) | ({
38
+ isTreeTable?: false;
39
+ } & DataViewTableBasicProps);
36
40
  export declare const DataViewTable: React.FC<DataViewTableProps>;
37
41
  export default DataViewTable;
@@ -1,49 +1,8 @@
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
1
  import React from 'react';
13
- import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
14
- import { useInternalContext } from '../InternalContext';
2
+ import { DataViewTableTree } from '../DataViewTableTree';
3
+ import { DataViewTableBasic } from '../DataViewTableBasic';
15
4
  export const isDataViewThObject = (value) => value != null && typeof value === 'object' && 'cell' in value;
16
5
  export const isDataViewTdObject = (value) => value != null && typeof value === 'object' && 'cell' in value;
17
6
  export const isDataViewTrObject = (value) => value != null && typeof value === 'object' && 'row' in value;
18
- export const DataViewTable = (_a) => {
19
- var { columns, rows, ouiaId = 'DataViewTable' } = _a, props = __rest(_a, ["columns", "rows", "ouiaId"]);
20
- const { selection } = useInternalContext();
21
- const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
22
- return (React.createElement(Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
23
- React.createElement(Thead, { "data-ouia-component-id": `${ouiaId}-thead` },
24
- React.createElement(Tr, { ouiaId: `${ouiaId}-tr-head` },
25
- onSelect && isSelected && React.createElement(Th, { key: "row-select" }),
26
- columns.map((column, index) => {
27
- var _a;
28
- 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));
29
- }))),
30
- React.createElement(Tbody, null, rows.map((row, rowIndex) => {
31
- var _a;
32
- const rowIsObject = isDataViewTrObject(row);
33
- return (React.createElement(Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && ((_a = row === null || row === void 0 ? void 0 : row.props) !== null && _a !== void 0 ? _a : {}))),
34
- onSelect && isSelected && (React.createElement(Td, { key: `select-${rowIndex}`, select: {
35
- rowIndex,
36
- onSelect: (_event, isSelecting) => {
37
- onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
38
- },
39
- isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
40
- isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
41
- } })),
42
- (rowIsObject ? row.row : row).map((cell, colIndex) => {
43
- var _a;
44
- const cellIsObject = isDataViewTdObject(cell);
45
- 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));
46
- })));
47
- }))));
48
- };
7
+ export const DataViewTable = (props) => (props.isTreeTable ? React.createElement(DataViewTableTree, Object.assign({}, props)) : React.createElement(DataViewTableBasic, Object.assign({}, props)));
49
8
  export default DataViewTable;
@@ -2,21 +2,51 @@ import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
  import { DataViewTable } from './DataViewTable';
4
4
  const repositories = [
5
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
6
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
7
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
8
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
9
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
10
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
5
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
6
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
7
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
8
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
9
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
10
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
11
11
  ];
12
- const rows = repositories.map(repo => ({
13
- row: Object.values(repo),
14
- }));
12
+ const rows = repositories.map(repo => ({ row: Object.values(repo) }));
13
+ const repositoriesTree = [
14
+ {
15
+ name: 'Repository one',
16
+ branches: 'Branch one',
17
+ prs: 'Pull request one',
18
+ workspaces: 'Workspace one',
19
+ lastCommit: 'Timestamp one',
20
+ children: [
21
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
22
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
23
+ ]
24
+ },
25
+ {
26
+ name: 'Repository four',
27
+ branches: 'Branch four',
28
+ prs: 'Pull request four',
29
+ workspaces: 'Workspace four',
30
+ lastCommit: 'Timestamp four',
31
+ children: [{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' }]
32
+ },
33
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
34
+ ];
35
+ const buildRows = (repositories) => repositories.map((repo) => (Object.assign({ row: [repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit], id: repo.name }, (repo.children
36
+ ? {
37
+ children: buildRows(repo.children) // build rows for children
38
+ }
39
+ : {}))));
40
+ const treeRows = buildRows(repositoriesTree);
15
41
  const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
16
42
  const ouiaId = 'TableExample';
17
43
  describe('DataViewTable component', () => {
18
- test('should render correctly', () => {
44
+ test('should render a basic table correctly', () => {
19
45
  const { container } = render(React.createElement(DataViewTable, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
20
46
  expect(container).toMatchSnapshot();
21
47
  });
48
+ test('should render a tree table correctly', () => {
49
+ const { container } = render(React.createElement(DataViewTable, { isTreeTable: true, "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: treeRows }));
50
+ expect(container).toMatchSnapshot();
51
+ });
22
52
  });
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { TableProps } from '@patternfly/react-table';
3
+ import { DataViewTh, DataViewTr } from '../DataViewTable';
4
+ export interface DataViewTableBasicProps extends Omit<TableProps, 'onSelect' | 'rows'> {
5
+ /** Columns definition */
6
+ columns: DataViewTh[];
7
+ /** Current page rows */
8
+ rows: DataViewTr[];
9
+ /** Custom OUIA ID */
10
+ ouiaId?: string;
11
+ }
12
+ export declare const DataViewTableBasic: React.FC<DataViewTableBasicProps>;
13
+ export default DataViewTableBasic;
@@ -0,0 +1,42 @@
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 from 'react';
13
+ import { Table, Tbody, Td, Tr, } from '@patternfly/react-table';
14
+ import { useInternalContext } from '../InternalContext';
15
+ import { DataViewTableHeader } from '../DataViewTableHeader';
16
+ import { isDataViewTdObject, isDataViewTrObject } from '../DataViewTable';
17
+ export const DataViewTableBasic = (_a) => {
18
+ var { columns, rows, ouiaId = 'DataViewTableBasic' } = _a, props = __rest(_a, ["columns", "rows", "ouiaId"]);
19
+ const { selection } = useInternalContext();
20
+ const { onSelect, isSelected, isSelectDisabled } = selection !== null && selection !== void 0 ? selection : {};
21
+ return (React.createElement(Table, Object.assign({ "aria-label": "Data table", ouiaId: ouiaId }, props),
22
+ React.createElement(DataViewTableHeader, { columns: columns, ouiaId: ouiaId }),
23
+ React.createElement(Tbody, null, rows.map((row, rowIndex) => {
24
+ var _a;
25
+ const rowIsObject = isDataViewTrObject(row);
26
+ return (React.createElement(Tr, Object.assign({ key: rowIndex, ouiaId: `${ouiaId}-tr-${rowIndex}` }, (rowIsObject && ((_a = row === null || row === void 0 ? void 0 : row.props) !== null && _a !== void 0 ? _a : {}))),
27
+ onSelect && isSelected && (React.createElement(Td, { key: `select-${rowIndex}`, select: {
28
+ rowIndex,
29
+ onSelect: (_event, isSelecting) => {
30
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(isSelecting, rowIsObject ? row : [row]);
31
+ },
32
+ isSelected: (isSelected === null || isSelected === void 0 ? void 0 : isSelected(row)) || false,
33
+ isDisabled: (isSelectDisabled === null || isSelectDisabled === void 0 ? void 0 : isSelectDisabled(row)) || false,
34
+ } })),
35
+ (rowIsObject ? row.row : row).map((cell, colIndex) => {
36
+ var _a;
37
+ const cellIsObject = isDataViewTdObject(cell);
38
+ 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
+ }))));
41
+ };
42
+ export default DataViewTableBasic;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { DataViewTableBasic } from './DataViewTableBasic';
4
+ const repositories = [
5
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
6
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
7
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
8
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
9
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
10
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
11
+ ];
12
+ const rows = repositories.map(repo => ({
13
+ row: Object.values(repo),
14
+ }));
15
+ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
16
+ const ouiaId = 'TableExample';
17
+ describe('DataViewTable component', () => {
18
+ test('should render correctly', () => {
19
+ const { container } = render(React.createElement(DataViewTableBasic, { "aria-label": 'Repositories table', ouiaId: ouiaId, columns: columns, rows: rows }));
20
+ expect(container).toMatchSnapshot();
21
+ });
22
+ });
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableBasic';
2
+ export * from './DataViewTableBasic';
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableBasic';
2
+ export * from './DataViewTableBasic';
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { TheadProps } from '@patternfly/react-table';
3
+ import { DataViewTh } from '../DataViewTable';
4
+ export interface DataViewTableHeaderProps extends TheadProps {
5
+ /** Indicates whether table is a tree */
6
+ isTreeTable?: boolean;
7
+ /** Columns definition */
8
+ columns: DataViewTh[];
9
+ /** Custom OUIA ID */
10
+ ouiaId?: string;
11
+ }
12
+ export declare const DataViewTableHeader: React.FC<DataViewTableHeaderProps>;
13
+ export default DataViewTableHeader;
@@ -0,0 +1,30 @@
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 { Th, Thead, Tr } from '@patternfly/react-table';
14
+ import { useInternalContext } from '../InternalContext';
15
+ import { isDataViewThObject } from '../DataViewTable';
16
+ export const DataViewTableHeader = (_a) => {
17
+ var { isTreeTable = false, columns, ouiaId = 'DataViewTableHeader' } = _a, props = __rest(_a, ["isTreeTable", "columns", "ouiaId"]);
18
+ const { selection } = useInternalContext();
19
+ const { onSelect, isSelected } = selection !== null && selection !== void 0 ? selection : {};
20
+ const cells = useMemo(() => [
21
+ onSelect && isSelected && !isTreeTable ? (React.createElement(Th, { key: "row-select", screenReaderText: 'Data selection table header cell' })) : null,
22
+ ...columns.map((column, index) => {
23
+ var _a;
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));
25
+ })
26
+ ], [columns, ouiaId, onSelect, isSelected, isTreeTable]);
27
+ return (React.createElement(Thead, Object.assign({ "data-ouia-component-id": `${ouiaId}-thead` }, props),
28
+ React.createElement(Tr, { ouiaId: `${ouiaId}-tr-head` }, cells)));
29
+ };
30
+ export default DataViewTableHeader;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { Table } from '@patternfly/react-table';
4
+ import { DataViewTableHeader } from './DataViewTableHeader';
5
+ import { DataView } from '../DataView';
6
+ const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
7
+ const ouiaId = 'HeaderExample';
8
+ describe('DataViewTableHeader component', () => {
9
+ const mockSelection = {
10
+ onSelect: jest.fn(),
11
+ isSelected: jest.fn(),
12
+ isSelectDisabled: jest.fn(),
13
+ };
14
+ test('should render correctly', () => {
15
+ const { container } = render(React.createElement(Table, null,
16
+ React.createElement(DataViewTableHeader, { columns: columns, ouiaId: ouiaId })));
17
+ expect(container).toMatchSnapshot();
18
+ });
19
+ test('should render the tree table correctly when isTreeTable is true', () => {
20
+ const { container } = render(React.createElement(DataView, { selection: mockSelection },
21
+ React.createElement(Table, null,
22
+ React.createElement(DataViewTableHeader, { isTreeTable: true, columns: columns, ouiaId: ouiaId }))));
23
+ expect(container).toMatchSnapshot();
24
+ });
25
+ test('should render selection column when selection is provided', () => {
26
+ const { container } = render(React.createElement(DataView, { selection: mockSelection },
27
+ React.createElement(Table, null,
28
+ React.createElement(DataViewTableHeader, { columns: columns, ouiaId: ouiaId }))));
29
+ expect(container).toMatchSnapshot();
30
+ });
31
+ });
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableHeader';
2
+ export * from './DataViewTableHeader';
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTableHeader';
2
+ export * from './DataViewTableHeader';
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { TableProps } from '@patternfly/react-table';
3
+ import { DataViewTh, DataViewTrTree } from '../DataViewTable';
4
+ export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
5
+ /** Columns definition */
6
+ columns: DataViewTh[];
7
+ /** Current page rows */
8
+ rows: DataViewTrTree[];
9
+ /** Optional icon for the leaf rows */
10
+ leafIcon?: React.ReactNode;
11
+ /** Optional icon for the expanded parent rows */
12
+ expandedIcon?: React.ReactNode;
13
+ /** Optional icon for the collapsed parent rows */
14
+ collapsedIcon?: React.ReactNode;
15
+ /** Custom OUIA ID */
16
+ ouiaId?: string;
17
+ }
18
+ export declare const DataViewTableTree: React.FC<DataViewTableTreeProps>;
19
+ export default DataViewTableTree;