@patternfly/react-data-view 6.1.0-prerelease.1 → 7.0.0-prerelease.2
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 +12 -0
- package/dist/cjs/DataView/DataView.js +14 -3
- 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/DataViewTable/DataViewTable.d.ts +41 -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 +18 -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 +13 -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 +24 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +132 -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/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/Hooks/pagination.d.ts +13 -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 -6
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/InternalContext/InternalContext.d.ts +25 -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 +12 -0
- package/dist/cjs/index.js +20 -2
- package/dist/dynamic/DataViewEventsContext/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/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +12 -0
- package/dist/esm/DataView/DataView.js +13 -2
- 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/DataViewTable/DataViewTable.d.ts +41 -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 +18 -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 +13 -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 +24 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +105 -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/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/Hooks/pagination.d.ts +13 -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 -6
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/InternalContext/InternalContext.d.ts +25 -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 +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +80 -5
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +4 -4
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +32 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +108 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +14 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +28 -37
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/patternfly-docs/pages/index.js +1 -1
- package/src/DataView/DataView.tsx +25 -3
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +37 -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 +82 -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 +53 -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 +164 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +8 -8
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +68 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +6 -7
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +51 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { Pagination } from '@patternfly/react-core';
|
|
3
|
-
import {
|
|
3
|
+
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
4
4
|
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
-
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
-
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
5
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
7
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
7
8
|
|
|
8
9
|
const perPageOptions = [
|
|
9
10
|
{ title: '5', value: 5 },
|
|
10
11
|
{ title: '10', value: 10 }
|
|
11
|
-
]
|
|
12
|
+
];
|
|
12
13
|
|
|
13
14
|
interface Repository {
|
|
14
15
|
name: string;
|
|
@@ -16,50 +17,40 @@ interface Repository {
|
|
|
16
17
|
prs: string | null;
|
|
17
18
|
workspaces: string;
|
|
18
19
|
lastCommit: string;
|
|
19
|
-
}
|
|
20
|
+
};
|
|
20
21
|
|
|
21
22
|
const repositories: Repository[] = [
|
|
22
|
-
{ name: 'one', branches: '
|
|
23
|
-
{ name: '
|
|
24
|
-
{ name: '
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
23
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
24
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
25
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
26
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
27
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
28
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
28
29
|
];
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
prs: 'Pull requests',
|
|
34
|
-
workspaces: 'Workspaces',
|
|
35
|
-
lastCommit: 'Last commit'
|
|
36
|
-
};
|
|
31
|
+
const rows = repositories.map(item => Object.values(item));
|
|
32
|
+
|
|
33
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
37
34
|
|
|
38
35
|
const ouiaId = 'LayoutExample';
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
const
|
|
37
|
+
const MyTable: React.FunctionComponent = () => {
|
|
38
|
+
const [ searchParams, setSearchParams ] = useSearchParams()
|
|
39
|
+
const pagination = useDataViewPagination({ perPage: 5, searchParams, setSearchParams });
|
|
42
40
|
const { page, perPage } = pagination;
|
|
43
41
|
|
|
44
|
-
const
|
|
45
|
-
|
|
42
|
+
const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
|
|
46
43
|
return (
|
|
47
44
|
<DataView>
|
|
48
45
|
<DataViewToolbar ouiaId='DataViewHeader' pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
49
|
-
<
|
|
50
|
-
<Thead data-ouia-component-id={`${ouiaId}-thead`}>
|
|
51
|
-
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
52
|
-
{Object.values(cols).map((column, index) => <Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>)}
|
|
53
|
-
</Tr>
|
|
54
|
-
</Thead>
|
|
55
|
-
<Tbody>
|
|
56
|
-
{data.map((repo, rowIndex) => (
|
|
57
|
-
<Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
58
|
-
{Object.keys(cols).map((column, colIndex) => <Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>)}
|
|
59
|
-
</Tr>
|
|
60
|
-
))}
|
|
61
|
-
</Tbody>
|
|
62
|
-
</Table>
|
|
46
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
63
47
|
<DataViewToolbar ouiaId='DataViewFooter' pagination={<Pagination isCompact perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
64
48
|
</DataView>
|
|
65
|
-
)
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
53
|
+
<BrowserRouter>
|
|
54
|
+
<MyTable/>
|
|
55
|
+
</BrowserRouter>
|
|
56
|
+
);
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
3
2
|
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
4
3
|
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
|
|
5
4
|
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
5
|
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
6
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
7
7
|
|
|
8
8
|
interface Repository {
|
|
9
9
|
name: string;
|
|
@@ -14,35 +14,31 @@ interface Repository {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const repositories: Repository[] = [
|
|
17
|
-
{ name: 'one', branches: '
|
|
18
|
-
{ name: '
|
|
19
|
-
{ name: '
|
|
20
|
-
{ name: '
|
|
21
|
-
{ name: '
|
|
22
|
-
{ name: '
|
|
17
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
18
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
19
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
20
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
21
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
22
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
prs: 'Pull requests',
|
|
29
|
-
workspaces: 'Workspaces',
|
|
30
|
-
lastCommit: 'Last commit'
|
|
31
|
-
};
|
|
25
|
+
const rows = repositories.map(item => Object.values(item));
|
|
26
|
+
|
|
27
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
32
28
|
|
|
33
29
|
const ouiaId = 'LayoutExample';
|
|
34
30
|
|
|
35
31
|
export const BasicExample: React.FunctionComponent = () => {
|
|
36
|
-
const selection = useDataViewSelection({});
|
|
37
|
-
const { selected, onSelect
|
|
32
|
+
const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
|
|
33
|
+
const { selected, onSelect } = selection;
|
|
38
34
|
|
|
39
35
|
const handleBulkSelect = (value: BulkSelectValue) => {
|
|
40
36
|
value === BulkSelectValue.none && onSelect(false);
|
|
41
|
-
value === BulkSelectValue.all && onSelect(true,
|
|
37
|
+
value === BulkSelectValue.all && onSelect(true, rows);
|
|
42
38
|
};
|
|
43
39
|
|
|
44
40
|
return (
|
|
45
|
-
<DataView>
|
|
41
|
+
<DataView selection={selection}>
|
|
46
42
|
<DataViewToolbar
|
|
47
43
|
ouiaId='DataViewHeader'
|
|
48
44
|
bulkSelect={
|
|
@@ -55,34 +51,7 @@ export const BasicExample: React.FunctionComponent = () => {
|
|
|
55
51
|
/>
|
|
56
52
|
}
|
|
57
53
|
/>
|
|
58
|
-
<
|
|
59
|
-
<Thead data-ouia-component-id={`${ouiaId}-thead`}>
|
|
60
|
-
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
61
|
-
<Th key="row-select"/>
|
|
62
|
-
{Object.values(cols).map((column, index) => (
|
|
63
|
-
<Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>
|
|
64
|
-
))}
|
|
65
|
-
</Tr>
|
|
66
|
-
</Thead>
|
|
67
|
-
<Tbody>
|
|
68
|
-
{repositories.map((repo, rowIndex) => (
|
|
69
|
-
<Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
70
|
-
<Td
|
|
71
|
-
key={`select-${rowIndex}`}
|
|
72
|
-
select={{
|
|
73
|
-
rowIndex,
|
|
74
|
-
onSelect: (_event, isSelecting) => onSelect(isSelecting, repo),
|
|
75
|
-
isSelected: isSelected(repo),
|
|
76
|
-
isDisabled: false
|
|
77
|
-
}}
|
|
78
|
-
/>
|
|
79
|
-
{Object.keys(cols).map((column, colIndex) => (
|
|
80
|
-
<Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>
|
|
81
|
-
))}
|
|
82
|
-
</Tr>
|
|
83
|
-
))}
|
|
84
|
-
</Tbody>
|
|
85
|
-
</Table>
|
|
54
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
86
55
|
</DataView>
|
|
87
56
|
);
|
|
88
57
|
}
|
|
@@ -11,7 +11,7 @@ source: react
|
|
|
11
11
|
# If you use typescript, the name of the interface to display props for
|
|
12
12
|
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
13
13
|
sortValue: 2
|
|
14
|
-
propComponents: ['DataView']
|
|
14
|
+
propComponents: ['DataView', 'DataViewState']
|
|
15
15
|
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md
|
|
16
16
|
---
|
|
17
17
|
import { useMemo } from 'react';
|
|
@@ -19,6 +19,7 @@ import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-d
|
|
|
19
19
|
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
|
|
20
20
|
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
21
21
|
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
22
|
+
import DataViewTable from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
22
23
|
|
|
23
24
|
The **data view** component renders record data in a configured layout.
|
|
24
25
|
|
package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { Pagination } from '@patternfly/react-core';
|
|
3
|
-
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
4
3
|
import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
4
|
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
|
|
6
5
|
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
7
7
|
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
8
8
|
|
|
9
9
|
const perPageOptions = [
|
|
@@ -20,51 +20,47 @@ interface Repository {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const repositories: Repository[] = [
|
|
23
|
-
{ name: 'one', branches: '
|
|
24
|
-
{ name: '
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
28
|
-
{ name: '
|
|
23
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
24
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
25
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
26
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
27
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
28
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
29
29
|
];
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
prs: 'Pull requests',
|
|
35
|
-
workspaces: 'Workspaces',
|
|
36
|
-
lastCommit: 'Last commit'
|
|
37
|
-
};
|
|
31
|
+
const rows = repositories.map(item => Object.values(item));
|
|
32
|
+
|
|
33
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
38
34
|
|
|
39
35
|
const ouiaId = 'LayoutExample';
|
|
40
36
|
|
|
41
37
|
export const BasicExample: React.FunctionComponent = () => {
|
|
42
38
|
const pagination = useDataViewPagination({ perPage: 5 });
|
|
43
39
|
const { page, perPage } = pagination;
|
|
44
|
-
const selection = useDataViewSelection({});
|
|
40
|
+
const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
|
|
45
41
|
const { selected, onSelect, isSelected } = selection;
|
|
46
42
|
|
|
47
|
-
const
|
|
43
|
+
const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
|
|
48
44
|
|
|
49
45
|
const handleBulkSelect = (value: BulkSelectValue) => {
|
|
50
46
|
value === BulkSelectValue.none && onSelect(false);
|
|
51
|
-
value === BulkSelectValue.all && onSelect(true,
|
|
52
|
-
value === BulkSelectValue.nonePage && onSelect(false,
|
|
53
|
-
value === BulkSelectValue.page && onSelect(true,
|
|
47
|
+
value === BulkSelectValue.all && onSelect(true, rows);
|
|
48
|
+
value === BulkSelectValue.nonePage && onSelect(false, pageRows);
|
|
49
|
+
value === BulkSelectValue.page && onSelect(true, pageRows);
|
|
54
50
|
};
|
|
55
51
|
|
|
56
52
|
return (
|
|
57
|
-
<DataView>
|
|
53
|
+
<DataView selection={selection}>
|
|
58
54
|
<DataViewToolbar
|
|
59
55
|
ouiaId='LayoutExampleHeader'
|
|
60
56
|
bulkSelect={
|
|
61
57
|
<BulkSelect
|
|
62
58
|
canSelectAll
|
|
63
|
-
pageCount={
|
|
59
|
+
pageCount={pageRows.length}
|
|
64
60
|
totalCount={repositories.length}
|
|
65
61
|
selectedCount={selected.length}
|
|
66
|
-
pageSelected={
|
|
67
|
-
pagePartiallySelected={
|
|
62
|
+
pageSelected={pageRows.every(item => isSelected(item))}
|
|
63
|
+
pagePartiallySelected={pageRows.some(item => isSelected(item)) && !pageRows.every(item => isSelected(item))}
|
|
68
64
|
onSelect={handleBulkSelect}
|
|
69
65
|
/>
|
|
70
66
|
}
|
|
@@ -76,34 +72,7 @@ export const BasicExample: React.FunctionComponent = () => {
|
|
|
76
72
|
/>
|
|
77
73
|
}
|
|
78
74
|
/>
|
|
79
|
-
<
|
|
80
|
-
<Thead data-ouia-component-id={`${ouiaId}-thead`}>
|
|
81
|
-
<Tr ouiaId={`${ouiaId}-tr-head`}>
|
|
82
|
-
<Th key="row-select"/>
|
|
83
|
-
{Object.values(cols).map((column, index) => (
|
|
84
|
-
<Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>
|
|
85
|
-
))}
|
|
86
|
-
</Tr>
|
|
87
|
-
</Thead>
|
|
88
|
-
<Tbody>
|
|
89
|
-
{pageData.map((repo, rowIndex) => (
|
|
90
|
-
<Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
|
|
91
|
-
<Td
|
|
92
|
-
key={`select-${rowIndex}`}
|
|
93
|
-
select={{
|
|
94
|
-
rowIndex,
|
|
95
|
-
onSelect: (_event, isSelecting) => onSelect(isSelecting, repo),
|
|
96
|
-
isSelected: isSelected(repo),
|
|
97
|
-
isDisabled: false
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
{Object.keys(cols).map((column, colIndex) => (
|
|
101
|
-
<Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>
|
|
102
|
-
))}
|
|
103
|
-
</Tr>
|
|
104
|
-
))}
|
|
105
|
-
</Tbody>
|
|
106
|
-
</Table>
|
|
75
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
107
76
|
<DataViewToolbar
|
|
108
77
|
ouiaId='LayoutExampleFooter'
|
|
109
78
|
pagination={
|
|
@@ -10,7 +10,7 @@ const centerStyle = {
|
|
|
10
10
|
|
|
11
11
|
const IndexPage = () => {
|
|
12
12
|
return (
|
|
13
|
-
<PageSection style={centerStyle}>
|
|
13
|
+
<PageSection hasBodyWrapper={false} style={centerStyle}>
|
|
14
14
|
<div style={{ flex: 'none', textAlign: 'center' }}>
|
|
15
15
|
<Title size="4xl" headingLevel="h1">
|
|
16
16
|
My extension docs
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Stack, StackItem } from '@patternfly/react-core';
|
|
3
|
+
import { DataViewSelection, InternalContextProvider } from '../InternalContext';
|
|
4
|
+
|
|
5
|
+
export const DataViewState = {
|
|
6
|
+
empty: 'empty',
|
|
7
|
+
loading: 'loading',
|
|
8
|
+
error: 'error'
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
12
|
+
|
|
3
13
|
export interface DataViewProps {
|
|
4
14
|
/** Content rendered inside the data view */
|
|
5
15
|
children: React.ReactNode;
|
|
6
16
|
/** Custom OUIA ID */
|
|
7
17
|
ouiaId?: string;
|
|
18
|
+
/** Selection context configuration */
|
|
19
|
+
selection?: DataViewSelection;
|
|
20
|
+
/** Currently active state */
|
|
21
|
+
activeState?: DataViewState | string;
|
|
8
22
|
}
|
|
9
23
|
|
|
10
|
-
export
|
|
24
|
+
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
25
|
+
|
|
26
|
+
const DataViewImplementation: React.FC<DataViewImpementationProps> = ({
|
|
11
27
|
children, ouiaId = 'DataView', ...props
|
|
12
|
-
}:
|
|
13
|
-
<Stack data-ouia-component-id={`${ouiaId}-stack
|
|
28
|
+
}: DataViewImpementationProps) => (
|
|
29
|
+
<Stack data-ouia-component-id={`${ouiaId}-stack`} {...props}>
|
|
14
30
|
{React.Children.map(children, (child, index) => (
|
|
15
31
|
<StackItem data-ouia-component-id={`${ouiaId}-stack-item-${index}`}>
|
|
16
32
|
{child}
|
|
@@ -19,4 +35,10 @@ export const DataView: React.FC<DataViewProps> = ({
|
|
|
19
35
|
</Stack>
|
|
20
36
|
)
|
|
21
37
|
|
|
38
|
+
export const DataView: React.FC<DataViewProps> = ({ children, selection, activeState, ...props }: DataViewProps) => (
|
|
39
|
+
<InternalContextProvider selection={selection} activeState={activeState} >
|
|
40
|
+
<DataViewImplementation {...props}>{children}</DataViewImplementation>
|
|
41
|
+
</InternalContextProvider>
|
|
42
|
+
);
|
|
43
|
+
|
|
22
44
|
export default DataView;
|
|
@@ -7,7 +7,7 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
7
7
|
<div>
|
|
8
8
|
<div
|
|
9
9
|
class="pf-v6-l-stack"
|
|
10
|
-
data-ouia-component-id="DataView-stack
|
|
10
|
+
data-ouia-component-id="DataView-stack"
|
|
11
11
|
>
|
|
12
12
|
<div
|
|
13
13
|
class="pf-v6-l-stack__item"
|
|
@@ -45,7 +45,7 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
45
45
|
"container": <div>
|
|
46
46
|
<div
|
|
47
47
|
class="pf-v6-l-stack"
|
|
48
|
-
data-ouia-component-id="DataView-stack
|
|
48
|
+
data-ouia-component-id="DataView-stack"
|
|
49
49
|
>
|
|
50
50
|
<div
|
|
51
51
|
class="pf-v6-l-stack__item"
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { useDataViewEventsContext, DataViewEventsProvider, EventTypes } from './DataViewEventsContext';
|
|
4
|
+
|
|
5
|
+
let id = 0;
|
|
6
|
+
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
Object.defineProperty(global, 'crypto', {
|
|
9
|
+
value: {
|
|
10
|
+
randomUUID: jest.fn(() => `mocked-uuid-${id++}`),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('DataViewEventsContext', () => {
|
|
16
|
+
test('should provide context value and allow subscriptions', () => {
|
|
17
|
+
const callback = jest.fn();
|
|
18
|
+
|
|
19
|
+
const TestComponent = () => {
|
|
20
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
24
|
+
return () => unsubscribe();
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { getByText } = render(
|
|
34
|
+
<DataViewEventsProvider>
|
|
35
|
+
<TestComponent />
|
|
36
|
+
</DataViewEventsProvider>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
fireEvent.click(getByText('Trigger'));
|
|
40
|
+
expect(callback).toHaveBeenCalledWith('some payload');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should handle unsubscribing correctly', () => {
|
|
44
|
+
const callback = jest.fn();
|
|
45
|
+
|
|
46
|
+
const TestComponent = () => {
|
|
47
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
48
|
+
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
const unsubscribe = subscribe(EventTypes.rowClick, callback);
|
|
51
|
+
unsubscribe();
|
|
52
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const { getByText } = render(
|
|
61
|
+
<DataViewEventsProvider>
|
|
62
|
+
<TestComponent />
|
|
63
|
+
</DataViewEventsProvider>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
fireEvent.click(getByText('Trigger'));
|
|
67
|
+
|
|
68
|
+
expect(callback).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should handle multiple subscriptions and trigger events correctly', () => {
|
|
72
|
+
const callback1 = jest.fn();
|
|
73
|
+
const callback2 = jest.fn();
|
|
74
|
+
|
|
75
|
+
const TestComponent = () => {
|
|
76
|
+
const { subscribe, trigger } = useDataViewEventsContext();
|
|
77
|
+
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const unsubscribe1 = subscribe(EventTypes.rowClick, callback1);
|
|
80
|
+
const unsubscribe2 = subscribe(EventTypes.rowClick, callback2);
|
|
81
|
+
|
|
82
|
+
return () => {
|
|
83
|
+
unsubscribe1();
|
|
84
|
+
unsubscribe2();
|
|
85
|
+
};
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<button onClick={() => trigger(EventTypes.rowClick, 'some payload')}>Trigger</button>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const { getByText } = render(
|
|
95
|
+
<DataViewEventsProvider>
|
|
96
|
+
<TestComponent />
|
|
97
|
+
</DataViewEventsProvider>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
fireEvent.click(getByText('Trigger'));
|
|
101
|
+
|
|
102
|
+
expect(callback1).toHaveBeenCalledWith('some payload');
|
|
103
|
+
expect(callback2).toHaveBeenCalledWith('some payload');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
PropsWithChildren,
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
export const EventTypes = {
|
|
10
|
+
rowClick: 'rowClick'
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export type DataViewEvent = typeof EventTypes[keyof typeof EventTypes];
|
|
14
|
+
|
|
15
|
+
type Callback = (...args: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
16
|
+
interface Subscriptions { [id: string]: Callback }
|
|
17
|
+
type EventSubscriptions = { [event in DataViewEvent]: Subscriptions };
|
|
18
|
+
type Subscribe = (event: DataViewEvent, callback: Callback) => () => void;
|
|
19
|
+
type Trigger = (event: DataViewEvent, ...payload: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
20
|
+
|
|
21
|
+
export interface DataViewEventsContextValue {
|
|
22
|
+
subscribe: Subscribe;
|
|
23
|
+
trigger: Trigger;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DataViewEventsContext = createContext<DataViewEventsContextValue>({
|
|
27
|
+
subscribe: () => () => null,
|
|
28
|
+
trigger: () => null
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const DataViewEventsProvider = ({ children }: PropsWithChildren) => {
|
|
32
|
+
const [ subscriptions, setSubscriptions ] = useState<EventSubscriptions>({
|
|
33
|
+
[EventTypes.rowClick]: {}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const subscribe: Subscribe = (event, callback) => {
|
|
37
|
+
const id = crypto.randomUUID();
|
|
38
|
+
|
|
39
|
+
// set new subscription
|
|
40
|
+
setSubscriptions(prevSubscriptions => ({
|
|
41
|
+
...prevSubscriptions,
|
|
42
|
+
[event]: { ...prevSubscriptions[event], [id]: callback }
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
// return unsubscribe function
|
|
46
|
+
return () => {
|
|
47
|
+
setSubscriptions(prevSubscriptions => {
|
|
48
|
+
const updatedSubscriptions = { ...prevSubscriptions };
|
|
49
|
+
delete updatedSubscriptions[event][id];
|
|
50
|
+
return updatedSubscriptions;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const trigger = useCallback((event: DataViewEvent, ...payload: unknown[]) => {
|
|
56
|
+
Object.values(subscriptions[event]).forEach(callback => {
|
|
57
|
+
callback(...payload);
|
|
58
|
+
});
|
|
59
|
+
}, [ subscriptions ]);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<DataViewEventsContext.Provider value={{ subscribe, trigger }}>
|
|
63
|
+
{children}
|
|
64
|
+
</DataViewEventsContext.Provider>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const useDataViewEventsContext = () => useContext(DataViewEventsContext);
|
|
69
|
+
|
|
70
|
+
export default DataViewEventsContext;
|