@patternfly/react-data-view 6.1.0-prerelease.1 → 7.0.0-prerelease.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/DataView/DataView.d.ts +12 -0
- package/dist/cjs/DataView/DataView.js +14 -3
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
- package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
- package/dist/cjs/DataViewEventsContext/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
- package/dist/cjs/DataViewTable/index.d.ts +2 -0
- package/dist/cjs/DataViewTable/index.js +23 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
- package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
- package/dist/cjs/DataViewTableBasic/index.js +23 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
- package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
- package/dist/cjs/DataViewTableHead/index.js +23 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +132 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
- package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
- package/dist/cjs/DataViewTableTree/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/cjs/Hooks/pagination.d.ts +13 -1
- package/dist/cjs/Hooks/pagination.js +36 -4
- package/dist/cjs/Hooks/pagination.test.js +1 -1
- package/dist/cjs/Hooks/selection.d.ts +3 -3
- package/dist/cjs/Hooks/selection.js +4 -6
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/InternalContext/InternalContext.d.ts +25 -0
- package/dist/cjs/InternalContext/InternalContext.js +40 -0
- package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
- package/dist/cjs/InternalContext/index.d.ts +2 -0
- package/dist/cjs/InternalContext/index.js +23 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.js +20 -2
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewTable/package.json +1 -0
- package/dist/dynamic/DataViewTableBasic/package.json +1 -0
- package/dist/dynamic/DataViewTableHead/package.json +1 -0
- package/dist/dynamic/DataViewTableTree/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +12 -0
- package/dist/esm/DataView/DataView.js +13 -2
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
- package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
- package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
- package/dist/esm/DataViewEventsContext/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +41 -0
- package/dist/esm/DataViewTable/DataViewTable.js +8 -0
- package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
- package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
- package/dist/esm/DataViewTable/index.d.ts +2 -0
- package/dist/esm/DataViewTable/index.js +2 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +18 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
- package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
- package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
- package/dist/esm/DataViewTableBasic/index.js +2 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +13 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
- package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
- package/dist/esm/DataViewTableHead/index.d.ts +2 -0
- package/dist/esm/DataViewTableHead/index.js +2 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +24 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +105 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
- package/dist/esm/DataViewTableTree/index.d.ts +2 -0
- package/dist/esm/DataViewTableTree/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +2 -1
- package/dist/esm/Hooks/pagination.d.ts +13 -1
- package/dist/esm/Hooks/pagination.js +36 -4
- package/dist/esm/Hooks/pagination.test.js +1 -1
- package/dist/esm/Hooks/selection.d.ts +3 -3
- package/dist/esm/Hooks/selection.js +4 -6
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/InternalContext/InternalContext.d.ts +25 -0
- package/dist/esm/InternalContext/InternalContext.js +12 -0
- package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
- package/dist/esm/InternalContext/InternalContext.test.js +51 -0
- package/dist/esm/InternalContext/index.d.ts +2 -0
- package/dist/esm/InternalContext/index.js +2 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -9
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +80 -5
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +4 -4
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +32 -0
- package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsExample.tsx +108 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +14 -6
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +28 -37
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +15 -46
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +2 -1
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +20 -51
- package/patternfly-docs/pages/index.js +1 -1
- package/src/DataView/DataView.tsx +25 -3
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +37 -0
- package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
- package/src/DataViewTable/index.ts +2 -0
- package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
- package/src/DataViewTableBasic/DataViewTableBasic.tsx +82 -0
- package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
- package/src/DataViewTableBasic/index.ts +2 -0
- package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
- package/src/DataViewTableHead/DataViewTableHead.tsx +53 -0
- package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
- package/src/DataViewTableHead/index.ts +2 -0
- package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
- package/src/DataViewTableTree/DataViewTableTree.tsx +164 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +9 -2
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +8 -8
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +68 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +6 -7
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +51 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-data-view",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-prerelease.2",
|
|
4
4
|
"description": "Data view used for Red Hat projects.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"tag": "prerelease"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@patternfly/react-
|
|
35
|
-
"@patternfly/react-
|
|
36
|
-
"@patternfly/react-
|
|
37
|
-
"@patternfly/react-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
34
|
+
"@patternfly/react-component-groups": "6.0.0-prerelease.7",
|
|
35
|
+
"@patternfly/react-core": "6.0.0-prerelease.21",
|
|
36
|
+
"@patternfly/react-icons": "6.0.0-prerelease.7",
|
|
37
|
+
"@patternfly/react-table": "6.0.0-prerelease.22",
|
|
38
|
+
"clsx": "^2.1.1",
|
|
39
|
+
"react-jss": "^10.10.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^17 || ^18",
|
|
43
43
|
"react-dom": "^17 || ^18"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@patternfly/documentation-framework": "6.0.0-alpha.117",
|
|
47
|
+
"@patternfly/patternfly": "6.0.0-prerelease.15",
|
|
46
48
|
"@patternfly/patternfly-a11y": "^4.3.1",
|
|
47
|
-
"@patternfly/patternfly": "6.0.0-alpha.205",
|
|
48
|
-
"@patternfly/documentation-framework": "6.0.0-alpha.69",
|
|
49
49
|
"@types/react": "^18.3.1",
|
|
50
50
|
"@types/react-dom": "^18.3.0",
|
|
51
51
|
"@types/react-router-dom": "^5.3.3",
|
|
@@ -11,21 +11,96 @@ 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: 4
|
|
14
|
-
propComponents: ['DataViewToolbar']
|
|
14
|
+
propComponents: ['DataViewToolbar', 'DataViewTableBasic', 'DataViewTableTree']
|
|
15
15
|
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
|
|
16
16
|
---
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
17
|
+
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter } from '@patternfly/react-core';
|
|
18
|
+
import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
|
|
19
|
+
import { BulkSelect, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
|
|
20
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
21
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
22
|
+
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
23
|
+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
24
|
|
|
20
25
|
## Data view toolbar
|
|
21
26
|
|
|
22
27
|
The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
|
|
23
28
|
|
|
24
|
-
Data view toolbar can contain a `pagination`, `bulkSelect` or
|
|
29
|
+
Data view toolbar can contain a `pagination`, `bulkSelect`, `actions` or other children content passed. The preffered way of passing children toolbar items is using the [toolbar item](/components/toolbar#toolbar-items) component.
|
|
25
30
|
|
|
26
|
-
### Basic example
|
|
31
|
+
### Basic toolbar example
|
|
27
32
|
|
|
28
33
|
```js file="./DataViewToolbarExample.tsx"
|
|
29
34
|
|
|
30
35
|
```
|
|
31
36
|
|
|
37
|
+
# Toolbar actions
|
|
38
|
+
Data view toolbar can display actions using the `actions` property accepting a React node. You can make use of a predefined [responsive actions](/extensions/component-groups/responsive-actions) component from the [component groups](/extensions/component-groups/about-component-groups) extension.
|
|
39
|
+
|
|
40
|
+
### Actions configuration
|
|
41
|
+
|
|
42
|
+
### Actions example
|
|
43
|
+
|
|
44
|
+
```js file="./DataViewToolbarActionsExample.tsx"
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Data view table
|
|
49
|
+
|
|
50
|
+
The **data view table** component renders your columns and rows definition into a [table](/components/table) component.
|
|
51
|
+
|
|
52
|
+
### Rows and columns customization
|
|
53
|
+
|
|
54
|
+
This example shows possible formats of `rows` and `columns` passed to the `DataViewTable` which allow you various customizations of the table head and body.
|
|
55
|
+
|
|
56
|
+
```js file="./DataViewTableExample.tsx"
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The `DataViewTable` component accepts the following props:
|
|
61
|
+
|
|
62
|
+
- `columns` defining the column heads of the table. Each item in the array can be a `ReactNode` (for simple heads) or an object with the following properties:
|
|
63
|
+
- `cell` (`ReactNode`) content to display in the column head.
|
|
64
|
+
- optional `props` (`ThProps`) to pass to the `<Th>` component, such as `width`, `sort`, and other table head cell properties.
|
|
65
|
+
|
|
66
|
+
- `rows` defining the rows to be displayed in the table. Each item in the array can be either an array of `DataViewTd` (for simple rows) or an object with the following properties:
|
|
67
|
+
- `row` (`DataViewTd[]`) defining the content for each cell in the row.
|
|
68
|
+
- optional `id` (`string`) for the row (can be used to match items in selection).
|
|
69
|
+
- optional `props` (`TrProps`) to pass to the `<Tr>` component, such as `isHoverable`, `isRowSelected`, and other table row properties.
|
|
70
|
+
|
|
71
|
+
- optional `ouiaId`
|
|
72
|
+
|
|
73
|
+
- optional `props` (`TableProps`) that are passed down to the `<Table>` component, except for `onSelect`, which is managed internally.
|
|
74
|
+
|
|
75
|
+
### Tree table example
|
|
76
|
+
This example shows the tree table variant with expandable rows, custom icons for leaf and parent nodes. Tree table is turned on by passing `isTreeTable` flag to the `DataViewTable` component. You can pass `collapsedIcon`, `expandedIcon` or `leafIcon` to be displayen rows with given status. The tree table rows have to be defined in a format of object with following keys:
|
|
77
|
+
- `row` (`DataViewTd[]`) defining the content for each cell in the row.
|
|
78
|
+
- `id` (`string`) for the row (used to match items in selection end expand the rows).
|
|
79
|
+
- optional `children` (`DataViewTrTree[]`) defining the children rows.
|
|
80
|
+
|
|
81
|
+
It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component.
|
|
82
|
+
|
|
83
|
+
```js file="./DataViewTableTreeExample.tsx"
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Empty state example
|
|
88
|
+
The data view table supports displaying a custom empty state. You can pass it using the the `headStates` and `bodyStates` properties and their `empty` key. It will be automatically displayed in case there are no rows to be rendered.
|
|
89
|
+
|
|
90
|
+
```js file="./DataViewTableEmptyExample.tsx"
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Error state example
|
|
95
|
+
The data view table also supports displaying an error state. You can pass it using the the `headStates` and `bodyStates` properties and their `error` key. It will be displayed in case the data view recieves its `state` property set to `error`.
|
|
96
|
+
|
|
97
|
+
```js file="./DataViewTableErrorExample.tsx"
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Loading state example
|
|
102
|
+
The data view table also supports displaying a custom loading state. You can pass it using the `headStates` and `bodyStates` properties and their `loading` key. Your state will be displayed in case the data view recieves its `state` property set to `loading`.
|
|
103
|
+
|
|
104
|
+
```js file="./DataViewTableLoadingExample.tsx"
|
|
105
|
+
|
|
106
|
+
```
|
|
@@ -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
|
+
);
|
package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx
ADDED
|
@@ -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-v5-u-ml-sm' color="var(--pf-t--temp--dev--tbd)"/* CODEMODS: original v5 color was --pf-v5-global--danger-color--100 *//></> },
|
|
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,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
import { BulkSelect, ResponsiveAction, ResponsiveActions } from '@patternfly/react-component-groups';
|
|
4
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
5
|
+
|
|
6
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
7
|
+
<DataViewToolbar
|
|
8
|
+
bulkSelect={
|
|
9
|
+
<BulkSelect
|
|
10
|
+
selectedCount={0}
|
|
11
|
+
pageCount={5}
|
|
12
|
+
onSelect={() => null}
|
|
13
|
+
/>
|
|
14
|
+
}
|
|
15
|
+
actions={
|
|
16
|
+
<ResponsiveActions breakpoint="lg" ouiaId="example-actions">
|
|
17
|
+
<ResponsiveAction isPersistent variant="primary">Persistent</ResponsiveAction>
|
|
18
|
+
<ResponsiveAction isPinned variant="secondary">Pinned</ResponsiveAction>
|
|
19
|
+
<ResponsiveAction>Action three</ResponsiveAction>
|
|
20
|
+
<ResponsiveAction>Action four</ResponsiveAction>
|
|
21
|
+
</ResponsiveActions>
|
|
22
|
+
}
|
|
23
|
+
pagination={
|
|
24
|
+
<Pagination page={1} perPage={10} />
|
|
25
|
+
}
|
|
26
|
+
/>
|
|
27
|
+
)
|
package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx
CHANGED
|
@@ -6,15 +6,15 @@ import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewTo
|
|
|
6
6
|
|
|
7
7
|
export const BasicExample: React.FunctionComponent = () => (
|
|
8
8
|
<DataViewToolbar
|
|
9
|
-
pagination={
|
|
10
|
-
<Pagination page={1} perPage={10} />
|
|
11
|
-
}
|
|
12
9
|
bulkSelect={
|
|
13
10
|
<BulkSelect
|
|
14
11
|
selectedCount={0}
|
|
15
12
|
pageCount={5}
|
|
16
13
|
onSelect={() => null}
|
|
17
14
|
/>
|
|
18
|
-
}
|
|
15
|
+
}
|
|
16
|
+
pagination={
|
|
17
|
+
<Pagination page={1} perPage={10} />
|
|
18
|
+
}
|
|
19
19
|
/>
|
|
20
20
|
)
|
|
@@ -0,0 +1,32 @@
|
|
|
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: Events context
|
|
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/EventsContext/EventsContext.md
|
|
15
|
+
---
|
|
16
|
+
import { useState, useEffect, useRef, useMemo } from 'react';
|
|
17
|
+
import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
|
|
18
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
19
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
20
|
+
import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
|
|
21
|
+
import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
|
|
22
|
+
|
|
23
|
+
The **data view events context** provides a way of listening to the data view events from the outside of the component.
|
|
24
|
+
|
|
25
|
+
### Row click subscription example
|
|
26
|
+
The following example demonstrates how to use the `DataViewEventsContext` to manage shared state and handle events. The `DataViewEventsProvider` is used to wrap components that need access to the shared context. This example illustrates how to set up a layout that listens for data view row click events and displays detailed information about the selected row in a [drawer component](/components/drawer).
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```js file="./EventsExample.tsx"
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
|
|
@@ -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
|
+
};
|
package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md
CHANGED
|
@@ -14,10 +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';
|
|
22
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
23
|
+
|
|
21
24
|
|
|
22
25
|
This is a list of functionality you can use to manage data displayed in the **data view**.
|
|
23
26
|
|
|
@@ -33,9 +36,15 @@ The `useDataViewPagination` hook manages the pagination state of the data view.
|
|
|
33
36
|
|
|
34
37
|
**Initial values:**
|
|
35
38
|
- `perPage` initial value
|
|
36
|
-
-
|
|
39
|
+
- optional `page` initial value
|
|
40
|
+
- optional `searchParams` object
|
|
41
|
+
- optional `setSearchParams` function
|
|
42
|
+
|
|
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.
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
You can also pass custom `pageParam` or `perPageParam` names, renaming the pagination parameters in the URL.
|
|
46
|
+
|
|
47
|
+
The retrieved values are named to match the PatternFly [pagination](/components/pagination) component props, so you can easily spread them to the component.
|
|
39
48
|
|
|
40
49
|
**Return values:**
|
|
41
50
|
- current `page` number
|
|
@@ -52,15 +61,15 @@ The retrieved values are named to match the PatternFly [pagination](/components/
|
|
|
52
61
|
Allows to select data records inside the data view and show the selection state.
|
|
53
62
|
|
|
54
63
|
### 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.
|
|
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.
|
|
56
65
|
|
|
57
66
|
### Selection state
|
|
58
67
|
|
|
59
68
|
The `useDataViewSelection` hook manages the selection state of the data view.
|
|
60
69
|
|
|
61
70
|
**Initial values:**
|
|
62
|
-
-
|
|
63
|
-
-
|
|
71
|
+
- optional `initialSelected` array of record's identifiers selected by default
|
|
72
|
+
- `matchOption` function to check if given record is selected
|
|
64
73
|
|
|
65
74
|
*When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.*
|
|
66
75
|
|
|
@@ -74,4 +83,3 @@ The `useDataViewSelection` hook manages the selection state of the data view.
|
|
|
74
83
|
```js file="./SelectionExample.tsx"
|
|
75
84
|
|
|
76
85
|
```
|
|
77
|
-
|