@patternfly/react-data-view 7.0.0-prerelease.1 → 7.0.0-prerelease.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 (156) hide show
  1. package/dist/cjs/DataView/DataView.d.ts +12 -0
  2. package/dist/cjs/DataView/DataView.js +14 -3
  3. package/dist/cjs/DataView/DataView.test.js +3 -4
  4. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  5. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
  6. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  7. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
  8. package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
  9. package/dist/cjs/DataViewEventsContext/index.js +23 -0
  10. package/dist/cjs/DataViewTable/DataViewTable.d.ts +41 -0
  11. package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
  12. package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
  13. package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
  14. package/dist/cjs/DataViewTable/index.d.ts +2 -0
  15. package/dist/cjs/DataViewTable/index.js +23 -0
  16. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
  17. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
  18. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  19. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
  20. package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
  21. package/dist/cjs/DataViewTableBasic/index.js +23 -0
  22. package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +13 -0
  23. package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
  24. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  25. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
  26. package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
  27. package/dist/cjs/DataViewTableHead/index.js +23 -0
  28. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +24 -0
  29. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +132 -0
  30. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  31. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
  32. package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
  33. package/dist/cjs/DataViewTableTree/index.js +23 -0
  34. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
  35. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
  36. package/dist/cjs/Hooks/pagination.d.ts +9 -5
  37. package/dist/cjs/Hooks/pagination.js +8 -8
  38. package/dist/cjs/Hooks/pagination.test.js +0 -52
  39. package/dist/cjs/Hooks/selection.d.ts +3 -3
  40. package/dist/cjs/Hooks/selection.js +4 -6
  41. package/dist/cjs/Hooks/selection.test.js +4 -4
  42. package/dist/cjs/InternalContext/InternalContext.d.ts +25 -0
  43. package/dist/cjs/InternalContext/InternalContext.js +40 -0
  44. package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
  45. package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
  46. package/dist/cjs/InternalContext/index.d.ts +2 -0
  47. package/dist/cjs/InternalContext/index.js +23 -0
  48. package/dist/cjs/index.d.ts +12 -0
  49. package/dist/cjs/index.js +20 -2
  50. package/dist/dynamic/DataViewEventsContext/package.json +1 -0
  51. package/dist/dynamic/DataViewTable/package.json +1 -0
  52. package/dist/dynamic/DataViewTableBasic/package.json +1 -0
  53. package/dist/dynamic/DataViewTableHead/package.json +1 -0
  54. package/dist/dynamic/DataViewTableTree/package.json +1 -0
  55. package/dist/dynamic/InternalContext/package.json +1 -0
  56. package/dist/esm/DataView/DataView.d.ts +12 -0
  57. package/dist/esm/DataView/DataView.js +13 -2
  58. package/dist/esm/DataView/DataView.test.js +3 -4
  59. package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  60. package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
  61. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  62. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
  63. package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
  64. package/dist/esm/DataViewEventsContext/index.js +2 -0
  65. package/dist/esm/DataViewTable/DataViewTable.d.ts +41 -0
  66. package/dist/esm/DataViewTable/DataViewTable.js +8 -0
  67. package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
  68. package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
  69. package/dist/esm/DataViewTable/index.d.ts +2 -0
  70. package/dist/esm/DataViewTable/index.js +2 -0
  71. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
  72. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
  73. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  74. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
  75. package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
  76. package/dist/esm/DataViewTableBasic/index.js +2 -0
  77. package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +13 -0
  78. package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
  79. package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  80. package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
  81. package/dist/esm/DataViewTableHead/index.d.ts +2 -0
  82. package/dist/esm/DataViewTableHead/index.js +2 -0
  83. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +24 -0
  84. package/dist/esm/DataViewTableTree/DataViewTableTree.js +105 -0
  85. package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  86. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
  87. package/dist/esm/DataViewTableTree/index.d.ts +2 -0
  88. package/dist/esm/DataViewTableTree/index.js +2 -0
  89. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
  90. package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
  91. package/dist/esm/Hooks/pagination.d.ts +9 -5
  92. package/dist/esm/Hooks/pagination.js +9 -9
  93. package/dist/esm/Hooks/pagination.test.js +0 -52
  94. package/dist/esm/Hooks/selection.d.ts +3 -3
  95. package/dist/esm/Hooks/selection.js +4 -6
  96. package/dist/esm/Hooks/selection.test.js +4 -4
  97. package/dist/esm/InternalContext/InternalContext.d.ts +25 -0
  98. package/dist/esm/InternalContext/InternalContext.js +12 -0
  99. package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
  100. package/dist/esm/InternalContext/InternalContext.test.js +51 -0
  101. package/dist/esm/InternalContext/index.d.ts +2 -0
  102. package/dist/esm/InternalContext/index.js +2 -0
  103. package/dist/esm/index.d.ts +12 -0
  104. package/dist/esm/index.js +12 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -0
  106. package/package.json +11 -10
  107. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +80 -5
  108. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +57 -0
  109. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +45 -0
  110. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +67 -0
  111. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
  112. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +71 -0
  113. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarActionsExample.tsx +27 -0
  114. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +4 -4
  115. package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +32 -0
  116. package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +108 -0
  117. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +12 -11
  118. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +20 -37
  119. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
  120. package/patternfly-docs/content/extensions/data-view/examples/Layout/AbstractLayoutExample.tsx +3 -4
  121. package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +2 -1
  122. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
  123. package/patternfly-docs/pages/index.js +1 -1
  124. package/release.config.js +1 -5
  125. package/src/DataView/DataView.test.tsx +3 -4
  126. package/src/DataView/DataView.tsx +25 -3
  127. package/src/DataView/__snapshots__/DataView.test.tsx.snap +16 -16
  128. package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
  129. package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
  130. package/src/DataViewEventsContext/index.ts +2 -0
  131. package/src/DataViewTable/DataViewTable.test.tsx +80 -0
  132. package/src/DataViewTable/DataViewTable.tsx +37 -0
  133. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
  134. package/src/DataViewTable/index.ts +2 -0
  135. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
  136. package/src/DataViewTableBasic/DataViewTableBasic.tsx +82 -0
  137. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
  138. package/src/DataViewTableBasic/index.ts +2 -0
  139. package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
  140. package/src/DataViewTableHead/DataViewTableHead.tsx +53 -0
  141. package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
  142. package/src/DataViewTableHead/index.ts +2 -0
  143. package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
  144. package/src/DataViewTableTree/DataViewTableTree.tsx +164 -0
  145. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
  146. package/src/DataViewTableTree/index.ts +2 -0
  147. package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
  148. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +208 -166
  149. package/src/Hooks/pagination.test.tsx +0 -80
  150. package/src/Hooks/pagination.ts +22 -16
  151. package/src/Hooks/selection.test.tsx +5 -5
  152. package/src/Hooks/selection.ts +6 -7
  153. package/src/InternalContext/InternalContext.test.tsx +89 -0
  154. package/src/InternalContext/InternalContext.tsx +51 -0
  155. package/src/InternalContext/index.ts +2 -0
  156. package/src/index.ts +18 -0
@@ -0,0 +1,108 @@
1
+ import React, { useEffect, useState, useRef, useMemo } from 'react';
2
+ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentBody, DrawerHead, DrawerPanelContent, Title, Content } from '@patternfly/react-core';
3
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
4
+ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
5
+ import { DataViewEventsProvider, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
6
+
7
+ interface Repository {
8
+ name: string;
9
+ branches: string | null;
10
+ prs: string | null;
11
+ workspaces: string;
12
+ lastCommit: string;
13
+ }
14
+
15
+ const repositories: Repository[] = [
16
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
17
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
18
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
19
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
20
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
21
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
22
+ ];
23
+
24
+ const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
25
+
26
+ const ouiaId = 'ContextExample';
27
+
28
+ interface RepositoryDetailProps {
29
+ selectedRepo?: Repository;
30
+ setSelectedRepo: React.Dispatch<React.SetStateAction<Repository | undefined>>;
31
+ }
32
+
33
+ const RepositoryDetail: React.FunctionComponent<RepositoryDetailProps> = ({ selectedRepo, setSelectedRepo }) => {
34
+ const context = useDataViewEventsContext();
35
+
36
+ useEffect(() => {
37
+ const unsubscribe = context.subscribe(EventTypes.rowClick, (repo: Repository) => {
38
+ setSelectedRepo(repo);
39
+ });
40
+
41
+ return () => unsubscribe();
42
+ // eslint-disable-next-line react-hooks/exhaustive-deps
43
+ }, []);
44
+
45
+ return (
46
+ <DrawerPanelContent>
47
+ <DrawerHead>
48
+ <Title className="pf-v5-u-mb-md" headingLevel="h2" ouiaId="detail-drawer-title">
49
+ Detail of {selectedRepo?.name}
50
+ </Title>
51
+ <Content component="p">Branches: {selectedRepo?.branches}</Content>
52
+ <Content component="p">Pull requests: {selectedRepo?.prs}</Content>
53
+ <Content component="p">Workspaces: {selectedRepo?.workspaces}</Content>
54
+ <Content component="p">Last commit: {selectedRepo?.lastCommit}</Content>
55
+ <DrawerActions>
56
+ <DrawerCloseButton onClick={() => setSelectedRepo(undefined)} data-ouia-component-id="detail-drawer-close-btn"/>
57
+ </DrawerActions>
58
+ </DrawerHead>
59
+ </DrawerPanelContent>
60
+ );
61
+ };
62
+
63
+ interface RepositoriesTableProps {
64
+ selectedRepo?: Repository;
65
+ }
66
+
67
+ const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
68
+ const { trigger } = useDataViewEventsContext();
69
+ const rows = useMemo(() => {
70
+ const handleRowClick = (repo: Repository | undefined) => {
71
+ trigger(EventTypes.rowClick, repo);
72
+ };
73
+
74
+ return repositories.map(repo => ({
75
+ row: Object.values(repo),
76
+ props: {
77
+ isClickable: true,
78
+ onRowClick: () => handleRowClick(selectedRepo?.name === repo.name ? undefined : repo),
79
+ isRowSelected: selectedRepo?.name === repo.name
80
+ }
81
+ }));
82
+ }, [ selectedRepo?.name, trigger ]);
83
+
84
+ return (
85
+ <DataView>
86
+ <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
87
+ </DataView>
88
+ );
89
+ };
90
+
91
+ export const BasicExample: React.FunctionComponent = () => {
92
+ const [ selectedRepo, setSelectedRepo ] = useState<Repository>();
93
+ const drawerRef = useRef<HTMLDivElement>(null);
94
+
95
+ return (
96
+ <DataViewEventsProvider>
97
+ <Drawer isExpanded={Boolean(selectedRepo)} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id="detail-drawer" >
98
+ <DrawerContent
99
+ panelContent={<RepositoryDetail selectedRepo={selectedRepo} setSelectedRepo={setSelectedRepo} />}
100
+ >
101
+ <DrawerContentBody>
102
+ <RepositoriesTable selectedRepo={selectedRepo} />
103
+ </DrawerContentBody>
104
+ </DrawerContent>
105
+ </Drawer>
106
+ </DataViewEventsProvider>
107
+ );
108
+ };
@@ -14,11 +14,13 @@ sortValue: 3
14
14
  sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md
15
15
  ---
16
16
  import { useMemo } from 'react';
17
+ import { BrowserRouter, useSearchParams } from 'react-router-dom';
17
18
  import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
18
19
  import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
19
20
  import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
20
21
  import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
21
- import { BrowserRouter, useSearchParams } from 'react-router-dom';
22
+ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
23
+
22
24
 
23
25
  This is a list of functionality you can use to manage data displayed in the **data view**.
24
26
 
@@ -26,7 +28,7 @@ This is a list of functionality you can use to manage data displayed in the **da
26
28
  Allows to display data records on multiple pages and display the pagination state.
27
29
 
28
30
  ### Toolbar usage
29
- Data view toolbar can display a pagination using the `pagination` property accepting a React node. You can also pass a custom `ouiaId` for testing purposes. Additionally, it offers an option to persist pagination values in the URL, which makes it easier to share or bookmark specific pages of your data.
31
+ Data view toolbar can display a pagination using the `pagination` property accepting a React node. You can also pass a custom `ouiaId` for testing purposes.
30
32
 
31
33
  ### Pagination state
32
34
 
@@ -34,12 +36,14 @@ The `useDataViewPagination` hook manages the pagination state of the data view.
34
36
 
35
37
  **Initial values:**
36
38
  - `perPage` initial value
37
- - (optional) `page` initial value
38
- - (optional) `searchParams` object
39
- - (optional) `seSearchParams` function
39
+ - optional `page` initial value
40
+ - optional `searchParams` object
41
+ - optional `setSearchParams` function
40
42
 
41
43
  While the hook works seamlessly with React Router library, you do not need to use it to take advantage of URL persistence. The `searchParams` and `setSearchParams` props can be managed using native browser APIs (`URLSearchParams` and `window.history.pushState`) or any other routing library of your choice. If you don't pass these two props, the pagination state will be stored internally without the URL usage.
42
44
 
45
+ You can also pass custom `pageParam` or `perPageParam` names, renaming the pagination parameters in the URL.
46
+
43
47
  The retrieved values are named to match the PatternFly [pagination](/components/pagination) component props, so you can easily spread them to the component.
44
48
 
45
49
  **Return values:**
@@ -49,8 +53,6 @@ The retrieved values are named to match the PatternFly [pagination](/components/
49
53
  - `onPerPageSelect` to modify per page value
50
54
 
51
55
  ### Pagination example
52
- This example uses the URL for persisting the pagination state.
53
-
54
56
  ```js file="./PaginationExample.tsx"
55
57
 
56
58
  ```
@@ -59,15 +61,15 @@ This example uses the URL for persisting the pagination state.
59
61
  Allows to select data records inside the data view and show the selection state.
60
62
 
61
63
  ### Toolbar usage
62
- Data view toolbar can display a bulk selection component using the `bulkSelect` property accepting a React node. You can make use of a predefined [bulk select](/extensions/component-groups/bulk-select) from the [component groups](/extensions/component-groups/about-component-groups) extension.
64
+ Data view toolbar can display a bulk selection component using the `bulkSelect` property accepting a React node. You can make use of a predefined [bulk select](/extensions/component-groups/bulk-select) component from the [component groups](/extensions/component-groups/about-component-groups) extension.
63
65
 
64
66
  ### Selection state
65
67
 
66
68
  The `useDataViewSelection` hook manages the selection state of the data view.
67
69
 
68
70
  **Initial values:**
69
- - (optional) `initialSelected` array of record's identifiers selected by default
70
- - (optional) `matchOption` function to check if given record is selected
71
+ - optional `initialSelected` array of record's identifiers selected by default
72
+ - `matchOption` function to check if given record is selected
71
73
 
72
74
  *When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.*
73
75
 
@@ -81,4 +83,3 @@ The `useDataViewSelection` hook manages the selection state of the data view.
81
83
  ```js file="./SelectionExample.tsx"
82
84
 
83
85
  ```
84
-
@@ -1,15 +1,15 @@
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
- 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';
7
3
  import { BrowserRouter, useSearchParams } from 'react-router-dom';
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';
7
+ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
8
8
 
9
9
  const perPageOptions = [
10
10
  { title: '5', value: 5 },
11
11
  { title: '10', value: 10 }
12
- ]
12
+ ];
13
13
 
14
14
  interface Repository {
15
15
  name: string;
@@ -17,24 +17,20 @@ interface Repository {
17
17
  prs: string | null;
18
18
  workspaces: string;
19
19
  lastCommit: string;
20
- }
20
+ };
21
21
 
22
22
  const repositories: Repository[] = [
23
- { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
24
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
25
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
26
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
27
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
28
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
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 cols = {
32
- name: 'Repositories',
33
- branches: 'Branches',
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
 
@@ -43,31 +39,18 @@ const MyTable: React.FunctionComponent = () => {
43
39
  const pagination = useDataViewPagination({ perPage: 5, searchParams, setSearchParams });
44
40
  const { page, perPage } = pagination;
45
41
 
46
- const data = useMemo(() => repositories.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
42
+ const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
47
43
  return (
48
44
  <DataView>
49
45
  <DataViewToolbar ouiaId='DataViewHeader' pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
50
- <Table aria-label="Repositories table" ouiaId={ouiaId}>
51
- <Thead data-ouia-component-id={`${ouiaId}-thead`}>
52
- <Tr ouiaId={`${ouiaId}-tr-head`}>
53
- {Object.values(cols).map((column, index) => <Th key={index} data-ouia-component-id={`${ouiaId}-th-${index}`}>{column}</Th>)}
54
- </Tr>
55
- </Thead>
56
- <Tbody>
57
- {data.map((repo, rowIndex) => (
58
- <Tr key={repo.name} ouiaId={`${ouiaId}-tr-${rowIndex}`}>
59
- {Object.keys(cols).map((column, colIndex) => <Td key={colIndex} data-ouia-component-id={`${ouiaId}-td-${rowIndex}-${colIndex}`}>{repo[column]}</Td>)}
60
- </Tr>
61
- ))}
62
- </Tbody>
63
- </Table>
46
+ <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
64
47
  <DataViewToolbar ouiaId='DataViewFooter' pagination={<Pagination isCompact perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
65
48
  </DataView>
66
- )
67
- }
49
+ );
50
+ };
68
51
 
69
52
  export const BasicExample: React.FunctionComponent = () => (
70
53
  <BrowserRouter>
71
54
  <MyTable/>
72
55
  </BrowserRouter>
73
- )
56
+ );
@@ -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: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
18
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
19
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
20
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
21
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
22
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
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 cols = {
26
- name: 'Repositories',
27
- branches: 'Branches',
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, isSelected } = selection;
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, repositories);
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
- <Table aria-label="Repositories table" ouiaId={ouiaId}>
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
  }
@@ -4,15 +4,14 @@ import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
4
4
  const layoutItemStyling = {
5
5
  width: '100%',
6
6
  height: '5rem',
7
- padding: 'var(--pf-v5-global--spacer--md)',
8
- borderStyle: 'dashed',
9
- borderWidth: '2px',
7
+ padding: 'var(--pf-t--global--spacer--md)',
8
+ border: 'var(--pf-t--global--border--width--box--default) dashed var(--pf-t--global--border--color--default)'
10
9
  };
11
10
 
12
11
  export const BasicExample: React.FunctionComponent = () => (
13
12
  <DataView>
14
13
  <div style={layoutItemStyling}>Header</div>
15
- <div style={{ ...layoutItemStyling, borderTopWidth: 0, borderBottomWidth: 0 }}>Data representation</div>
14
+ <div style={layoutItemStyling}>Data representation</div>
16
15
  <div style={layoutItemStyling}>Footer</div>
17
16
  </DataView>
18
17
  )
@@ -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
 
@@ -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: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
24
- { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
25
- { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
26
- { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
27
- { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
28
- { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
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 cols = {
32
- name: 'Repositories',
33
- branches: 'Branches',
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 pageData = useMemo(() => repositories.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
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, repositories);
52
- value === BulkSelectValue.nonePage && onSelect(false, pageData);
53
- value === BulkSelectValue.page && onSelect(true, pageData);
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={pageData.length}
59
+ pageCount={pageRows.length}
64
60
  totalCount={repositories.length}
65
61
  selectedCount={selected.length}
66
- pageSelected={pageData.every(item => isSelected(item))}
67
- pagePartiallySelected={pageData.some(item => isSelected(item)) && !pageData.every(item => isSelected(item))}
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
- <Table aria-label="Repositories table" ouiaId={ouiaId}>
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 variant="light" 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
package/release.config.js CHANGED
@@ -1,9 +1,5 @@
1
1
  module.exports = {
2
- branches: [
3
- 'do-not-delete',
4
- { name: 'main', channel: 'prerelease', prerelease: 'prerelease' },
5
- { name: 'v5', channel: 'prerelease-v5', range: '5.x' },
6
- ],
2
+ branches: [ 'do-not-delete', { name: 'main', channel: 'prerelease', prerelease: 'prerelease' } ],
7
3
  analyzeCommits: {
8
4
  preset: 'angular'
9
5
  },
@@ -5,9 +5,8 @@ import DataView from './DataView';
5
5
  const layoutItemStyling = {
6
6
  width: '100%',
7
7
  height: '5rem',
8
- padding: 'var(--pf-v5-global--spacer--md)',
9
- borderStyle: 'dashed',
10
- borderWidth: '2px',
8
+ padding: 'var(--pf-t--global--spacer--md)',
9
+ border: 'var(--pf-t--global--border--width--box--default) dashed var(--pf-t--global--border--color--default)'
11
10
  };
12
11
 
13
12
  describe('DataView component', () => {
@@ -15,7 +14,7 @@ describe('DataView component', () => {
15
14
  expect(render(
16
15
  <DataView>
17
16
  <div style={layoutItemStyling}>Header</div>
18
- <div style={{ ...layoutItemStyling, borderTopWidth: 0, borderBottomWidth: 0 }}>Data representation</div>
17
+ <div style={layoutItemStyling}>Data representation</div>
19
18
  <div style={layoutItemStyling}>Footer</div>
20
19
  </DataView>)).toMatchSnapshot();
21
20
  });
@@ -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 const DataView: React.FC<DataViewProps> = ({
24
+ export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
25
+
26
+ const DataViewImplementation: React.FC<DataViewImpementationProps> = ({
11
27
  children, ouiaId = 'DataView', ...props
12
- }: DataViewProps) => (
13
- <Stack data-ouia-component-id={`${ouiaId}-stack}`} {...props}>
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;