@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.
Files changed (239) hide show
  1. package/dist/cjs/DataView/DataView.d.ts +15 -1
  2. package/dist/cjs/DataView/DataView.js +14 -3
  3. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
  4. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +70 -0
  5. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
  6. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +25 -0
  7. package/dist/cjs/DataViewCheckboxFilter/index.d.ts +2 -0
  8. package/dist/cjs/DataViewCheckboxFilter/index.js +23 -0
  9. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  10. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
  11. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  12. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
  13. package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
  14. package/dist/cjs/DataViewEventsContext/index.js +23 -0
  15. package/dist/cjs/DataViewFilters/DataViewFilters.d.ts +25 -0
  16. package/dist/cjs/DataViewFilters/DataViewFilters.js +85 -0
  17. package/dist/cjs/DataViewFilters/DataViewFilters.test.d.ts +1 -0
  18. package/dist/cjs/DataViewFilters/DataViewFilters.test.js +19 -0
  19. package/dist/cjs/DataViewFilters/index.d.ts +2 -0
  20. package/dist/cjs/DataViewFilters/index.js +23 -0
  21. package/dist/cjs/DataViewTable/DataViewTable.d.ts +49 -0
  22. package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
  23. package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
  24. package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
  25. package/dist/cjs/DataViewTable/index.d.ts +2 -0
  26. package/dist/cjs/DataViewTable/index.js +23 -0
  27. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
  28. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
  29. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  30. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
  31. package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
  32. package/dist/cjs/DataViewTableBasic/index.js +23 -0
  33. package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +14 -0
  34. package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
  35. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  36. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
  37. package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
  38. package/dist/cjs/DataViewTableHead/index.js +23 -0
  39. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +25 -0
  40. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +144 -0
  41. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  42. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
  43. package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
  44. package/dist/cjs/DataViewTableTree/index.js +23 -0
  45. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
  46. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +26 -0
  47. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
  48. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +22 -0
  49. package/dist/cjs/DataViewTextFilter/index.d.ts +2 -0
  50. package/dist/cjs/DataViewTextFilter/index.js +23 -0
  51. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +13 -3
  52. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +31 -6
  53. package/dist/cjs/Hooks/filters.d.ts +14 -0
  54. package/dist/cjs/Hooks/filters.js +69 -0
  55. package/dist/cjs/Hooks/filters.test.d.ts +1 -0
  56. package/dist/cjs/Hooks/filters.test.js +75 -0
  57. package/dist/cjs/Hooks/index.d.ts +2 -0
  58. package/dist/cjs/Hooks/index.js +2 -0
  59. package/dist/cjs/Hooks/pagination.d.ts +14 -1
  60. package/dist/cjs/Hooks/pagination.js +36 -4
  61. package/dist/cjs/Hooks/pagination.test.js +1 -1
  62. package/dist/cjs/Hooks/selection.d.ts +3 -3
  63. package/dist/cjs/Hooks/selection.js +4 -4
  64. package/dist/cjs/Hooks/selection.test.js +4 -4
  65. package/dist/cjs/Hooks/sort.d.ts +32 -0
  66. package/dist/cjs/Hooks/sort.js +47 -0
  67. package/dist/cjs/Hooks/sort.test.d.ts +1 -0
  68. package/dist/cjs/Hooks/sort.test.js +68 -0
  69. package/dist/cjs/InternalContext/InternalContext.d.ts +26 -0
  70. package/dist/cjs/InternalContext/InternalContext.js +40 -0
  71. package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
  72. package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
  73. package/dist/cjs/InternalContext/index.d.ts +2 -0
  74. package/dist/cjs/InternalContext/index.js +23 -0
  75. package/dist/cjs/index.d.ts +16 -0
  76. package/dist/cjs/index.js +26 -2
  77. package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
  78. package/dist/dynamic/DataViewEventsContext/package.json +1 -0
  79. package/dist/dynamic/DataViewFilters/package.json +1 -0
  80. package/dist/dynamic/DataViewTable/package.json +1 -0
  81. package/dist/dynamic/DataViewTableBasic/package.json +1 -0
  82. package/dist/dynamic/DataViewTableHead/package.json +1 -0
  83. package/dist/dynamic/DataViewTableTree/package.json +1 -0
  84. package/dist/dynamic/DataViewTextFilter/package.json +1 -0
  85. package/dist/dynamic/InternalContext/package.json +1 -0
  86. package/dist/esm/DataView/DataView.d.ts +15 -1
  87. package/dist/esm/DataView/DataView.js +13 -2
  88. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
  89. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +62 -0
  90. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
  91. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +20 -0
  92. package/dist/esm/DataViewCheckboxFilter/index.d.ts +2 -0
  93. package/dist/esm/DataViewCheckboxFilter/index.js +2 -0
  94. package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  95. package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
  96. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  97. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
  98. package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
  99. package/dist/esm/DataViewEventsContext/index.js +2 -0
  100. package/dist/esm/DataViewFilters/DataViewFilters.d.ts +25 -0
  101. package/dist/esm/DataViewFilters/DataViewFilters.js +58 -0
  102. package/dist/esm/DataViewFilters/DataViewFilters.test.d.ts +1 -0
  103. package/dist/esm/DataViewFilters/DataViewFilters.test.js +14 -0
  104. package/dist/esm/DataViewFilters/index.d.ts +2 -0
  105. package/dist/esm/DataViewFilters/index.js +2 -0
  106. package/dist/esm/DataViewTable/DataViewTable.d.ts +49 -0
  107. package/dist/esm/DataViewTable/DataViewTable.js +8 -0
  108. package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
  109. package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
  110. package/dist/esm/DataViewTable/index.d.ts +2 -0
  111. package/dist/esm/DataViewTable/index.js +2 -0
  112. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
  113. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
  114. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  115. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
  116. package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
  117. package/dist/esm/DataViewTableBasic/index.js +2 -0
  118. package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +14 -0
  119. package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
  120. package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  121. package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
  122. package/dist/esm/DataViewTableHead/index.d.ts +2 -0
  123. package/dist/esm/DataViewTableHead/index.js +2 -0
  124. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +25 -0
  125. package/dist/esm/DataViewTableTree/DataViewTableTree.js +117 -0
  126. package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  127. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
  128. package/dist/esm/DataViewTableTree/index.d.ts +2 -0
  129. package/dist/esm/DataViewTableTree/index.js +2 -0
  130. package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
  131. package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +19 -0
  132. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
  133. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +17 -0
  134. package/dist/esm/DataViewTextFilter/index.d.ts +2 -0
  135. package/dist/esm/DataViewTextFilter/index.js +2 -0
  136. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +13 -3
  137. package/dist/esm/DataViewToolbar/DataViewToolbar.js +9 -4
  138. package/dist/esm/Hooks/filters.d.ts +14 -0
  139. package/dist/esm/Hooks/filters.js +65 -0
  140. package/dist/esm/Hooks/filters.test.d.ts +1 -0
  141. package/dist/esm/Hooks/filters.test.js +73 -0
  142. package/dist/esm/Hooks/index.d.ts +2 -0
  143. package/dist/esm/Hooks/index.js +2 -0
  144. package/dist/esm/Hooks/pagination.d.ts +14 -1
  145. package/dist/esm/Hooks/pagination.js +36 -4
  146. package/dist/esm/Hooks/pagination.test.js +1 -1
  147. package/dist/esm/Hooks/selection.d.ts +3 -3
  148. package/dist/esm/Hooks/selection.js +4 -4
  149. package/dist/esm/Hooks/selection.test.js +4 -4
  150. package/dist/esm/Hooks/sort.d.ts +32 -0
  151. package/dist/esm/Hooks/sort.js +43 -0
  152. package/dist/esm/Hooks/sort.test.d.ts +1 -0
  153. package/dist/esm/Hooks/sort.test.js +66 -0
  154. package/dist/esm/InternalContext/InternalContext.d.ts +26 -0
  155. package/dist/esm/InternalContext/InternalContext.js +12 -0
  156. package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
  157. package/dist/esm/InternalContext/InternalContext.test.js +51 -0
  158. package/dist/esm/InternalContext/index.d.ts +2 -0
  159. package/dist/esm/InternalContext/index.js +2 -0
  160. package/dist/esm/index.d.ts +16 -0
  161. package/dist/esm/index.js +16 -0
  162. package/dist/tsconfig.tsbuildinfo +1 -0
  163. package/package.json +16 -15
  164. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
  165. package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +130 -0
  166. package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
  167. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +57 -0
  168. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +45 -0
  169. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +67 -0
  170. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +27 -0
  171. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +71 -0
  172. package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +87 -0
  173. package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
  174. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/AllSelectedExample.tsx +116 -0
  175. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarActionsExample.tsx +27 -0
  176. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
  177. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +107 -0
  178. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +56 -0
  179. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +57 -0
  180. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +154 -0
  181. package/patternfly-docs/pages/index.js +1 -1
  182. package/release.config.js +1 -1
  183. package/src/DataView/DataView.tsx +28 -5
  184. package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
  185. package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +24 -0
  186. package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +175 -0
  187. package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +197 -0
  188. package/src/DataViewCheckboxFilter/index.ts +2 -0
  189. package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
  190. package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
  191. package/src/DataViewEventsContext/index.ts +2 -0
  192. package/src/DataViewFilters/DataViewFilters.test.tsx +21 -0
  193. package/src/DataViewFilters/DataViewFilters.tsx +144 -0
  194. package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +194 -0
  195. package/src/DataViewFilters/index.tsx +2 -0
  196. package/src/DataViewTable/DataViewTable.test.tsx +80 -0
  197. package/src/DataViewTable/DataViewTable.tsx +57 -0
  198. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
  199. package/src/DataViewTable/index.ts +2 -0
  200. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
  201. package/src/DataViewTableBasic/DataViewTableBasic.tsx +83 -0
  202. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
  203. package/src/DataViewTableBasic/index.ts +2 -0
  204. package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
  205. package/src/DataViewTableHead/DataViewTableHead.tsx +54 -0
  206. package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
  207. package/src/DataViewTableHead/index.ts +2 -0
  208. package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
  209. package/src/DataViewTableTree/DataViewTableTree.tsx +186 -0
  210. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
  211. package/src/DataViewTableTree/index.ts +2 -0
  212. package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +24 -0
  213. package/src/DataViewTextFilter/DataViewTextFilter.tsx +54 -0
  214. package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +203 -0
  215. package/src/DataViewTextFilter/index.ts +2 -0
  216. package/src/DataViewToolbar/DataViewToolbar.tsx +55 -22
  217. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +52 -8
  218. package/src/Hooks/filters.test.tsx +89 -0
  219. package/src/Hooks/filters.ts +97 -0
  220. package/src/Hooks/index.ts +2 -0
  221. package/src/Hooks/pagination.test.tsx +1 -1
  222. package/src/Hooks/pagination.ts +69 -12
  223. package/src/Hooks/selection.test.tsx +5 -5
  224. package/src/Hooks/selection.ts +7 -7
  225. package/src/Hooks/sort.test.tsx +84 -0
  226. package/src/Hooks/sort.ts +87 -0
  227. package/src/InternalContext/InternalContext.test.tsx +89 -0
  228. package/src/InternalContext/InternalContext.tsx +52 -0
  229. package/src/InternalContext/index.ts +2 -0
  230. package/src/index.ts +24 -0
  231. package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
  232. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -31
  233. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
  234. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -77
  235. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +0 -65
  236. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +0 -88
  237. package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -39
  238. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -120
  239. /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
@@ -0,0 +1,275 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import React, { useEffect, useState, useRef, useMemo } from 'react';
3
+ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentBody, DrawerHead, DrawerPanelContent, Title, Content, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateActions, Button, } from '@patternfly/react-core';
4
+ import { ActionsColumn, Tbody, Td, ThProps, Tr } from '@patternfly/react-table';
5
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
6
+ import { Pagination } from '@patternfly/react-core';
7
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
8
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
9
+ import { DataViewTable, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
10
+ import { DataViewEventsProvider, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
11
+ import { useDataViewPagination, useDataViewSelection, useDataViewFilters, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
12
+ import { ResponsiveAction, ResponsiveActions } from '@patternfly/react-component-groups';
13
+ import { DataViewFilterOption, DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
14
+ import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
15
+ import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
16
+ import { CubesIcon } from '@patternfly/react-icons';
17
+
18
+ const perPageOptions = [
19
+ { title: '5', value: 5 },
20
+ { title: '10', value: 10 }
21
+ ];
22
+
23
+ interface Repository {
24
+ name: string;
25
+ branch: string | null;
26
+ prs: string | null;
27
+ workspace: string;
28
+ lastCommit: string;
29
+ };
30
+
31
+ interface RepositoryFilters {
32
+ name: string,
33
+ branch: string,
34
+ workspace: string[]
35
+ };
36
+
37
+ const repositories: Repository[] = [
38
+ { name: 'Repository one', branch: 'Branch one', prs: 'Pull request one', workspace: 'Workspace one', lastCommit: 'Timestamp one' },
39
+ { name: 'Repository two', branch: 'Branch two', prs: 'Pull request two', workspace: 'Workspace two', lastCommit: 'Timestamp two' },
40
+ { name: 'Repository three', branch: 'Branch three', prs: 'Pull request three', workspace: 'Workspace three', lastCommit: 'Timestamp three' },
41
+ { name: 'Repository four', branch: 'Branch four', prs: 'Pull request four', workspace: 'Workspace four', lastCommit: 'Timestamp four' },
42
+ { name: 'Repository five', branch: 'Branch five', prs: 'Pull request five', workspace: 'Workspace five', lastCommit: 'Timestamp five' },
43
+ { name: 'Repository six', branch: 'Branch six', prs: 'Pull request six', workspace: 'Workspace six', lastCommit: 'Timestamp six' }
44
+ ];
45
+
46
+ const filterOptions: DataViewFilterOption[] = [
47
+ { label: 'Workspace one', value: 'workspace-one' },
48
+ { label: 'Workspace two', value: 'workspace-two' },
49
+ { label: 'Workspace three', value: 'workspace-three' }
50
+ ];
51
+
52
+ const COLUMNS = [
53
+ { label: 'Repository', key: 'name', index: 0 },
54
+ { label: 'Branch', key: 'branches', index: 1 },
55
+ { label: 'Pull request', key: 'prs', index: 2 },
56
+ { label: 'Workspace', key: 'workspaces', index: 3 },
57
+ { label: 'Last commit', key: 'lastCommit', index: 4 }
58
+ ];
59
+
60
+ const ouiaId = 'LayoutExample';
61
+
62
+ const sortData = (data: Repository[], sortBy: string | undefined, direction: 'asc' | 'desc' | undefined) =>
63
+ sortBy && direction
64
+ ? [ ...data ].sort((a, b) =>
65
+ direction === 'asc'
66
+ ? a[sortBy] < b[sortBy] ? -1 : a[sortBy] > b[sortBy] ? 1 : 0
67
+ : a[sortBy] > b[sortBy] ? -1 : a[sortBy] < b[sortBy] ? 1 : 0
68
+ )
69
+ : data;
70
+
71
+ const empty = (
72
+ <Tbody>
73
+ <Tr key="loading" ouiaId={`${ouiaId}-tr-loading`}>
74
+ <Td colSpan={COLUMNS.length}>
75
+ <EmptyState headingLevel="h4" icon={CubesIcon} titleText="No data found">
76
+ <EmptyStateBody>There are no matching data to be displayed.</EmptyStateBody>
77
+ <EmptyStateFooter>
78
+ <EmptyStateActions>
79
+ <Button variant="primary">Primary action</Button>
80
+ </EmptyStateActions>
81
+ <EmptyStateActions>
82
+ <Button variant="link">Multiple</Button>
83
+ <Button variant="link">Action Buttons</Button>
84
+ </EmptyStateActions>
85
+ </EmptyStateFooter>
86
+ </EmptyState>
87
+ </Td>
88
+ </Tr>
89
+ </Tbody>
90
+ );
91
+
92
+ interface RepositoryDetailProps {
93
+ selectedRepo?: Repository;
94
+ setSelectedRepo: React.Dispatch<React.SetStateAction<Repository | undefined>>;
95
+ }
96
+
97
+ const RepositoryDetail: React.FunctionComponent<RepositoryDetailProps> = ({ selectedRepo, setSelectedRepo }) => {
98
+ const context = useDataViewEventsContext();
99
+
100
+ useEffect(() => {
101
+ const unsubscribe = context.subscribe(EventTypes.rowClick, (repo: Repository) => {
102
+ setSelectedRepo(repo);
103
+ });
104
+
105
+ return () => unsubscribe();
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ }, []);
108
+
109
+ return (
110
+ <DrawerPanelContent>
111
+ <DrawerHead>
112
+ <Title className="pf-v5-u-mb-md" headingLevel="h2" ouiaId="detail-drawer-title">
113
+ Detail of {selectedRepo?.name}
114
+ </Title>
115
+ <Content component="p">Branch: {selectedRepo?.branch}</Content>
116
+ <Content component="p">Pull requests: {selectedRepo?.prs}</Content>
117
+ <Content component="p">Workspace: {selectedRepo?.workspace}</Content>
118
+ <Content component="p">Last commit: {selectedRepo?.lastCommit}</Content>
119
+ <DrawerActions>
120
+ <DrawerCloseButton onClick={() => setSelectedRepo(undefined)} data-ouia-component-id="detail-drawer-close-btn"/>
121
+ </DrawerActions>
122
+ </DrawerHead>
123
+ </DrawerPanelContent>
124
+ );
125
+ };
126
+
127
+ interface RepositoriesTableProps {
128
+ selectedRepo?: Repository;
129
+ }
130
+
131
+ const rowActions = [
132
+ {
133
+ title: 'Some action',
134
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
135
+ },
136
+ {
137
+ title: <div>Another action</div>,
138
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
139
+ },
140
+ {
141
+ isSeparator: true
142
+ },
143
+ {
144
+ title: 'Third action',
145
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
146
+ }
147
+ ];
148
+
149
+ const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
150
+ const { filters, onSetFilters, clearAllFilters } = useDataViewFilters<RepositoryFilters>({ initialFilters: { name: '', branch: '', workspace: [] } });
151
+
152
+ const pagination = useDataViewPagination({ perPage: 5 });
153
+ const { page, perPage } = pagination;
154
+
155
+ const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
156
+ const { selected, onSelect, isSelected } = selection;
157
+
158
+ const { trigger } = useDataViewEventsContext();
159
+
160
+ const { sortBy, direction, onSort } = useDataViewSort();
161
+ const sortByIndex = useMemo(() => COLUMNS.findIndex(item => item.key === sortBy), [ sortBy ]);
162
+ const getSortParams = (columnIndex: number): ThProps['sort'] => ({
163
+ sortBy: {
164
+ index: sortByIndex,
165
+ direction,
166
+ defaultDirection: 'asc'
167
+ },
168
+ onSort: (_event, index, direction) => onSort(_event, COLUMNS[index].key, direction),
169
+ columnIndex
170
+ });
171
+
172
+ const columns: DataViewTh[] = COLUMNS.map((column, index) => ({
173
+ cell: column.label,
174
+ props: { sort: getSortParams(index) }
175
+ }));
176
+
177
+ const finalData = useMemo(() => sortData(repositories, sortBy, direction).filter(item =>
178
+ (!filters.name || item.name?.toLocaleLowerCase().includes(filters.name?.toLocaleLowerCase())) &&
179
+ (!filters.branch || item.branch?.toLocaleLowerCase().includes(filters.branch?.toLocaleLowerCase())) &&
180
+ (!filters.workspace || filters.workspace.length === 0 || filters.workspace.includes(String(filterOptions.find(option => option.label === item.workspace)?.value)))
181
+ ), [ filters, sortBy, direction ]);
182
+
183
+ const pageRows = useMemo(() => {
184
+ const handleRowClick = (event, repo: Repository | undefined) => {
185
+ // prevents drawer toggle on actions or checkbox click
186
+ (event.target.matches('td') || event.target.matches('tr')) && trigger(EventTypes.rowClick, repo);
187
+ };
188
+
189
+ return finalData.map(repo => ({
190
+ row: [ ...Object.values(repo), { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } } ],
191
+ props: {
192
+ isClickable: true,
193
+ onRowClick: (event) => handleRowClick(event, selectedRepo?.name === repo.name ? undefined : repo),
194
+ isRowSelected: selectedRepo?.name === repo.name
195
+ }
196
+ })).slice((page - 1) * perPage, ((page - 1) * perPage) + perPage);
197
+ }, [ selectedRepo?.name, trigger, page, perPage, finalData ]);
198
+
199
+ const handleBulkSelect = (value: BulkSelectValue) => {
200
+ value === BulkSelectValue.none && onSelect(false);
201
+ value === BulkSelectValue.nonePage && onSelect(false, pageRows);
202
+ value === BulkSelectValue.page && onSelect(true, pageRows);
203
+ };
204
+
205
+ return (
206
+ <DataView selection={selection} activeState={finalData.length > 0 ? undefined : 'empty'}>
207
+ <DataViewToolbar
208
+ ouiaId='LayoutExampleHeader'
209
+ clearAllFilters={clearAllFilters}
210
+ bulkSelect={
211
+ <BulkSelect
212
+ pageCount={pageRows.length}
213
+ totalCount={repositories.length}
214
+ selectedCount={selected.length}
215
+ pageSelected={pageRows.every(item => isSelected(item))}
216
+ pagePartiallySelected={pageRows.some(item => isSelected(item)) && !pageRows.every(item => isSelected(item))}
217
+ onSelect={handleBulkSelect}
218
+ />
219
+ }
220
+ filters={
221
+ <DataViewFilters onChange={(_e, values) => onSetFilters(values)} values={filters}>
222
+ <DataViewTextFilter filterId="name" title='Name' placeholder='Filter by name' />
223
+ <DataViewTextFilter filterId="branch" title='Branch' placeholder='Filter by branch' />
224
+ <DataViewCheckboxFilter filterId="workspace" title='Workspace' placeholder='Filter by workspace' options={filterOptions} />
225
+ </DataViewFilters>
226
+ }
227
+ actions={
228
+ <ResponsiveActions ouiaId="example-actions">
229
+ <ResponsiveAction>Add repository</ResponsiveAction>
230
+ <ResponsiveAction>Delete repository</ResponsiveAction>
231
+ </ResponsiveActions>
232
+ }
233
+ pagination={
234
+ <Pagination
235
+ isCompact
236
+ perPageOptions={perPageOptions}
237
+ itemCount={repositories.length}
238
+ {...pagination}
239
+ />
240
+ }
241
+ />
242
+ <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} bodyStates={{ empty }} />
243
+ <DataViewToolbar
244
+ ouiaId='LayoutExampleFooter'
245
+ pagination={
246
+ <Pagination
247
+ isCompact
248
+ perPageOptions={perPageOptions}
249
+ itemCount={repositories.length}
250
+ {...pagination}
251
+ />
252
+ }
253
+ />
254
+ </DataView>
255
+ );
256
+ };
257
+
258
+ export const BasicExample: React.FunctionComponent = () => {
259
+ const [ selectedRepo, setSelectedRepo ] = useState<Repository>();
260
+ const drawerRef = useRef<HTMLDivElement>(null);
261
+
262
+ return (
263
+ <DataViewEventsProvider>
264
+ <Drawer isExpanded={Boolean(selectedRepo)} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id="detail-drawer" >
265
+ <DrawerContent
266
+ panelContent={<RepositoryDetail selectedRepo={selectedRepo} setSelectedRepo={setSelectedRepo} />}
267
+ >
268
+ <DrawerContentBody>
269
+ <RepositoriesTable selectedRepo={selectedRepo} />
270
+ </DrawerContentBody>
271
+ </DrawerContent>
272
+ </Drawer>
273
+ </DataViewEventsProvider>
274
+ );
275
+ };
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
3
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4
+ import { CubesIcon } from '@patternfly/react-icons';
5
+ import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter, } from '@patternfly/react-core';
6
+ import { Tbody, Td, Tr } from '@patternfly/react-table';
7
+
8
+ interface Repository {
9
+ id: number;
10
+ name: string;
11
+ branches: string | null;
12
+ prs: string | null;
13
+ workspaces: string;
14
+ lastCommit: string;
15
+ }
16
+
17
+ const repositories: Repository[] = [];
18
+
19
+ // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
20
+ const rows: DataViewTr[] = repositories.map((repository) => Object.values(repository));
21
+
22
+ const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
23
+
24
+ const ouiaId = 'TableExample';
25
+
26
+ const empty = (
27
+ <Tbody>
28
+ <Tr key="loading" ouiaId={`${ouiaId}-tr-loading`}>
29
+ <Td colSpan={columns.length}>
30
+ <EmptyState headingLevel="h4" icon={CubesIcon} titleText="No data found">
31
+ <EmptyStateBody>There are no matching data to be displayed.</EmptyStateBody>
32
+ <EmptyStateFooter>
33
+ <EmptyStateActions>
34
+ <Button variant="primary">Primary action</Button>
35
+ </EmptyStateActions>
36
+ <EmptyStateActions>
37
+ <Button variant="link">Multiple</Button>
38
+ <Button variant="link">Action Buttons</Button>
39
+ </EmptyStateActions>
40
+ </EmptyStateFooter>
41
+ </EmptyState>
42
+ </Td>
43
+ </Tr>
44
+ </Tbody>
45
+ );
46
+
47
+ export const BasicExample: React.FunctionComponent = () => (
48
+ <DataView activeState={DataViewState.empty}>
49
+ <DataViewTable
50
+ aria-label='Repositories table'
51
+ ouiaId={ouiaId}
52
+ columns={columns}
53
+ rows={rows}
54
+ bodyStates={{ empty }}
55
+ />
56
+ </DataView>
57
+ );
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
3
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4
+ import { ErrorState } from '@patternfly/react-component-groups';
5
+ import { Tbody, Td, Tr } from '@patternfly/react-table';
6
+
7
+ interface Repository {
8
+ id: number;
9
+ name: string;
10
+ branches: string | null;
11
+ prs: string | null;
12
+ workspaces: string;
13
+ lastCommit: string;
14
+ }
15
+
16
+ const repositories: Repository[] = [];
17
+
18
+ // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
19
+ const rows: DataViewTr[] = repositories.map((repository) => Object.values(repository));
20
+
21
+ const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
22
+
23
+ const ouiaId = 'TableErrorExample';
24
+
25
+ const error = (
26
+ <Tbody>
27
+ <Tr key="loading" ouiaId={`${ouiaId}-tr-loading`}>
28
+ <Td colSpan={columns.length}>
29
+ <ErrorState titleText='Unable to load data' bodyText='There was an error retrieving data. Check your connection and reload the page.' />
30
+ </Td>
31
+ </Tr>
32
+ </Tbody>
33
+ );
34
+
35
+ export const BasicExample: React.FunctionComponent = () => (
36
+ <DataView activeState={DataViewState.error}>
37
+ <DataViewTable
38
+ aria-label='Repositories table'
39
+ ouiaId={ouiaId}
40
+ columns={columns}
41
+ rows={rows}
42
+ bodyStates={{ error }}
43
+ />
44
+ </DataView>
45
+ );
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3
+ import { ExclamationCircleIcon } from '@patternfly/react-icons';
4
+ import { Button } from '@patternfly/react-core';
5
+ import { ActionsColumn } from '@patternfly/react-table';
6
+
7
+ interface Repository {
8
+ id: number;
9
+ name: string;
10
+ branches: string | null;
11
+ prs: string | null;
12
+ workspaces: string;
13
+ lastCommit: string;
14
+ }
15
+
16
+ const repositories: Repository[] = [
17
+ { id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
18
+ { id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
19
+ { id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
20
+ { id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
21
+ { id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
22
+ { id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
23
+ ];
24
+
25
+ const rowActions = [
26
+ {
27
+ title: 'Some action',
28
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
29
+ },
30
+ {
31
+ title: <div>Another action</div>,
32
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
33
+ },
34
+ {
35
+ isSeparator: true
36
+ },
37
+ {
38
+ title: 'Third action',
39
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
40
+ }
41
+ ];
42
+
43
+ // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
44
+ const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
45
+ { id, cell: workspaces, props: { favorites: { isFavorited: true } } },
46
+ { cell: <Button href='#' variant='link' isInline>{name}</Button> },
47
+ branches,
48
+ prs,
49
+ workspaces,
50
+ lastCommit,
51
+ { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } },
52
+ ]);
53
+
54
+ const columns: DataViewTh[] = [
55
+ null,
56
+ 'Repositories',
57
+ { cell: <>Branches<ExclamationCircleIcon className='pf-v6-u-ml-sm' color="var(--pf-t--global--color--status--danger--default)"/></> },
58
+ 'Pull requests',
59
+ { cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
60
+ { cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } },
61
+ ];
62
+
63
+ const ouiaId = 'TableExample';
64
+
65
+ export const BasicExample: React.FunctionComponent = () => (
66
+ <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
67
+ );
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
3
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4
+ import { SkeletonTableBody, SkeletonTableHead } from '@patternfly/react-component-groups';
5
+
6
+ // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
7
+ const rows: DataViewTr[] = [];
8
+
9
+ const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
10
+
11
+ const ouiaId = 'TableExample';
12
+
13
+ const headLoading = <SkeletonTableHead columns={columns} />
14
+ const bodyLoading = <SkeletonTableBody rowsCount={5} columnsCount={columns.length} />;
15
+
16
+ export const BasicExample: React.FunctionComponent = () => (
17
+ <DataView activeState={DataViewState.loading}>
18
+ <DataViewTable
19
+ aria-label='Repositories table'
20
+ ouiaId={ouiaId}
21
+ columns={columns}
22
+ rows={rows}
23
+ headStates={{ loading: headLoading }}
24
+ bodyStates={{ loading: bodyLoading }}
25
+ />
26
+ </DataView>
27
+ );
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
3
+ import { DataViewTable, DataViewTh, DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
5
+ import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
6
+
7
+ interface Repository {
8
+ name: string;
9
+ branches: string | null;
10
+ prs: string | null;
11
+ workspaces: string;
12
+ lastCommit: string;
13
+ children?: Repository[];
14
+ }
15
+
16
+ const repositories: Repository[] = [
17
+ {
18
+ name: 'Repository one',
19
+ branches: 'Branch one',
20
+ prs: 'Pull request one',
21
+ workspaces: 'Workspace one',
22
+ lastCommit: 'Timestamp one',
23
+ children: [
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
+ ]
27
+ },
28
+ {
29
+ name: 'Repository four',
30
+ branches: 'Branch four',
31
+ prs: 'Pull request four',
32
+ workspaces: 'Workspace four',
33
+ lastCommit: 'Timestamp four',
34
+ children: [ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' } ]
35
+ },
36
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
37
+ ];
38
+
39
+ const buildRows = (repositories: Repository[]): DataViewTrTree[] => repositories.map((repo) => ({
40
+ row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
41
+ id: repo.name, // unique ID for each row
42
+ ...(repo.children
43
+ ? {
44
+ children: buildRows(repo.children) // build rows for children
45
+ }
46
+ : {})
47
+ }));
48
+
49
+ const rows: DataViewTrTree[] = buildRows(repositories);
50
+
51
+ const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
52
+
53
+ const ouiaId = 'TreeTableExample';
54
+
55
+ export const BasicExample: React.FunctionComponent = () => {
56
+ const selection = useDataViewSelection({ matchOption: (a, b) => a.id === b.id });
57
+
58
+ return (
59
+ <DataView selection={selection}>
60
+ <DataViewTable
61
+ isTreeTable
62
+ ouiaId={ouiaId}
63
+ columns={columns}
64
+ rows={rows}
65
+ leafIcon={<LeafIcon/>}
66
+ expandedIcon={<FolderOpenIcon aria-hidden />}
67
+ collapsedIcon={<FolderIcon aria-hidden />}
68
+ />
69
+ </DataView>
70
+ );
71
+ }
@@ -0,0 +1,87 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import React, { useMemo } from 'react';
3
+ import { useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
4
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
5
+ import { ThProps } from '@patternfly/react-table';
6
+ import { BrowserRouter, useSearchParams } from 'react-router-dom';
7
+
8
+ interface Repository {
9
+ name: string;
10
+ branches: string;
11
+ prs: string;
12
+ workspaces: string;
13
+ lastCommit: string;
14
+ };
15
+
16
+ const COLUMNS = [
17
+ { label: 'Repository', key: 'name', index: 0 },
18
+ { label: 'Branch', key: 'branches', index: 1 },
19
+ { label: 'Pull request', key: 'prs', index: 2 },
20
+ { label: 'Workspace', key: 'workspaces', index: 3 },
21
+ { label: 'Last commit', key: 'lastCommit', index: 4 }
22
+ ];
23
+
24
+ const repositories: Repository[] = [
25
+ { name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
26
+ { name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
27
+ { name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
28
+ { name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
29
+ { name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
30
+ { name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
31
+ ];
32
+
33
+ const sortData = (data: Repository[], sortBy: string | undefined, direction: 'asc' | 'desc' | undefined) =>
34
+ sortBy && direction
35
+ ? [ ...data ].sort((a, b) =>
36
+ direction === 'asc'
37
+ ? a[sortBy] < b[sortBy] ? -1 : a[sortBy] > b[sortBy] ? 1 : 0
38
+ : a[sortBy] > b[sortBy] ? -1 : a[sortBy] < b[sortBy] ? 1 : 0
39
+ )
40
+ : data;
41
+
42
+ const ouiaId = 'TableExample';
43
+
44
+ export const MyTable: React.FunctionComponent = () => {
45
+ const [ searchParams, setSearchParams ] = useSearchParams();
46
+ const { sortBy, direction, onSort } = useDataViewSort({ searchParams, setSearchParams });
47
+ const sortByIndex = useMemo(() => COLUMNS.findIndex(item => item.key === sortBy), [ sortBy ]);
48
+
49
+ const getSortParams = (columnIndex: number): ThProps['sort'] => ({
50
+ sortBy: {
51
+ index: sortByIndex,
52
+ direction,
53
+ defaultDirection: 'asc'
54
+ },
55
+ onSort: (_event, index, direction) => onSort(_event, COLUMNS[index].key, direction),
56
+ columnIndex
57
+ });
58
+
59
+ const columns: DataViewTh[] = COLUMNS.map((column, index) => ({
60
+ cell: column.label,
61
+ props: { sort: getSortParams(index) }
62
+ }));
63
+
64
+ const rows: DataViewTr[] = useMemo(() => sortData(repositories, sortBy, direction).map(({ name, branches, prs, workspaces, lastCommit }) => [
65
+ name,
66
+ branches,
67
+ prs,
68
+ workspaces,
69
+ lastCommit,
70
+ ]), [ sortBy, direction ]);
71
+
72
+ return (
73
+ <DataViewTable
74
+ aria-label="Repositories table"
75
+ ouiaId={ouiaId}
76
+ columns={columns}
77
+ rows={rows}
78
+ />
79
+ );
80
+ };
81
+
82
+ export const BasicExample: React.FunctionComponent = () => (
83
+ <BrowserRouter>
84
+ <MyTable/>
85
+ </BrowserRouter>
86
+ )
87
+