@patternfly/react-data-view 6.1.0-prerelease.1 → 6.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 +15 -1
- package/dist/cjs/DataView/DataView.js +14 -3
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +70 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +25 -0
- package/dist/cjs/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewCheckboxFilter/index.js +23 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
- package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
- package/dist/cjs/DataViewEventsContext/index.js +23 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.js +85 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.js +19 -0
- package/dist/cjs/DataViewFilters/index.d.ts +2 -0
- package/dist/cjs/DataViewFilters/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +49 -0
- package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
- package/dist/cjs/DataViewTable/index.d.ts +2 -0
- package/dist/cjs/DataViewTable/index.js +23 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +14 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHead/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +25 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +144 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +26 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +22 -0
- package/dist/cjs/DataViewTextFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewTextFilter/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +13 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +31 -6
- package/dist/cjs/Hooks/filters.d.ts +14 -0
- package/dist/cjs/Hooks/filters.js +69 -0
- package/dist/cjs/Hooks/filters.test.d.ts +1 -0
- package/dist/cjs/Hooks/filters.test.js +75 -0
- package/dist/cjs/Hooks/index.d.ts +2 -0
- package/dist/cjs/Hooks/index.js +2 -0
- package/dist/cjs/Hooks/pagination.d.ts +14 -1
- package/dist/cjs/Hooks/pagination.js +36 -4
- package/dist/cjs/Hooks/pagination.test.js +1 -1
- package/dist/cjs/Hooks/selection.d.ts +3 -3
- package/dist/cjs/Hooks/selection.js +4 -4
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/Hooks/sort.d.ts +32 -0
- package/dist/cjs/Hooks/sort.js +47 -0
- package/dist/cjs/Hooks/sort.test.d.ts +1 -0
- package/dist/cjs/Hooks/sort.test.js +68 -0
- package/dist/cjs/InternalContext/InternalContext.d.ts +26 -0
- package/dist/cjs/InternalContext/InternalContext.js +40 -0
- package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
- package/dist/cjs/InternalContext/index.d.ts +2 -0
- package/dist/cjs/InternalContext/index.js +23 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +26 -2
- package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewFilters/package.json +1 -0
- package/dist/dynamic/DataViewTable/package.json +1 -0
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHead/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/dynamic/DataViewTextFilter/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +15 -1
- package/dist/esm/DataView/DataView.js +13 -2
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +62 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +20 -0
- package/dist/esm/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/esm/DataViewCheckboxFilter/index.js +2 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
- package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
- package/dist/esm/DataViewEventsContext/index.js +2 -0
- package/dist/esm/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/esm/DataViewFilters/DataViewFilters.js +58 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.js +14 -0
- package/dist/esm/DataViewFilters/index.d.ts +2 -0
- package/dist/esm/DataViewFilters/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +49 -0
- package/dist/esm/DataViewTable/DataViewTable.js +8 -0
- package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
- package/dist/esm/DataViewTable/index.d.ts +2 -0
- package/dist/esm/DataViewTable/index.js +2 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +14 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +25 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +117 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +19 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +17 -0
- package/dist/esm/DataViewTextFilter/index.d.ts +2 -0
- package/dist/esm/DataViewTextFilter/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +13 -3
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +9 -4
- package/dist/esm/Hooks/filters.d.ts +14 -0
- package/dist/esm/Hooks/filters.js +65 -0
- package/dist/esm/Hooks/filters.test.d.ts +1 -0
- package/dist/esm/Hooks/filters.test.js +73 -0
- package/dist/esm/Hooks/index.d.ts +2 -0
- package/dist/esm/Hooks/index.js +2 -0
- package/dist/esm/Hooks/pagination.d.ts +14 -1
- package/dist/esm/Hooks/pagination.js +36 -4
- package/dist/esm/Hooks/pagination.test.js +1 -1
- package/dist/esm/Hooks/selection.d.ts +3 -3
- package/dist/esm/Hooks/selection.js +4 -4
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/Hooks/sort.d.ts +32 -0
- package/dist/esm/Hooks/sort.js +43 -0
- package/dist/esm/Hooks/sort.test.d.ts +1 -0
- package/dist/esm/Hooks/sort.test.js +66 -0
- package/dist/esm/InternalContext/InternalContext.d.ts +26 -0
- package/dist/esm/InternalContext/InternalContext.js +12 -0
- package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/esm/InternalContext/InternalContext.test.js +51 -0
- package/dist/esm/InternalContext/index.d.ts +2 -0
- package/dist/esm/InternalContext/index.js +2 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +16 -15
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +87 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/AllSelectedExample.tsx +116 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +107 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +56 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +154 -0
- package/patternfly-docs/pages/index.js +1 -1
- package/release.config.js +1 -1
- package/src/DataView/DataView.tsx +28 -5
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +24 -0
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +175 -0
- package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +197 -0
- package/src/DataViewCheckboxFilter/index.ts +2 -0
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewFilters/DataViewFilters.test.tsx +21 -0
- package/src/DataViewFilters/DataViewFilters.tsx +144 -0
- package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +194 -0
- package/src/DataViewFilters/index.tsx +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +57 -0
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +83 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +54 -0
- package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +186 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +24 -0
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +54 -0
- package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +203 -0
- package/src/DataViewTextFilter/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +55 -22
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +52 -8
- package/src/Hooks/filters.test.tsx +89 -0
- package/src/Hooks/filters.ts +97 -0
- package/src/Hooks/index.ts +2 -0
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +69 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +7 -7
- package/src/Hooks/sort.test.tsx +84 -0
- package/src/Hooks/sort.ts +87 -0
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +52 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +24 -0
- package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -31
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -77
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +0 -65
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +0 -88
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -39
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -120
- /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Table } from '@patternfly/react-table';
|
|
4
|
+
import { DataViewTableHead } from './DataViewTableHead';
|
|
5
|
+
import { DataViewSelection } from '../InternalContext';
|
|
6
|
+
import { DataView } from '../DataView';
|
|
7
|
+
|
|
8
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
9
|
+
|
|
10
|
+
const ouiaId = 'HeaderExample';
|
|
11
|
+
|
|
12
|
+
describe('DataViewTableHead component', () => {
|
|
13
|
+
const mockSelection: DataViewSelection = {
|
|
14
|
+
onSelect: jest.fn(),
|
|
15
|
+
isSelected: jest.fn(),
|
|
16
|
+
isSelectDisabled: jest.fn(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('should render correctly', () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<Table>
|
|
22
|
+
<DataViewTableHead columns={columns} ouiaId={ouiaId} />
|
|
23
|
+
</Table>
|
|
24
|
+
);
|
|
25
|
+
expect(container).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('should render the tree table correctly when isTreeTable is true', () => {
|
|
29
|
+
const { container } = render(
|
|
30
|
+
<DataView selection={mockSelection}>
|
|
31
|
+
<Table>
|
|
32
|
+
<DataViewTableHead isTreeTable columns={columns} ouiaId={ouiaId} />
|
|
33
|
+
</Table>
|
|
34
|
+
</DataView>
|
|
35
|
+
);
|
|
36
|
+
expect(container).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should render selection column when selection is provided', () => {
|
|
40
|
+
const { container } = render(
|
|
41
|
+
<DataView selection={mockSelection}>
|
|
42
|
+
<Table>
|
|
43
|
+
<DataViewTableHead columns={columns} ouiaId={ouiaId} />
|
|
44
|
+
</Table>
|
|
45
|
+
</DataView>
|
|
46
|
+
);
|
|
47
|
+
expect(container).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Th,
|
|
4
|
+
Thead,
|
|
5
|
+
TheadProps,
|
|
6
|
+
Tr
|
|
7
|
+
} from '@patternfly/react-table';
|
|
8
|
+
import { useInternalContext } from '../InternalContext';
|
|
9
|
+
import { DataViewTh, isDataViewThObject } from '../DataViewTable';
|
|
10
|
+
|
|
11
|
+
/** extends TheadProps */
|
|
12
|
+
export interface DataViewTableHeadProps extends TheadProps {
|
|
13
|
+
/** Indicates whether table is a tree */
|
|
14
|
+
isTreeTable?: boolean;
|
|
15
|
+
/** Columns definition */
|
|
16
|
+
columns: DataViewTh[];
|
|
17
|
+
/** Custom OUIA ID */
|
|
18
|
+
ouiaId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DataViewTableHead: React.FC<DataViewTableHeadProps> = ({
|
|
22
|
+
isTreeTable = false,
|
|
23
|
+
columns,
|
|
24
|
+
ouiaId = 'DataViewTableHead',
|
|
25
|
+
...props
|
|
26
|
+
}: DataViewTableHeadProps) => {
|
|
27
|
+
const { selection } = useInternalContext();
|
|
28
|
+
const { onSelect, isSelected } = selection ?? {};
|
|
29
|
+
|
|
30
|
+
const cells = useMemo(() => [
|
|
31
|
+
onSelect && isSelected && !isTreeTable ? (
|
|
32
|
+
<Th key="row-select" screenReaderText='Data selection table head cell' />
|
|
33
|
+
) : null,
|
|
34
|
+
...columns.map((column, index) => (
|
|
35
|
+
<Th
|
|
36
|
+
key={index}
|
|
37
|
+
{...(isDataViewThObject(column) && (column?.props ?? {}))}
|
|
38
|
+
data-ouia-component-id={`${ouiaId}-th-${index}`}
|
|
39
|
+
>
|
|
40
|
+
{isDataViewThObject(column) ? column.cell : column}
|
|
41
|
+
</Th>
|
|
42
|
+
)
|
|
43
|
+
) ], [ columns, ouiaId, onSelect, isSelected, isTreeTable ]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Thead data-ouia-component-id={`${ouiaId}-thead`} {...props}>
|
|
47
|
+
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
48
|
+
{cells}
|
|
49
|
+
</Tr>
|
|
50
|
+
</Thead>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default DataViewTableHead;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DataViewTableHead component should render correctly 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<table
|
|
6
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
7
|
+
data-ouia-component-id="OUIA-Generated-Table-1"
|
|
8
|
+
data-ouia-component-type="PF6/Table"
|
|
9
|
+
data-ouia-safe="true"
|
|
10
|
+
role="grid"
|
|
11
|
+
>
|
|
12
|
+
<thead
|
|
13
|
+
class="pf-v6-c-table__thead"
|
|
14
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
15
|
+
>
|
|
16
|
+
<tr
|
|
17
|
+
class="pf-v6-c-table__tr"
|
|
18
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
19
|
+
data-ouia-component-type="PF6/TableRow"
|
|
20
|
+
data-ouia-safe="true"
|
|
21
|
+
>
|
|
22
|
+
<th
|
|
23
|
+
class="pf-v6-c-table__th"
|
|
24
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
25
|
+
scope="col"
|
|
26
|
+
tabindex="-1"
|
|
27
|
+
>
|
|
28
|
+
Repositories
|
|
29
|
+
</th>
|
|
30
|
+
<th
|
|
31
|
+
class="pf-v6-c-table__th"
|
|
32
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
33
|
+
scope="col"
|
|
34
|
+
tabindex="-1"
|
|
35
|
+
>
|
|
36
|
+
Branches
|
|
37
|
+
</th>
|
|
38
|
+
<th
|
|
39
|
+
class="pf-v6-c-table__th"
|
|
40
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
41
|
+
scope="col"
|
|
42
|
+
tabindex="-1"
|
|
43
|
+
>
|
|
44
|
+
Pull requests
|
|
45
|
+
</th>
|
|
46
|
+
<th
|
|
47
|
+
class="pf-v6-c-table__th"
|
|
48
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
49
|
+
scope="col"
|
|
50
|
+
tabindex="-1"
|
|
51
|
+
>
|
|
52
|
+
Workspaces
|
|
53
|
+
</th>
|
|
54
|
+
<th
|
|
55
|
+
class="pf-v6-c-table__th"
|
|
56
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
57
|
+
scope="col"
|
|
58
|
+
tabindex="-1"
|
|
59
|
+
>
|
|
60
|
+
Last commit
|
|
61
|
+
</th>
|
|
62
|
+
</tr>
|
|
63
|
+
</thead>
|
|
64
|
+
</table>
|
|
65
|
+
</div>
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
exports[`DataViewTableHead component should render selection column when selection is provided 1`] = `
|
|
69
|
+
<div>
|
|
70
|
+
<div
|
|
71
|
+
class="pf-v6-l-stack"
|
|
72
|
+
data-ouia-component-id="DataView-stack"
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
class="pf-v6-l-stack__item"
|
|
76
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
77
|
+
>
|
|
78
|
+
<table
|
|
79
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
80
|
+
data-ouia-component-id="OUIA-Generated-Table-3"
|
|
81
|
+
data-ouia-component-type="PF6/Table"
|
|
82
|
+
data-ouia-safe="true"
|
|
83
|
+
role="grid"
|
|
84
|
+
>
|
|
85
|
+
<thead
|
|
86
|
+
class="pf-v6-c-table__thead"
|
|
87
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
88
|
+
>
|
|
89
|
+
<tr
|
|
90
|
+
class="pf-v6-c-table__tr"
|
|
91
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
92
|
+
data-ouia-component-type="PF6/TableRow"
|
|
93
|
+
data-ouia-safe="true"
|
|
94
|
+
>
|
|
95
|
+
<th
|
|
96
|
+
class="pf-v6-c-table__th"
|
|
97
|
+
scope="col"
|
|
98
|
+
tabindex="-1"
|
|
99
|
+
>
|
|
100
|
+
<span
|
|
101
|
+
class="pf-v6-u-screen-reader"
|
|
102
|
+
>
|
|
103
|
+
Data selection table head cell
|
|
104
|
+
</span>
|
|
105
|
+
</th>
|
|
106
|
+
<th
|
|
107
|
+
class="pf-v6-c-table__th"
|
|
108
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
109
|
+
scope="col"
|
|
110
|
+
tabindex="-1"
|
|
111
|
+
>
|
|
112
|
+
Repositories
|
|
113
|
+
</th>
|
|
114
|
+
<th
|
|
115
|
+
class="pf-v6-c-table__th"
|
|
116
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
117
|
+
scope="col"
|
|
118
|
+
tabindex="-1"
|
|
119
|
+
>
|
|
120
|
+
Branches
|
|
121
|
+
</th>
|
|
122
|
+
<th
|
|
123
|
+
class="pf-v6-c-table__th"
|
|
124
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
125
|
+
scope="col"
|
|
126
|
+
tabindex="-1"
|
|
127
|
+
>
|
|
128
|
+
Pull requests
|
|
129
|
+
</th>
|
|
130
|
+
<th
|
|
131
|
+
class="pf-v6-c-table__th"
|
|
132
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
133
|
+
scope="col"
|
|
134
|
+
tabindex="-1"
|
|
135
|
+
>
|
|
136
|
+
Workspaces
|
|
137
|
+
</th>
|
|
138
|
+
<th
|
|
139
|
+
class="pf-v6-c-table__th"
|
|
140
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
141
|
+
scope="col"
|
|
142
|
+
tabindex="-1"
|
|
143
|
+
>
|
|
144
|
+
Last commit
|
|
145
|
+
</th>
|
|
146
|
+
</tr>
|
|
147
|
+
</thead>
|
|
148
|
+
</table>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
`;
|
|
153
|
+
|
|
154
|
+
exports[`DataViewTableHead component should render the tree table correctly when isTreeTable is true 1`] = `
|
|
155
|
+
<div>
|
|
156
|
+
<div
|
|
157
|
+
class="pf-v6-l-stack"
|
|
158
|
+
data-ouia-component-id="DataView-stack"
|
|
159
|
+
>
|
|
160
|
+
<div
|
|
161
|
+
class="pf-v6-l-stack__item"
|
|
162
|
+
data-ouia-component-id="DataView-stack-item-0"
|
|
163
|
+
>
|
|
164
|
+
<table
|
|
165
|
+
class="pf-v6-c-table pf-m-grid-md"
|
|
166
|
+
data-ouia-component-id="OUIA-Generated-Table-2"
|
|
167
|
+
data-ouia-component-type="PF6/Table"
|
|
168
|
+
data-ouia-safe="true"
|
|
169
|
+
role="grid"
|
|
170
|
+
>
|
|
171
|
+
<thead
|
|
172
|
+
class="pf-v6-c-table__thead"
|
|
173
|
+
data-ouia-component-id="HeaderExample-thead"
|
|
174
|
+
>
|
|
175
|
+
<tr
|
|
176
|
+
class="pf-v6-c-table__tr"
|
|
177
|
+
data-ouia-component-id="HeaderExample-tr-head"
|
|
178
|
+
data-ouia-component-type="PF6/TableRow"
|
|
179
|
+
data-ouia-safe="true"
|
|
180
|
+
>
|
|
181
|
+
<th
|
|
182
|
+
class="pf-v6-c-table__th"
|
|
183
|
+
data-ouia-component-id="HeaderExample-th-0"
|
|
184
|
+
scope="col"
|
|
185
|
+
tabindex="-1"
|
|
186
|
+
>
|
|
187
|
+
Repositories
|
|
188
|
+
</th>
|
|
189
|
+
<th
|
|
190
|
+
class="pf-v6-c-table__th"
|
|
191
|
+
data-ouia-component-id="HeaderExample-th-1"
|
|
192
|
+
scope="col"
|
|
193
|
+
tabindex="-1"
|
|
194
|
+
>
|
|
195
|
+
Branches
|
|
196
|
+
</th>
|
|
197
|
+
<th
|
|
198
|
+
class="pf-v6-c-table__th"
|
|
199
|
+
data-ouia-component-id="HeaderExample-th-2"
|
|
200
|
+
scope="col"
|
|
201
|
+
tabindex="-1"
|
|
202
|
+
>
|
|
203
|
+
Pull requests
|
|
204
|
+
</th>
|
|
205
|
+
<th
|
|
206
|
+
class="pf-v6-c-table__th"
|
|
207
|
+
data-ouia-component-id="HeaderExample-th-3"
|
|
208
|
+
scope="col"
|
|
209
|
+
tabindex="-1"
|
|
210
|
+
>
|
|
211
|
+
Workspaces
|
|
212
|
+
</th>
|
|
213
|
+
<th
|
|
214
|
+
class="pf-v6-c-table__th"
|
|
215
|
+
data-ouia-component-id="HeaderExample-th-4"
|
|
216
|
+
scope="col"
|
|
217
|
+
tabindex="-1"
|
|
218
|
+
>
|
|
219
|
+
Last commit
|
|
220
|
+
</th>
|
|
221
|
+
</tr>
|
|
222
|
+
</thead>
|
|
223
|
+
</table>
|
|
224
|
+
</div>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
`;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
|
|
4
|
+
import { DataView } from '../DataView';
|
|
5
|
+
import { DataViewTable } from '../DataViewTable';
|
|
6
|
+
import { DataViewSelection } from '../InternalContext';
|
|
7
|
+
|
|
8
|
+
const repositories = [
|
|
9
|
+
{
|
|
10
|
+
name: 'Repository one',
|
|
11
|
+
branches: 'Branch one',
|
|
12
|
+
prs: 'Pull request one',
|
|
13
|
+
workspaces: 'Workspace one',
|
|
14
|
+
lastCommit: 'Timestamp one',
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
name: 'Repository two',
|
|
18
|
+
branches: 'Branch two',
|
|
19
|
+
prs: 'Pull request two',
|
|
20
|
+
workspaces: 'Workspace two',
|
|
21
|
+
lastCommit: 'Timestamp two',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'Repository three',
|
|
25
|
+
branches: 'Branch three',
|
|
26
|
+
prs: 'Pull request three',
|
|
27
|
+
workspaces: 'Workspace three',
|
|
28
|
+
lastCommit: 'Timestamp three',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Repository four',
|
|
34
|
+
branches: 'Branch four',
|
|
35
|
+
prs: 'Pull request four',
|
|
36
|
+
workspaces: 'Workspace four',
|
|
37
|
+
lastCommit: 'Timestamp four',
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
name: 'Repository five',
|
|
41
|
+
branches: 'Branch five',
|
|
42
|
+
prs: 'Pull request five',
|
|
43
|
+
workspaces: 'Workspace five',
|
|
44
|
+
lastCommit: 'Timestamp five',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Repository six',
|
|
50
|
+
branches: 'Branch six',
|
|
51
|
+
prs: 'Pull request six',
|
|
52
|
+
workspaces: 'Workspace six',
|
|
53
|
+
lastCommit: 'Timestamp six',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// Build rows for DataViewTable
|
|
58
|
+
const buildRows = (repositories) => repositories.map((repo) => ({
|
|
59
|
+
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
|
|
60
|
+
id: repo.name,
|
|
61
|
+
...(repo.children ? { children: buildRows(repo.children) } : {}),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const rows = buildRows(repositories);
|
|
65
|
+
|
|
66
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
67
|
+
|
|
68
|
+
const ouiaId = 'TreeTableExample';
|
|
69
|
+
|
|
70
|
+
describe('DataViewTableTree component', () => {
|
|
71
|
+
const mockSelection: DataViewSelection = {
|
|
72
|
+
onSelect: jest.fn(),
|
|
73
|
+
isSelected: jest.fn(),
|
|
74
|
+
isSelectDisabled: jest.fn(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
test('should render the tree table correctly', () => {
|
|
78
|
+
const { container } = render(
|
|
79
|
+
<DataView selection={mockSelection}>
|
|
80
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
|
|
81
|
+
</DataView>
|
|
82
|
+
);
|
|
83
|
+
expect(container).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('should render tree table with an empty state', () => {
|
|
87
|
+
const { container } = render(
|
|
88
|
+
<DataView activeState="empty">
|
|
89
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ empty: "No data found" }} rows={[]} />
|
|
90
|
+
|
|
91
|
+
</DataView>
|
|
92
|
+
);
|
|
93
|
+
expect(container).toMatchSnapshot();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('should render tree table with an error state', () => {
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<DataView activeState="error">
|
|
99
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ error: "Some error" }} rows={[]} />
|
|
100
|
+
</DataView>
|
|
101
|
+
);
|
|
102
|
+
expect(container).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('should render tree table with a loading state', () => {
|
|
106
|
+
const { container } = render(
|
|
107
|
+
<DataView activeState="loading">
|
|
108
|
+
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ loading: "Data is loading" }} rows={[]} />
|
|
109
|
+
</DataView>
|
|
110
|
+
);
|
|
111
|
+
expect(container).toMatchSnapshot();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
TableProps,
|
|
5
|
+
Tbody,
|
|
6
|
+
Td,
|
|
7
|
+
TdProps,
|
|
8
|
+
TreeRowWrapper,
|
|
9
|
+
} from '@patternfly/react-table';
|
|
10
|
+
import { useInternalContext } from '../InternalContext';
|
|
11
|
+
import { DataViewTableHead } from '../DataViewTableHead';
|
|
12
|
+
import { DataViewTh, DataViewTrTree, isDataViewTdObject } from '../DataViewTable';
|
|
13
|
+
import { DataViewState } from '../DataView/DataView';
|
|
14
|
+
|
|
15
|
+
const getNodesAffectedBySelection = (
|
|
16
|
+
allRows: DataViewTrTree[],
|
|
17
|
+
node: DataViewTrTree,
|
|
18
|
+
isChecking: boolean,
|
|
19
|
+
isSelected?: (item: DataViewTrTree) => boolean
|
|
20
|
+
): DataViewTrTree[] => {
|
|
21
|
+
|
|
22
|
+
const getDescendants = (node: DataViewTrTree): DataViewTrTree[] =>
|
|
23
|
+
node.children ? node.children.flatMap(getDescendants).concat(node) : [ node ];
|
|
24
|
+
|
|
25
|
+
const findParent = (child: DataViewTrTree, rows: DataViewTrTree[]): DataViewTrTree | undefined =>
|
|
26
|
+
rows.find(row => row.children?.some(c => c === child)) ??
|
|
27
|
+
rows.flatMap(row => row.children ?? []).map(c => findParent(child, [ c ])).find(p => p);
|
|
28
|
+
|
|
29
|
+
const getAncestors = (node: DataViewTrTree): DataViewTrTree[] => {
|
|
30
|
+
const ancestors: DataViewTrTree[] = [];
|
|
31
|
+
let parent = findParent(node, allRows);
|
|
32
|
+
while (parent) {
|
|
33
|
+
ancestors.push(parent);
|
|
34
|
+
parent = findParent(parent, allRows);
|
|
35
|
+
}
|
|
36
|
+
return ancestors;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const affectedNodes = new Set([ node, ...getDescendants(node) ]);
|
|
40
|
+
|
|
41
|
+
getAncestors(node).forEach(ancestor => {
|
|
42
|
+
const allChildrenSelected = ancestor.children?.every(child => isSelected?.(child) || affectedNodes.has(child));
|
|
43
|
+
const anyChildAffected = ancestor.children?.some(child => affectedNodes.has(child) || child.id === node.id);
|
|
44
|
+
|
|
45
|
+
if (isChecking ? !isSelected?.(ancestor) && allChildrenSelected : isSelected?.(ancestor) && anyChildAffected) {
|
|
46
|
+
affectedNodes.add(ancestor);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return Array.from(affectedNodes);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/** extends TableProps */
|
|
55
|
+
export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'rows'> {
|
|
56
|
+
/** Columns definition */
|
|
57
|
+
columns: DataViewTh[];
|
|
58
|
+
/** Current page rows */
|
|
59
|
+
rows: DataViewTrTree[];
|
|
60
|
+
/** Table head states to be displayed when active */
|
|
61
|
+
headStates?: Partial<Record<DataViewState | string, React.ReactNode>>
|
|
62
|
+
/** Table body states to be displayed when active */
|
|
63
|
+
bodyStates?: Partial<Record<DataViewState | string, React.ReactNode>>
|
|
64
|
+
/** Optional icon for the leaf rows */
|
|
65
|
+
leafIcon?: React.ReactNode;
|
|
66
|
+
/** Optional icon for the expanded parent rows */
|
|
67
|
+
expandedIcon?: React.ReactNode;
|
|
68
|
+
/** Optional icon for the collapsed parent rows */
|
|
69
|
+
collapsedIcon?: React.ReactNode;
|
|
70
|
+
/** Custom OUIA ID */
|
|
71
|
+
ouiaId?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
|
|
75
|
+
columns,
|
|
76
|
+
rows,
|
|
77
|
+
headStates,
|
|
78
|
+
bodyStates,
|
|
79
|
+
leafIcon = null,
|
|
80
|
+
expandedIcon = null,
|
|
81
|
+
collapsedIcon = null,
|
|
82
|
+
ouiaId = 'DataViewTableTree',
|
|
83
|
+
...props
|
|
84
|
+
}: DataViewTableTreeProps) => {
|
|
85
|
+
const { selection, activeState } = useInternalContext();
|
|
86
|
+
const { onSelect, isSelected, isSelectDisabled } = selection ?? {};
|
|
87
|
+
const [ expandedNodeIds, setExpandedNodeIds ] = React.useState<string[]>([]);
|
|
88
|
+
const [ expandedDetailsNodeNames, setExpandedDetailsNodeIds ] = React.useState<string[]>([]);
|
|
89
|
+
|
|
90
|
+
const activeHeadState = useMemo(() => activeState ? headStates?.[activeState] : undefined, [ activeState, headStates ]);
|
|
91
|
+
const activeBodyState = useMemo(() => activeState ? bodyStates?.[activeState] : undefined, [ activeState, bodyStates ]);
|
|
92
|
+
|
|
93
|
+
const nodes = useMemo(() => {
|
|
94
|
+
|
|
95
|
+
const renderRows = (
|
|
96
|
+
[ node, ...remainingNodes ]: DataViewTrTree[],
|
|
97
|
+
level = 1,
|
|
98
|
+
posinset = 1,
|
|
99
|
+
rowIndex = 0,
|
|
100
|
+
isHidden = false
|
|
101
|
+
): React.ReactNode[] => {
|
|
102
|
+
if (!node) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const isExpanded = expandedNodeIds.includes(node.id);
|
|
106
|
+
const isDetailsExpanded = expandedDetailsNodeNames.includes(node.id);
|
|
107
|
+
const isChecked = isSelected?.(node);
|
|
108
|
+
let icon = leafIcon;
|
|
109
|
+
if (node.children) {
|
|
110
|
+
icon = isExpanded ? expandedIcon : collapsedIcon;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const treeRow: TdProps['treeRow'] = {
|
|
114
|
+
onCollapse: () =>
|
|
115
|
+
setExpandedNodeIds(prevExpanded => {
|
|
116
|
+
const otherExpandedNodeIds = prevExpanded.filter(id => id !== node.id);
|
|
117
|
+
return isExpanded ? otherExpandedNodeIds : [ ...otherExpandedNodeIds, node.id ];
|
|
118
|
+
}),
|
|
119
|
+
onToggleRowDetails: () =>
|
|
120
|
+
setExpandedDetailsNodeIds(prevDetailsExpanded => {
|
|
121
|
+
const otherDetailsExpandedNodeIds = prevDetailsExpanded.filter(id => id !== node.id);
|
|
122
|
+
return isDetailsExpanded ? otherDetailsExpandedNodeIds : [ ...otherDetailsExpandedNodeIds, node.id ];
|
|
123
|
+
}),
|
|
124
|
+
onCheckChange: (isSelectDisabled?.(node) || !onSelect) ? undefined : (_event, isChecking) => onSelect?.(isChecking, getNodesAffectedBySelection(rows, node, isChecking, isSelected)),
|
|
125
|
+
rowIndex,
|
|
126
|
+
props: {
|
|
127
|
+
isExpanded,
|
|
128
|
+
isDetailsExpanded,
|
|
129
|
+
isHidden,
|
|
130
|
+
'aria-level': level,
|
|
131
|
+
'aria-posinset': posinset,
|
|
132
|
+
'aria-setsize': node.children?.length ?? 0,
|
|
133
|
+
isChecked,
|
|
134
|
+
checkboxId: `checkbox_id_${node.id?.toLowerCase().replace(/\s+/g, '_')}`,
|
|
135
|
+
icon,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const childRows = node.children?.length
|
|
140
|
+
? renderRows(node.children, level + 1, 1, rowIndex + 1, !isExpanded || isHidden)
|
|
141
|
+
: [];
|
|
142
|
+
|
|
143
|
+
return [
|
|
144
|
+
<TreeRowWrapper key={node.id} row={{ props: treeRow.props }} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
145
|
+
{node.row.map((cell, colIndex) => {
|
|
146
|
+
const cellIsObject = isDataViewTdObject(cell);
|
|
147
|
+
return (
|
|
148
|
+
<Td
|
|
149
|
+
key={colIndex}
|
|
150
|
+
treeRow={colIndex === 0 ? treeRow : undefined}
|
|
151
|
+
{...(cellIsObject && (cell?.props ?? {}))}
|
|
152
|
+
data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}
|
|
153
|
+
>
|
|
154
|
+
{cellIsObject ? cell.cell : cell}
|
|
155
|
+
</Td>
|
|
156
|
+
);
|
|
157
|
+
})}
|
|
158
|
+
</TreeRowWrapper>,
|
|
159
|
+
...childRows,
|
|
160
|
+
...renderRows(remainingNodes, level, posinset + 1, rowIndex + 1 + childRows.length, isHidden),
|
|
161
|
+
];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return renderRows(rows);
|
|
165
|
+
}, [
|
|
166
|
+
rows,
|
|
167
|
+
expandedNodeIds,
|
|
168
|
+
expandedDetailsNodeNames,
|
|
169
|
+
leafIcon,
|
|
170
|
+
expandedIcon,
|
|
171
|
+
collapsedIcon,
|
|
172
|
+
isSelected,
|
|
173
|
+
onSelect,
|
|
174
|
+
isSelectDisabled,
|
|
175
|
+
ouiaId
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<Table isTreeTable aria-label="Data table" ouiaId={ouiaId} {...props}>
|
|
180
|
+
{activeHeadState || <DataViewTableHead isTreeTable columns={columns} ouiaId={ouiaId} />}
|
|
181
|
+
{activeBodyState || <Tbody>{nodes}</Tbody>}
|
|
182
|
+
</Table>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default DataViewTableTree;
|