@patternfly/react-data-view 1.0.0-prerelease.3 → 1.0.0-prerelease.5

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 (60) hide show
  1. package/dist/cjs/DataView/DataView.test.d.ts +1 -1
  2. package/dist/cjs/DataView/DataView.test.js +12 -6
  3. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  4. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +3 -2
  5. package/dist/cjs/DataViewToolbar/DataViewToolbar.test.js +14 -0
  6. package/dist/cjs/Hooks/index.d.ts +2 -1
  7. package/dist/cjs/Hooks/index.js +2 -1
  8. package/dist/cjs/Hooks/pagination.d.ts +16 -0
  9. package/dist/cjs/Hooks/pagination.js +16 -0
  10. package/dist/cjs/Hooks/pagination.test.d.ts +1 -0
  11. package/dist/cjs/Hooks/pagination.test.js +49 -0
  12. package/dist/cjs/Hooks/selection.d.ts +11 -0
  13. package/dist/cjs/Hooks/selection.js +26 -0
  14. package/dist/cjs/Hooks/selection.test.d.ts +1 -0
  15. package/dist/cjs/Hooks/selection.test.js +55 -0
  16. package/dist/esm/DataView/DataView.test.d.ts +1 -1
  17. package/dist/esm/DataView/DataView.test.js +13 -7
  18. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  19. package/dist/esm/DataViewToolbar/DataViewToolbar.js +3 -2
  20. package/dist/esm/DataViewToolbar/DataViewToolbar.test.d.ts +1 -0
  21. package/dist/esm/DataViewToolbar/DataViewToolbar.test.js +9 -0
  22. package/dist/esm/Hooks/index.d.ts +2 -1
  23. package/dist/esm/Hooks/index.js +2 -1
  24. package/dist/esm/Hooks/pagination.d.ts +16 -0
  25. package/dist/esm/Hooks/pagination.js +12 -0
  26. package/dist/esm/Hooks/pagination.test.d.ts +1 -0
  27. package/dist/esm/Hooks/pagination.test.js +47 -0
  28. package/dist/esm/Hooks/selection.d.ts +11 -0
  29. package/dist/esm/Hooks/selection.js +22 -0
  30. package/dist/esm/Hooks/selection.test.d.ts +1 -0
  31. package/dist/esm/Hooks/selection.test.js +53 -0
  32. package/generate-fed-package-json.js +7 -8
  33. package/generate-index.js +2 -2
  34. package/package.json +7 -6
  35. package/patternfly-docs/content/extensions/data-view/examples/{DataViewToolbar/DataViewToolbar.md → Components/Components.md} +9 -5
  36. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +20 -0
  37. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +77 -0
  38. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +65 -0
  39. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +88 -0
  40. package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataView.md → Layout/Layout.md} +9 -6
  41. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +120 -0
  42. package/src/DataView/DataView.test.tsx +16 -8
  43. package/src/DataView/__snapshots__/DataView.test.tsx.snap +134 -0
  44. package/src/DataViewToolbar/DataViewToolbar.test.tsx +11 -0
  45. package/src/DataViewToolbar/DataViewToolbar.tsx +12 -5
  46. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +538 -0
  47. package/src/Hooks/index.ts +2 -1
  48. package/src/Hooks/pagination.test.tsx +57 -0
  49. package/src/Hooks/pagination.ts +31 -0
  50. package/src/Hooks/selection.test.tsx +52 -0
  51. package/src/Hooks/selection.ts +32 -0
  52. package/dist/cjs/Hooks/useDataViewPagination.d.ts +0 -4
  53. package/dist/cjs/Hooks/useDataViewPagination.js +0 -2
  54. package/dist/esm/Hooks/useDataViewPagination.d.ts +0 -4
  55. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewPredefinedLayoutExample.tsx +0 -24
  56. package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +0 -7
  57. package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +0 -23
  58. package/src/Hooks/useDataViewPagination.ts +0 -4
  59. /package/dist/{esm/Hooks/useDataViewPagination.js → cjs/DataViewToolbar/DataViewToolbar.test.d.ts} +0 -0
  60. /package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewLayoutExample.tsx → Layout/AbstractLayoutExample.tsx} +0 -0
@@ -5,21 +5,25 @@ section: extensions
5
5
  subsection: Data view
6
6
  # Sidenav secondary level section
7
7
  # should be the same for all markdown files
8
- id: Data view toolbar
8
+ id: Components
9
9
  # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
10
  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
+ sortValue: 4
13
14
  propComponents: ['DataViewToolbar']
14
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbar.md
15
+ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
15
16
  ---
17
+ import { BulkSelect } from '@patternfly/react-component-groups';
16
18
  import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
17
19
 
18
- The **data view toolbar** component renders a default opinionated data view toolbar.
20
+ ## Data view toolbar
19
21
 
20
- ### Basic example
22
+ The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
23
+
24
+ Data view toolbar can contain a `pagination`, `bulkSelect` or any other children content passed. The preffered way of passing children toolbar items is using the [toolbar item](/components/toolbar#toolbar-items) component.
21
25
 
22
- 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.
26
+ ### Basic example
23
27
 
24
28
  ```js file="./DataViewToolbarExample.tsx"
25
29
 
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { Pagination } from '@patternfly/react-core';
3
+ import { BulkSelect } from '@patternfly/react-component-groups';
4
+ import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
5
+
6
+
7
+ export const BasicExample: React.FunctionComponent = () => (
8
+ <DataViewToolbar
9
+ pagination={
10
+ <Pagination page={1} perPage={10} />
11
+ }
12
+ bulkSelect={
13
+ <BulkSelect
14
+ selectedCount={0}
15
+ pageCount={5}
16
+ onSelect={() => null}
17
+ />
18
+ }
19
+ />
20
+ )
@@ -0,0 +1,77 @@
1
+ ---
2
+ # Sidenav top-level section
3
+ # should be the same for all markdown files
4
+ section: extensions
5
+ subsection: Data view
6
+ # Sidenav secondary level section
7
+ # should be the same for all markdown files
8
+ id: Functionality
9
+ # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
+ source: react
11
+ # If you use typescript, the name of the interface to display props for
12
+ # These are found through the sourceProps function provided in patternfly-docs.source.js
13
+ sortValue: 3
14
+ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md
15
+ ---
16
+ import { useMemo } from 'react';
17
+ import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
18
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
19
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
20
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
21
+
22
+ This is a list of functionality you can use to manage data displayed in the **data view**.
23
+
24
+ # Pagination
25
+ Allows to display data records on multiple pages and display the pagination state.
26
+
27
+ ### Toolbar usage
28
+ 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.
29
+
30
+ ### Pagination state
31
+
32
+ The `useDataViewPagination` hook manages the pagination state of the data view.
33
+
34
+ **Initial values:**
35
+ - `perPage` initial value
36
+ - (optional) `page` initial value
37
+
38
+ The retrieved values are named to match the PatternFly [pagination](/components/pagination) component props, so you can easily spread them.
39
+
40
+ **Return values:**
41
+ - current `page` number
42
+ - `onSetPage` to modify current page
43
+ - items `perPage` value
44
+ - `onPerPageSelect` to modify per page value
45
+
46
+ ### Pagination example
47
+ ```js file="./PaginationExample.tsx"
48
+
49
+ ```
50
+
51
+ # Selection
52
+ Allows to select data records inside the data view and show the selection state.
53
+
54
+ ### Toolbar usage
55
+ 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.
56
+
57
+ ### Selection state
58
+
59
+ The `useDataViewSelection` hook manages the selection state of the data view.
60
+
61
+ **Initial values:**
62
+ - (optional) `initialSelected` array of record's identifiers selected by default
63
+ - (optional) `matchOption` function to check if given record is selected
64
+
65
+ *When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.*
66
+
67
+ **Return values:**
68
+ - `selected` array of currently selected records
69
+ - `isSelected` function returning the selection state for given record
70
+ - `onSelect` callback to modify the selection state and accepting `isSelecting` flag indicating if records are changing to selected or deselected and `items` containing affected records
71
+
72
+ ### Selection example
73
+
74
+ ```js file="./SelectionExample.tsx"
75
+
76
+ ```
77
+
@@ -0,0 +1,65 @@
1
+ import React, { useMemo } from 'react';
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
+
8
+ const perPageOptions = [
9
+ { title: '5', value: 5 },
10
+ { title: '10', value: 10 }
11
+ ]
12
+
13
+ interface Repository {
14
+ name: string;
15
+ branches: string | null;
16
+ prs: string | null;
17
+ workspaces: string;
18
+ lastCommit: string;
19
+ }
20
+
21
+ const repositories: Repository[] = [
22
+ { name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
23
+ { name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
24
+ { name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
25
+ { name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
26
+ { name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
27
+ { name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
28
+ ];
29
+
30
+ const cols = {
31
+ name: 'Repositories',
32
+ branches: 'Branches',
33
+ prs: 'Pull requests',
34
+ workspaces: 'Workspaces',
35
+ lastCommit: 'Last commit'
36
+ };
37
+
38
+ const ouiaId = 'LayoutExample';
39
+
40
+ export const BasicExample: React.FunctionComponent = () => {
41
+ const pagination = useDataViewPagination({ perPage: 5 });
42
+ const { page, perPage } = pagination;
43
+
44
+ const data = useMemo(() => repositories.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
45
+
46
+ return (
47
+ <DataView>
48
+ <DataViewToolbar ouiaId='DataViewHeader' pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
49
+ <Table aria-label="Repositories table" ouiaId={ouiaId}>
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>
63
+ <DataViewToolbar ouiaId='DataViewFooter' pagination={<Pagination isCompact perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
64
+ </DataView>
65
+ )}
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
3
+ import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
4
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
5
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
6
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
7
+
8
+ interface Repository {
9
+ name: string;
10
+ branches: string | null;
11
+ prs: string | null;
12
+ workspaces: string;
13
+ lastCommit: string;
14
+ }
15
+
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' }
23
+ ];
24
+
25
+ const cols = {
26
+ name: 'Repositories',
27
+ branches: 'Branches',
28
+ prs: 'Pull requests',
29
+ workspaces: 'Workspaces',
30
+ lastCommit: 'Last commit'
31
+ };
32
+
33
+ const ouiaId = 'LayoutExample';
34
+
35
+ export const BasicExample: React.FunctionComponent = () => {
36
+ const selection = useDataViewSelection({});
37
+ const { selected, onSelect, isSelected } = selection;
38
+
39
+ const handleBulkSelect = (value: BulkSelectValue) => {
40
+ value === BulkSelectValue.none && onSelect(false);
41
+ value === BulkSelectValue.all && onSelect(true, repositories);
42
+ };
43
+
44
+ return (
45
+ <DataView>
46
+ <DataViewToolbar
47
+ ouiaId='DataViewHeader'
48
+ bulkSelect={
49
+ <BulkSelect
50
+ canSelectAll
51
+ isDataPaginated={false}
52
+ totalCount={repositories.length}
53
+ selectedCount={selected.length}
54
+ onSelect={handleBulkSelect}
55
+ />
56
+ }
57
+ />
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>
86
+ </DataView>
87
+ );
88
+ }
@@ -5,15 +5,18 @@ section: extensions
5
5
  subsection: Data view
6
6
  # Sidenav secondary level section
7
7
  # should be the same for all markdown files
8
- id: Data view layout
8
+ id: Layout
9
9
  # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
10
  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
+ sortValue: 2
13
14
  propComponents: ['DataView']
14
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md
15
+ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md
15
16
  ---
16
- import { Pagination } from '@patternfly/react-core';
17
+ import { useMemo } from 'react';
18
+ import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
19
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
17
20
  import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
18
21
  import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
19
22
 
@@ -23,14 +26,14 @@ The **data view** component renders record data in a configured layout.
23
26
 
24
27
  Data view is expected to consist of header, data part and footer stacked below each other and passed as `children`.
25
28
 
26
- ```js file="./DataViewLayoutExample.tsx"
29
+ ```js file="./AbstractLayoutExample.tsx"
27
30
 
28
31
  ```
29
32
 
30
33
  ### Predefined layout components
31
34
 
32
- You can make use of the predefined layout components to display a default header and footer. See [data view toolbar](/data-view/data-view-toolbar) for more information
35
+ You can make use of the predefined layout components to display a default header and footer. See [data view toolbar](/extensions/data-view/components#dataviewtoolbar) for more information
33
36
 
34
- ```js file="./DataViewPredefinedLayoutExample.tsx"
37
+ ```js file="./PredefinedLayoutExample.tsx"
35
38
 
36
39
  ```
@@ -0,0 +1,120 @@
1
+ import React, { useMemo } from 'react';
2
+ import { Pagination } from '@patternfly/react-core';
3
+ import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
4
+ import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
5
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
6
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
7
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
8
+
9
+ const perPageOptions = [
10
+ { title: '5', value: 5 },
11
+ { title: '10', value: 10 }
12
+ ];
13
+
14
+ interface Repository {
15
+ name: string;
16
+ branches: string | null;
17
+ prs: string | null;
18
+ workspaces: string;
19
+ lastCommit: string;
20
+ }
21
+
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' }
29
+ ];
30
+
31
+ const cols = {
32
+ name: 'Repositories',
33
+ branches: 'Branches',
34
+ prs: 'Pull requests',
35
+ workspaces: 'Workspaces',
36
+ lastCommit: 'Last commit'
37
+ };
38
+
39
+ const ouiaId = 'LayoutExample';
40
+
41
+ export const BasicExample: React.FunctionComponent = () => {
42
+ const pagination = useDataViewPagination({ perPage: 5 });
43
+ const { page, perPage } = pagination;
44
+ const selection = useDataViewSelection({});
45
+ const { selected, onSelect, isSelected } = selection;
46
+
47
+ const pageData = useMemo(() => repositories.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
48
+
49
+ const handleBulkSelect = (value: BulkSelectValue) => {
50
+ 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);
54
+ };
55
+
56
+ return (
57
+ <DataView>
58
+ <DataViewToolbar
59
+ ouiaId='LayoutExampleHeader'
60
+ bulkSelect={
61
+ <BulkSelect
62
+ canSelectAll
63
+ pageCount={pageData.length}
64
+ totalCount={repositories.length}
65
+ selectedCount={selected.length}
66
+ pageSelected={pageData.every(item => isSelected(item))}
67
+ pagePartiallySelected={pageData.some(item => isSelected(item)) && !pageData.every(item => isSelected(item))}
68
+ onSelect={handleBulkSelect}
69
+ />
70
+ }
71
+ pagination={
72
+ <Pagination
73
+ perPageOptions={perPageOptions}
74
+ itemCount={repositories.length}
75
+ {...pagination}
76
+ />
77
+ }
78
+ />
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>
107
+ <DataViewToolbar
108
+ ouiaId='LayoutExampleFooter'
109
+ pagination={
110
+ <Pagination
111
+ isCompact
112
+ perPageOptions={perPageOptions}
113
+ itemCount={repositories.length}
114
+ {...pagination}
115
+ />
116
+ }
117
+ />
118
+ </DataView>
119
+ );
120
+ }
@@ -1,13 +1,21 @@
1
1
  import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import '@testing-library/jest-dom'
2
+ import { render } from '@testing-library/react';
4
3
  import DataView from './DataView';
5
4
 
6
- describe('DataView', () => {
5
+ const layoutItemStyling = {
6
+ width: '100%',
7
+ height: '5rem',
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)'
10
+ };
7
11
 
8
- it('should render data view', () => {
9
- render(<DataView><>Data view content</></DataView>);
10
- expect(screen.getByText('Data view content')).toBeInTheDocument();
12
+ describe('DataView component', () => {
13
+ test('should render correctly', () => {
14
+ expect(render(
15
+ <DataView>
16
+ <div style={layoutItemStyling}>Header</div>
17
+ <div style={layoutItemStyling}>Data representation</div>
18
+ <div style={layoutItemStyling}>Footer</div>
19
+ </DataView>)).toMatchSnapshot();
11
20
  });
12
-
13
- });
21
+ });
@@ -0,0 +1,134 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DataView component should render correctly 1`] = `
4
+ {
5
+ "asFragment": [Function],
6
+ "baseElement": <body>
7
+ <div>
8
+ <div
9
+ class="pf-v6-l-stack"
10
+ data-ouia-component-id="DataView-stack}"
11
+ >
12
+ <div
13
+ class="pf-v6-l-stack__item"
14
+ data-ouia-component-id="DataView-stack-item-0"
15
+ >
16
+ <div
17
+ style="width: 100%; height: 5rem;"
18
+ >
19
+ Header
20
+ </div>
21
+ </div>
22
+ <div
23
+ class="pf-v6-l-stack__item"
24
+ data-ouia-component-id="DataView-stack-item-1"
25
+ >
26
+ <div
27
+ style="width: 100%; height: 5rem;"
28
+ >
29
+ Data representation
30
+ </div>
31
+ </div>
32
+ <div
33
+ class="pf-v6-l-stack__item"
34
+ data-ouia-component-id="DataView-stack-item-2"
35
+ >
36
+ <div
37
+ style="width: 100%; height: 5rem;"
38
+ >
39
+ Footer
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </body>,
45
+ "container": <div>
46
+ <div
47
+ class="pf-v6-l-stack"
48
+ data-ouia-component-id="DataView-stack}"
49
+ >
50
+ <div
51
+ class="pf-v6-l-stack__item"
52
+ data-ouia-component-id="DataView-stack-item-0"
53
+ >
54
+ <div
55
+ style="width: 100%; height: 5rem;"
56
+ >
57
+ Header
58
+ </div>
59
+ </div>
60
+ <div
61
+ class="pf-v6-l-stack__item"
62
+ data-ouia-component-id="DataView-stack-item-1"
63
+ >
64
+ <div
65
+ style="width: 100%; height: 5rem;"
66
+ >
67
+ Data representation
68
+ </div>
69
+ </div>
70
+ <div
71
+ class="pf-v6-l-stack__item"
72
+ data-ouia-component-id="DataView-stack-item-2"
73
+ >
74
+ <div
75
+ style="width: 100%; height: 5rem;"
76
+ >
77
+ Footer
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </div>,
82
+ "debug": [Function],
83
+ "findAllByAltText": [Function],
84
+ "findAllByDisplayValue": [Function],
85
+ "findAllByLabelText": [Function],
86
+ "findAllByPlaceholderText": [Function],
87
+ "findAllByRole": [Function],
88
+ "findAllByTestId": [Function],
89
+ "findAllByText": [Function],
90
+ "findAllByTitle": [Function],
91
+ "findByAltText": [Function],
92
+ "findByDisplayValue": [Function],
93
+ "findByLabelText": [Function],
94
+ "findByPlaceholderText": [Function],
95
+ "findByRole": [Function],
96
+ "findByTestId": [Function],
97
+ "findByText": [Function],
98
+ "findByTitle": [Function],
99
+ "getAllByAltText": [Function],
100
+ "getAllByDisplayValue": [Function],
101
+ "getAllByLabelText": [Function],
102
+ "getAllByPlaceholderText": [Function],
103
+ "getAllByRole": [Function],
104
+ "getAllByTestId": [Function],
105
+ "getAllByText": [Function],
106
+ "getAllByTitle": [Function],
107
+ "getByAltText": [Function],
108
+ "getByDisplayValue": [Function],
109
+ "getByLabelText": [Function],
110
+ "getByPlaceholderText": [Function],
111
+ "getByRole": [Function],
112
+ "getByTestId": [Function],
113
+ "getByText": [Function],
114
+ "getByTitle": [Function],
115
+ "queryAllByAltText": [Function],
116
+ "queryAllByDisplayValue": [Function],
117
+ "queryAllByLabelText": [Function],
118
+ "queryAllByPlaceholderText": [Function],
119
+ "queryAllByRole": [Function],
120
+ "queryAllByTestId": [Function],
121
+ "queryAllByText": [Function],
122
+ "queryAllByTitle": [Function],
123
+ "queryByAltText": [Function],
124
+ "queryByDisplayValue": [Function],
125
+ "queryByLabelText": [Function],
126
+ "queryByPlaceholderText": [Function],
127
+ "queryByRole": [Function],
128
+ "queryByTestId": [Function],
129
+ "queryByText": [Function],
130
+ "queryByTitle": [Function],
131
+ "rerender": [Function],
132
+ "unmount": [Function],
133
+ }
134
+ `;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import DataViewToolbar from './DataViewToolbar';
4
+ import { Pagination } from '@patternfly/react-core';
5
+
6
+ describe('DataViewToolbar component', () => {
7
+ test('should render correctly', () => {
8
+ expect(render(
9
+ <DataViewToolbar pagination={<Pagination page={1} perPage={10} />} />)).toMatchSnapshot();
10
+ });
11
+ });
@@ -1,21 +1,27 @@
1
- import React from 'react';
1
+ import React, { PropsWithChildren } from 'react';
2
2
  import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
3
3
 
4
- export interface DataViewToolbarProps {
4
+ export interface DataViewToolbarProps extends PropsWithChildren {
5
5
  /** Toolbar className */
6
6
  className?: string;
7
7
  /** Custom OUIA ID */
8
8
  ouiaId?: string;
9
+ /** React component to display bulk select */
10
+ bulkSelect?: React.ReactNode;
9
11
  /** React component to display pagination */
10
12
  pagination?: React.ReactNode;
11
13
  }
12
14
 
13
- export const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarProps>> = ({ className, ouiaId = 'DataViewToolbar', pagination, children, ...props }: React.PropsWithChildren<DataViewToolbarProps>) => (
15
+ export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children, ...props }: DataViewToolbarProps) => (
14
16
  <Toolbar ouiaId={ouiaId} className={className} {...props}>
15
17
  <ToolbarContent>
18
+ {bulkSelect && (
19
+ <ToolbarItem data-ouia-component-id={`${ouiaId}-bulk-select`}>
20
+ {bulkSelect}
21
+ </ToolbarItem>
22
+ )}
16
23
  {pagination && (
17
- <ToolbarItem variant={ToolbarItemVariant.pagination}>
18
- { /* TO DO: Make the pagination work later */ }
24
+ <ToolbarItem variant={ToolbarItemVariant.pagination} data-ouia-component-id={`${ouiaId}-pagination`}>
19
25
  {pagination}
20
26
  </ToolbarItem>
21
27
  )}
@@ -25,3 +31,4 @@ export const DataViewToolbar: React.FC<React.PropsWithChildren<DataViewToolbarPr
25
31
  );
26
32
 
27
33
  export default DataViewToolbar;
34
+