@patternfly/react-data-view 6.0.0-prerelease.1 → 6.1.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.
- package/dist/cjs/DataView/DataView.d.ts +15 -1
- package/dist/cjs/DataView/DataView.js +14 -3
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +70 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +25 -0
- package/dist/cjs/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewCheckboxFilter/index.js +23 -0
- 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/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.js +85 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/cjs/DataViewFilters/DataViewFilters.test.js +19 -0
- package/dist/cjs/DataViewFilters/index.d.ts +2 -0
- package/dist/cjs/DataViewFilters/index.js +23 -0
- package/dist/cjs/DataViewTable/DataViewTable.d.ts +49 -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 +19 -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 +14 -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 +25 -0
- package/dist/cjs/DataViewTableTree/DataViewTableTree.js +144 -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/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +26 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +22 -0
- package/dist/cjs/DataViewTextFilter/index.d.ts +2 -0
- package/dist/cjs/DataViewTextFilter/index.js +23 -0
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +11 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +30 -6
- package/dist/cjs/Hooks/filters.d.ts +14 -0
- package/dist/cjs/Hooks/filters.js +69 -0
- package/dist/cjs/Hooks/filters.test.d.ts +1 -0
- package/dist/cjs/Hooks/filters.test.js +50 -0
- package/dist/cjs/Hooks/index.d.ts +2 -0
- package/dist/cjs/Hooks/index.js +2 -0
- package/dist/cjs/Hooks/pagination.d.ts +14 -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 -4
- package/dist/cjs/Hooks/selection.test.js +4 -4
- package/dist/cjs/Hooks/sort.d.ts +32 -0
- package/dist/cjs/Hooks/sort.js +47 -0
- package/dist/cjs/Hooks/sort.test.d.ts +1 -0
- package/dist/cjs/Hooks/sort.test.js +68 -0
- package/dist/cjs/InternalContext/InternalContext.d.ts +26 -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 +16 -0
- package/dist/cjs/index.js +26 -2
- package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
- package/dist/dynamic/DataViewEventsContext/package.json +1 -0
- package/dist/dynamic/DataViewFilters/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/DataViewTextFilter/package.json +1 -0
- package/dist/dynamic/InternalContext/package.json +1 -0
- package/dist/esm/DataView/DataView.d.ts +15 -1
- package/dist/esm/DataView/DataView.js +13 -2
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +62 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
- package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +20 -0
- package/dist/esm/DataViewCheckboxFilter/index.d.ts +2 -0
- package/dist/esm/DataViewCheckboxFilter/index.js +2 -0
- 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/DataViewFilters/DataViewFilters.d.ts +25 -0
- package/dist/esm/DataViewFilters/DataViewFilters.js +58 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.d.ts +1 -0
- package/dist/esm/DataViewFilters/DataViewFilters.test.js +14 -0
- package/dist/esm/DataViewFilters/index.d.ts +2 -0
- package/dist/esm/DataViewFilters/index.js +2 -0
- package/dist/esm/DataViewTable/DataViewTable.d.ts +49 -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 +19 -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 +14 -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 +25 -0
- package/dist/esm/DataViewTableTree/DataViewTableTree.js +117 -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/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +19 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
- package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +17 -0
- package/dist/esm/DataViewTextFilter/index.d.ts +2 -0
- package/dist/esm/DataViewTextFilter/index.js +2 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +11 -3
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +8 -4
- package/dist/esm/Hooks/filters.d.ts +14 -0
- package/dist/esm/Hooks/filters.js +65 -0
- package/dist/esm/Hooks/filters.test.d.ts +1 -0
- package/dist/esm/Hooks/filters.test.js +48 -0
- package/dist/esm/Hooks/index.d.ts +2 -0
- package/dist/esm/Hooks/index.js +2 -0
- package/dist/esm/Hooks/pagination.d.ts +14 -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 -4
- package/dist/esm/Hooks/selection.test.js +4 -4
- package/dist/esm/Hooks/sort.d.ts +32 -0
- package/dist/esm/Hooks/sort.js +43 -0
- package/dist/esm/Hooks/sort.test.d.ts +1 -0
- package/dist/esm/Hooks/sort.test.js +66 -0
- package/dist/esm/InternalContext/InternalContext.d.ts +26 -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 +16 -0
- package/dist/esm/index.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +16 -15
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +45 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +67 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +71 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +87 -0
- package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarActionsExample.tsx +27 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +107 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +56 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +57 -0
- package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +142 -0
- package/patternfly-docs/pages/index.js +1 -1
- package/src/DataView/DataView.tsx +28 -5
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +24 -0
- package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +175 -0
- package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +197 -0
- package/src/DataViewCheckboxFilter/index.ts +2 -0
- package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
- package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
- package/src/DataViewEventsContext/index.ts +2 -0
- package/src/DataViewFilters/DataViewFilters.test.tsx +21 -0
- package/src/DataViewFilters/DataViewFilters.tsx +144 -0
- package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +194 -0
- package/src/DataViewFilters/index.tsx +2 -0
- package/src/DataViewTable/DataViewTable.test.tsx +80 -0
- package/src/DataViewTable/DataViewTable.tsx +57 -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 +83 -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 +54 -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 +186 -0
- package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
- package/src/DataViewTableTree/index.ts +2 -0
- package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +24 -0
- package/src/DataViewTextFilter/DataViewTextFilter.tsx +54 -0
- package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +203 -0
- package/src/DataViewTextFilter/index.ts +2 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +48 -22
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +264 -174
- package/src/Hooks/filters.test.tsx +62 -0
- package/src/Hooks/filters.ts +97 -0
- package/src/Hooks/index.ts +2 -0
- package/src/Hooks/pagination.test.tsx +1 -1
- package/src/Hooks/pagination.ts +69 -12
- package/src/Hooks/selection.test.tsx +5 -5
- package/src/Hooks/selection.ts +7 -7
- package/src/Hooks/sort.test.tsx +84 -0
- package/src/Hooks/sort.ts +87 -0
- package/src/InternalContext/InternalContext.test.tsx +89 -0
- package/src/InternalContext/InternalContext.tsx +52 -0
- package/src/InternalContext/index.ts +2 -0
- package/src/index.ts +24 -0
- package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
- package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -31
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -77
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +0 -65
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +0 -88
- package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -39
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -120
- /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
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: Table
|
|
9
|
+
title: Data view table
|
|
10
|
+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
11
|
+
source: react
|
|
12
|
+
# If you use typescript, the name of the interface to display props for
|
|
13
|
+
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
14
|
+
sortValue: 3
|
|
15
|
+
propComponents: ['DataViewTableBasic', 'DataViewTableTree', 'DataViewTrTree', 'DataViewTrObject']
|
|
16
|
+
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Table/Table.md
|
|
17
|
+
---
|
|
18
|
+
import { useMemo } from 'react';
|
|
19
|
+
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
20
|
+
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter } from '@patternfly/react-core';
|
|
21
|
+
import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
|
|
22
|
+
import { ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
|
|
23
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
24
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
25
|
+
import { useDataViewSelection, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
26
|
+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
27
|
+
|
|
28
|
+
The **data view table** component renders your data into columns and rows within a [PatternFly table](/components/table) component. You can easily customize and configure the table with these additional [data view components and props](/extensions/data-view/table#props).
|
|
29
|
+
|
|
30
|
+
## Configuring rows and columns
|
|
31
|
+
To define rows and columns for your table, use these props:
|
|
32
|
+
- `columns`: Defines 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:
|
|
33
|
+
- `cell`: Content to display in the column head.
|
|
34
|
+
- `props` (optional): (`ThProps`) to pass to the `<Th>` component, such as `width`, `sort`, and other table head cell properties.
|
|
35
|
+
- `rows`: Defines 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:
|
|
36
|
+
- `row`: Content to display in each cell in the row.
|
|
37
|
+
- `id` (optional): Unique identifier for the row that's used for matching selected items.
|
|
38
|
+
- `props` (optional): (`TrProps`) to pass to the `<Tr>` component, such as `isHoverable`, `isRowSelected`, and other table row properties.
|
|
39
|
+
|
|
40
|
+
It is also possible to disable row selection using the `isSelectDisabled` function, which can be passed to the wrapping `DataView` component through the `selection` prop.
|
|
41
|
+
|
|
42
|
+
### Table example
|
|
43
|
+
```js file="./DataViewTableExample.tsx"
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Tree table
|
|
48
|
+
|
|
49
|
+
A tree table includes expandable rows and custom icons for leaf and parent nodes.
|
|
50
|
+
To enable a tree table, pass the `isTreeTable` flag to the `<DataViewTable>` component.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Tree table rows have to be defined with following keys:
|
|
54
|
+
- `row`: Defines the content for each cell in the row.
|
|
55
|
+
- `id`: Unique identifier for the row that's used for matching selected items.
|
|
56
|
+
- `children` (optional): Defines the children rows.
|
|
57
|
+
|
|
58
|
+
To update a row's icon to reflect its expansion state, pass `collapsedIcon`, `expandedIcon`, and `leafIcon` to `<DataViewTable>`.
|
|
59
|
+
|
|
60
|
+
To disable row selection, pass the `isSelectDisabled` function to `selection` prop of the wrapping `<DataView>` component .
|
|
61
|
+
|
|
62
|
+
### Tree table example
|
|
63
|
+
|
|
64
|
+
```js file="./DataViewTableTreeExample.tsx"
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Sorting
|
|
69
|
+
The following example demonstrates how to enable sorting functionality within a data view. This implementation supports dynamic sorting by column and persists the sort state in the page's URL via [React Router](https://reactrouter.com/).
|
|
70
|
+
|
|
71
|
+
### Sorting example
|
|
72
|
+
```js file="./SortingExample.tsx"
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
### Sorting state
|
|
76
|
+
|
|
77
|
+
The `useDataViewSort` hook manages the sorting state of a data view and provides an easy way to handle sorting logic, such as synchronization with URL parameters and the definition of default sorting behavior.
|
|
78
|
+
|
|
79
|
+
**Initial values:**
|
|
80
|
+
- `initialSort` object to set default `sortBy` and `direction` values:
|
|
81
|
+
- `sortBy`: Key of the initial column to sort.
|
|
82
|
+
- `direction`: Default sorting direction (`asc` or `desc`).
|
|
83
|
+
- `searchParams` (optional): Object to manage URL-based synchronization of sort state.
|
|
84
|
+
- `setSearchParams` (optional): Function to update the URL parameters when sorting changes.
|
|
85
|
+
- `defaultDirection`: Used to set the default direction when no direction is specified.
|
|
86
|
+
- Customizable parameter names for the URL:
|
|
87
|
+
- `sortByParam`: Name of the URL parameter for the column key.
|
|
88
|
+
- `directionParam`: Name of the URL parameter for the sorting direction.
|
|
89
|
+
The `useDataViewSort` hook integrates seamlessly with [React Router](https://reactrouter.com/) to manage the sort state via URL parameters. Alternatively, you can use `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If URL synchronization is not configured, the sort state is managed internally within the component.
|
|
90
|
+
|
|
91
|
+
**Return values:**
|
|
92
|
+
- `sortBy`: Key of the column currently being sorted.
|
|
93
|
+
- `direction`: Current sorting direction (`asc` or `desc`).
|
|
94
|
+
- `onSort`: Function to handle sorting changes programmatically or via user interaction.
|
|
95
|
+
|
|
96
|
+
## States
|
|
97
|
+
|
|
98
|
+
The data view table allows you to react to the `activeState` of the data view (such as `empty`, `error`, `loading`). You can use the `headStates` and `bodyStates` props to define the table head and body for a given state.
|
|
99
|
+
|
|
100
|
+
### Empty
|
|
101
|
+
When there is no data to render in the data view, you can instead display an empty state.
|
|
102
|
+
|
|
103
|
+
You can create your empty state by passing a [PatternFly empty state](/components/empty-state) to the `empty` key of `headStates` or `bodyStates`.
|
|
104
|
+
|
|
105
|
+
```js file="./DataViewTableEmptyExample.tsx"
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Error
|
|
110
|
+
When there is a data connection or retrieval error, you can display an error state.
|
|
111
|
+
|
|
112
|
+
The error state will be displayed when the data view `activeState` value is `error`.
|
|
113
|
+
|
|
114
|
+
You can create your error state by passing either the [component groups extension's error state](/component-groups/error-state) or a [PatternFly empty state](/components/empty-state) to the `error` key of `headStates` or `bodyStates`.
|
|
115
|
+
|
|
116
|
+
```js file="./DataViewTableErrorExample.tsx"
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Loading
|
|
121
|
+
To indicate that data is loading, you can display a loading state.
|
|
122
|
+
|
|
123
|
+
The loading state will be displayed when the data view `activeState` value is `loading`.
|
|
124
|
+
|
|
125
|
+
You can create your loading state by passing either the [component groups extension's skeleton table](/component-groups/skeleton-table) or a customized [PatternFly empty state](/components/empty-state) to the `loading` key of `headStates` or `bodyStates`.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
```js file="./DataViewTableLoadingExample.tsx"
|
|
129
|
+
|
|
130
|
+
```
|
|
@@ -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/Toolbar/DataViewToolbarExample.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Pagination } from '@patternfly/react-core';
|
|
4
|
+
import { BulkSelect } from '@patternfly/react-component-groups';
|
|
5
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
6
|
+
import { ResponsiveAction, ResponsiveActions } from '@patternfly/react-component-groups';
|
|
7
|
+
import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
|
|
8
|
+
import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
|
|
9
|
+
|
|
10
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
11
|
+
<DataViewToolbar
|
|
12
|
+
clearAllFilters={() => console.log('clearAllFilters called')}
|
|
13
|
+
bulkSelect={
|
|
14
|
+
<BulkSelect
|
|
15
|
+
selectedCount={0}
|
|
16
|
+
pageCount={5}
|
|
17
|
+
onSelect={() => console.log('onSelect called')}
|
|
18
|
+
/>
|
|
19
|
+
}
|
|
20
|
+
filters={
|
|
21
|
+
<DataViewFilters onChange={() => console.log('onSetFilters calles')} values={{}}>
|
|
22
|
+
<DataViewTextFilter filterId="name" title='Name' placeholder='Filter by name' />
|
|
23
|
+
<DataViewTextFilter filterId="branch" title='Branch' placeholder='Filter by branch' />
|
|
24
|
+
</DataViewFilters>
|
|
25
|
+
}
|
|
26
|
+
actions={
|
|
27
|
+
<ResponsiveActions ouiaId="example-actions">
|
|
28
|
+
<ResponsiveAction>Add repository</ResponsiveAction>
|
|
29
|
+
<ResponsiveAction>Delete repository</ResponsiveAction>
|
|
30
|
+
</ResponsiveActions>
|
|
31
|
+
}
|
|
32
|
+
pagination={
|
|
33
|
+
<Pagination page={1} perPage={10} isCompact />
|
|
34
|
+
}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { useDataViewFilters, useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
7
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
8
|
+
import { DataViewFilterOption, DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
|
|
9
|
+
import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
|
|
10
|
+
import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
|
|
11
|
+
|
|
12
|
+
const perPageOptions = [
|
|
13
|
+
{ title: '5', value: 5 },
|
|
14
|
+
{ title: '10', value: 10 }
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
interface Repository {
|
|
18
|
+
name: string;
|
|
19
|
+
branch: string | null;
|
|
20
|
+
prs: string | null;
|
|
21
|
+
workspace: string;
|
|
22
|
+
lastCommit: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface RepositoryFilters {
|
|
26
|
+
name: string,
|
|
27
|
+
branch: string,
|
|
28
|
+
workspace: string[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const repositories: Repository[] = [
|
|
32
|
+
{ name: 'Repository one', branch: 'Branch one', prs: 'Pull request one', workspace: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
33
|
+
{ name: 'Repository two', branch: 'Branch two', prs: 'Pull request two', workspace: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
34
|
+
{ name: 'Repository three', branch: 'Branch three', prs: 'Pull request three', workspace: 'Workspace one', lastCommit: 'Timestamp three' },
|
|
35
|
+
{ name: 'Repository four', branch: 'Branch four', prs: 'Pull request four', workspace: 'Workspace one', lastCommit: 'Timestamp four' },
|
|
36
|
+
{ name: 'Repository five', branch: 'Branch five', prs: 'Pull request five', workspace: 'Workspace two', lastCommit: 'Timestamp five' },
|
|
37
|
+
{ name: 'Repository six', branch: 'Branch six', prs: 'Pull request six', workspace: 'Workspace three', lastCommit: 'Timestamp six' }
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const filterOptions: DataViewFilterOption[] = [
|
|
41
|
+
{ label: 'Workspace one', value: 'workspace-one' },
|
|
42
|
+
{ label: 'Workspace two', value: 'workspace-two' },
|
|
43
|
+
{ label: 'Workspace three', value: 'workspace-three' }
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const columns = [ 'Name', 'Branch', 'Pull requests', 'Workspace', 'Last commit' ];
|
|
47
|
+
|
|
48
|
+
const ouiaId = 'LayoutExample';
|
|
49
|
+
|
|
50
|
+
const MyTable: React.FunctionComponent = () => {
|
|
51
|
+
const [ searchParams, setSearchParams ] = useSearchParams();
|
|
52
|
+
const { filters, onSetFilters, clearAllFilters } = useDataViewFilters<RepositoryFilters>({ initialFilters: { name: '', branch: '', workspace: [] }, searchParams, setSearchParams });
|
|
53
|
+
const pagination = useDataViewPagination({ perPage: 5 });
|
|
54
|
+
const { page, perPage } = pagination;
|
|
55
|
+
|
|
56
|
+
const filteredData = useMemo(() => repositories.filter(item =>
|
|
57
|
+
(!filters.name || item.name?.toLocaleLowerCase().includes(filters.name?.toLocaleLowerCase())) &&
|
|
58
|
+
(!filters.branch || item.branch?.toLocaleLowerCase().includes(filters.branch?.toLocaleLowerCase())) &&
|
|
59
|
+
(!filters.workspace || filters.workspace.length === 0 || filters.workspace.includes(String(filterOptions.find(option => option.label === item.workspace)?.value)))
|
|
60
|
+
), [ filters ]);
|
|
61
|
+
|
|
62
|
+
const pageRows = useMemo(() => filteredData
|
|
63
|
+
.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage)
|
|
64
|
+
.map(item => Object.values(item)),
|
|
65
|
+
[ page, perPage, filteredData ]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<DataView>
|
|
69
|
+
<DataViewToolbar
|
|
70
|
+
ouiaId='LayoutExampleHeader'
|
|
71
|
+
clearAllFilters = {clearAllFilters}
|
|
72
|
+
pagination={
|
|
73
|
+
<Pagination
|
|
74
|
+
perPageOptions={perPageOptions}
|
|
75
|
+
itemCount={filteredData.length}
|
|
76
|
+
{...pagination}
|
|
77
|
+
/>
|
|
78
|
+
}
|
|
79
|
+
filters={
|
|
80
|
+
<DataViewFilters onChange={(_e, values) => onSetFilters(values)} values={filters}>
|
|
81
|
+
<DataViewTextFilter filterId="name" title='Name' placeholder='Filter by name' />
|
|
82
|
+
<DataViewTextFilter filterId="branch" title='Branch' placeholder='Filter by branch' />
|
|
83
|
+
<DataViewCheckboxFilter filterId="workspace" title='Workspace' placeholder='Filter by workspace' options={filterOptions} />
|
|
84
|
+
</DataViewFilters>
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
88
|
+
<DataViewToolbar
|
|
89
|
+
ouiaId='LayoutExampleFooter'
|
|
90
|
+
pagination={
|
|
91
|
+
<Pagination
|
|
92
|
+
isCompact
|
|
93
|
+
perPageOptions={perPageOptions}
|
|
94
|
+
itemCount={filteredData.length}
|
|
95
|
+
{...pagination}
|
|
96
|
+
/>
|
|
97
|
+
}
|
|
98
|
+
/>
|
|
99
|
+
</DataView>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
104
|
+
<BrowserRouter>
|
|
105
|
+
<MyTable/>
|
|
106
|
+
</BrowserRouter>
|
|
107
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
5
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
6
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
7
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
8
|
+
|
|
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: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
24
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
25
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
26
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
27
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
28
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const rows = repositories.map(item => Object.values(item));
|
|
32
|
+
|
|
33
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
34
|
+
|
|
35
|
+
const ouiaId = 'LayoutExample';
|
|
36
|
+
|
|
37
|
+
const MyTable: React.FunctionComponent = () => {
|
|
38
|
+
const [ searchParams, setSearchParams ] = useSearchParams()
|
|
39
|
+
const pagination = useDataViewPagination({ perPage: 5, searchParams, setSearchParams });
|
|
40
|
+
const { page, perPage } = pagination;
|
|
41
|
+
|
|
42
|
+
const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
|
|
43
|
+
return (
|
|
44
|
+
<DataView>
|
|
45
|
+
<DataViewToolbar ouiaId='DataViewHeader' pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
46
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
47
|
+
<DataViewToolbar ouiaId='DataViewFooter' pagination={<Pagination isCompact perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />} />
|
|
48
|
+
</DataView>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const BasicExample: React.FunctionComponent = () => (
|
|
53
|
+
<BrowserRouter>
|
|
54
|
+
<MyTable/>
|
|
55
|
+
</BrowserRouter>
|
|
56
|
+
);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
3
|
+
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
|
|
4
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
5
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
6
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
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: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
18
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
19
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
20
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
21
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
22
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const rows = repositories.map(item => Object.values(item));
|
|
26
|
+
|
|
27
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
28
|
+
|
|
29
|
+
const ouiaId = 'LayoutExample';
|
|
30
|
+
|
|
31
|
+
export const BasicExample: React.FunctionComponent = () => {
|
|
32
|
+
const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
|
|
33
|
+
const { selected, onSelect } = selection;
|
|
34
|
+
|
|
35
|
+
const handleBulkSelect = (value: BulkSelectValue) => {
|
|
36
|
+
value === BulkSelectValue.none && onSelect(false);
|
|
37
|
+
value === BulkSelectValue.all && onSelect(true, rows);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<DataView selection={selection}>
|
|
42
|
+
<DataViewToolbar
|
|
43
|
+
ouiaId='DataViewHeader'
|
|
44
|
+
bulkSelect={
|
|
45
|
+
<BulkSelect
|
|
46
|
+
canSelectAll
|
|
47
|
+
isDataPaginated={false}
|
|
48
|
+
totalCount={repositories.length}
|
|
49
|
+
selectedCount={selected.length}
|
|
50
|
+
onSelect={handleBulkSelect}
|
|
51
|
+
/>
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
54
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
|
|
55
|
+
</DataView>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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: Toolbar
|
|
9
|
+
title: Data view toolbar
|
|
10
|
+
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
|
|
11
|
+
source: react
|
|
12
|
+
# If you use typescript, the name of the interface to display props for
|
|
13
|
+
# These are found through the sourceProps function provided in patternfly-docs.source.js
|
|
14
|
+
sortValue: 2
|
|
15
|
+
propComponents: ['DataViewToolbar', 'DataViewFilters', 'DataViewTextFilter', 'DataViewCheckboxFilter']
|
|
16
|
+
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md
|
|
17
|
+
---
|
|
18
|
+
import { useMemo } from 'react';
|
|
19
|
+
import { BrowserRouter, useSearchParams } from 'react-router-dom';
|
|
20
|
+
import { useDataViewPagination, useDataViewSelection, useDataViewFilters } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
21
|
+
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
22
|
+
import { BulkSelect, BulkSelectValue, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
|
|
23
|
+
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
24
|
+
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
|
|
25
|
+
import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
|
|
26
|
+
import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
|
|
27
|
+
import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
|
|
28
|
+
|
|
29
|
+
The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
|
|
30
|
+
|
|
31
|
+
Data view toolbar can contain pagination, bulk select, filters, actions, or other custom child content. To pass child items to the toolbar, use the [toolbar item](/components/toolbar#toolbar-items) component or predefined `<DataViewToolbar>` props for specific use cases.
|
|
32
|
+
|
|
33
|
+
You can further customize toolbar interactions by referring to the additional documentation:
|
|
34
|
+
- [Actions](#toolbar-actions)
|
|
35
|
+
- [Pagination](#pagination)
|
|
36
|
+
- [Selection](#selection)
|
|
37
|
+
- [Filters](#filters)
|
|
38
|
+
|
|
39
|
+
### Toolbar example
|
|
40
|
+
|
|
41
|
+
```js file="./DataViewToolbarExample.tsx"
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Toolbar actions
|
|
46
|
+
To support additional user needs, you can pass relevant actions to the toolbar via `actions`. Add standard PatternFly actions (like buttons) or choose predefined [responsive actions](/component-groups/responsive-actions) which ensure the responsive behavior of multiple actions in 1 toolbar.
|
|
47
|
+
|
|
48
|
+
### Actions example
|
|
49
|
+
|
|
50
|
+
```js file="./DataViewToolbarActionsExample.tsx"
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Pagination
|
|
55
|
+
|
|
56
|
+
To help users navigate data records that span multiple pages, add pagination support to your toolbar.
|
|
57
|
+
|
|
58
|
+
The data view toolbar can display a pagination using the `pagination` prop. You can also pass a custom `ouiaId` to the toolbar for testing purposes. You can also persist pagination values in the URL to make it easier to share or bookmark specific pages of your data.
|
|
59
|
+
|
|
60
|
+
### Pagination state
|
|
61
|
+
|
|
62
|
+
The `useDataViewPagination` hook manages the pagination state of the data view.
|
|
63
|
+
|
|
64
|
+
**Initial values:**
|
|
65
|
+
- `perPage` initial value.
|
|
66
|
+
- Optional `page` initial value.
|
|
67
|
+
- Optional `searchParams` object.
|
|
68
|
+
- Optional `setSearchParams` function.
|
|
69
|
+
|
|
70
|
+
While the hook works seamlessly with the [React Router](https://reactrouter.com/) 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.
|
|
71
|
+
|
|
72
|
+
You can also pass custom `pageParam` or `perPageParam` names, renaming the pagination parameters in the URL.
|
|
73
|
+
|
|
74
|
+
The retrieved values are named to match the PatternFly pagination component props.
|
|
75
|
+
|
|
76
|
+
**Return values:**
|
|
77
|
+
- Current `page` number.
|
|
78
|
+
- `onSetPage` to modify current page.
|
|
79
|
+
- Items `perPage` value.
|
|
80
|
+
- `onPerPageSelect` to modify per page value.
|
|
81
|
+
|
|
82
|
+
### Pagination example
|
|
83
|
+
This example uses the URL to persist the pagination state.
|
|
84
|
+
|
|
85
|
+
```js file="./PaginationExample.tsx"
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Selection
|
|
90
|
+
To allow users to select data records inside the data view, add selection support that displays a row's selection state.
|
|
91
|
+
|
|
92
|
+
The data view toolbar can display a bulk selection component by using the predefined [component group extension bulk select](/extensions/component-groups/bulk-select) component.
|
|
93
|
+
|
|
94
|
+
### Selection state
|
|
95
|
+
|
|
96
|
+
The `useDataViewSelection` hook manages the selection state of the data view.
|
|
97
|
+
|
|
98
|
+
**Initial values:**
|
|
99
|
+
- Optional `initialSelected` array of record's identifiers selected by default.
|
|
100
|
+
- `matchOption` function to check if the record is selected.
|
|
101
|
+
- When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.
|
|
102
|
+
|
|
103
|
+
**Return values:**
|
|
104
|
+
- `selected` array of currently selected records.
|
|
105
|
+
- `isSelected` function returning the selection state for the record.
|
|
106
|
+
- `onSelect` callback to modify the selection state. This accepts the `isSelecting` flag (indicates if records are being selected or deselected) and `items` (affected records).
|
|
107
|
+
|
|
108
|
+
### Selection example
|
|
109
|
+
|
|
110
|
+
```js file="./SelectionExample.tsx"
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Filters
|
|
115
|
+
To allow users to filter data records in the data view, add filtering support that displays the applied filter chips.
|
|
116
|
+
|
|
117
|
+
The data view toolbar can include a set of filters by passing a React node to the `filters` property. You can use the predefined components `<DataViewFilters>`, `<DataViewTextFilter>`, and `<DataViewCheckboxFilter>` to customize and handle filtering directly in the toolbar. The `<DataViewFilters>` component is a wrapper that allows conditional filtering using multiple attributes. If you need just a single filter, you can use `<DataViewTextFilter>`, `<DataViewCheckboxFilter>`, or a different filter component alone. Props of these filter components are listed in the [props section of this page](#props).
|
|
118
|
+
|
|
119
|
+
You can either pass a `value` and `onChange` event to every filter separately, or you can pass `values` and `onChange` to the `<DataViewFilters>` wrapper, which makes them available to its children. Props directly passed to child filters have a higher priority than the "inherited" ones.
|
|
120
|
+
|
|
121
|
+
### Filters state
|
|
122
|
+
|
|
123
|
+
The `useDataViewFilters` hook manages the filter state of the data view. It allows you to define default filter values, synchronize filter state with URL parameters, and handle filter changes efficiently.
|
|
124
|
+
|
|
125
|
+
**Initial values:**
|
|
126
|
+
- `initialFilters` object with default filter values (if the filter param allows multiple values, pass an array).
|
|
127
|
+
- Optional `searchParams` object for managing URL-based filter state.
|
|
128
|
+
- Optional `setSearchParams` function to update the URL when filters are modified.
|
|
129
|
+
|
|
130
|
+
The `useDataViewFilters` hook works well with the [React Router](https://reactrouter.com/) library to support URL-based filtering. Alternatively, you can manage the filter state in the URL using `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If no URL parameters are provided, the filter state is managed internally.
|
|
131
|
+
|
|
132
|
+
**Return values:**
|
|
133
|
+
- `filters` object representing the current filter values.
|
|
134
|
+
- `onSetFilters` function to update the filter state.
|
|
135
|
+
- `clearAllFilters` function to reset all filters to their initial values.
|
|
136
|
+
|
|
137
|
+
### Filtering example
|
|
138
|
+
This example demonstrates the setup and usage of filters within the data view. It includes text filters for different attributes, the ability to clear all filters, and persistence of filter state in the URL.
|
|
139
|
+
|
|
140
|
+
```js file="./FiltersExample.tsx"
|
|
141
|
+
|
|
142
|
+
```
|
|
@@ -10,7 +10,7 @@ const centerStyle = {
|
|
|
10
10
|
|
|
11
11
|
const IndexPage = () => {
|
|
12
12
|
return (
|
|
13
|
-
<PageSection style={centerStyle}>
|
|
13
|
+
<PageSection hasBodyWrapper={false} style={centerStyle}>
|
|
14
14
|
<div style={{ flex: 'none', textAlign: 'center' }}>
|
|
15
15
|
<Title size="4xl" headingLevel="h1">
|
|
16
16
|
My extension docs
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Stack, StackItem } from '@patternfly/react-core';
|
|
3
|
-
|
|
2
|
+
import { Stack, StackItem, StackProps } from '@patternfly/react-core';
|
|
3
|
+
import { DataViewSelection, InternalContextProvider } from '../InternalContext';
|
|
4
|
+
|
|
5
|
+
export const DataViewState = {
|
|
6
|
+
empty: 'empty',
|
|
7
|
+
loading: 'loading',
|
|
8
|
+
error: 'error'
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
|
|
12
|
+
|
|
13
|
+
/** extends StackProps */
|
|
14
|
+
export interface DataViewProps extends StackProps {
|
|
4
15
|
/** Content rendered inside the data view */
|
|
5
16
|
children: React.ReactNode;
|
|
6
17
|
/** Custom OUIA ID */
|
|
7
18
|
ouiaId?: string;
|
|
19
|
+
/** Selection context configuration */
|
|
20
|
+
selection?: DataViewSelection;
|
|
21
|
+
/** Currently active state */
|
|
22
|
+
activeState?: DataViewState | string;
|
|
8
23
|
}
|
|
9
24
|
|
|
10
|
-
export
|
|
25
|
+
export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
|
|
26
|
+
|
|
27
|
+
const DataViewImplementation: React.FC<DataViewImpementationProps> = ({
|
|
11
28
|
children, ouiaId = 'DataView', ...props
|
|
12
|
-
}:
|
|
13
|
-
<Stack data-ouia-component-id={`${ouiaId}-stack
|
|
29
|
+
}: DataViewImpementationProps) => (
|
|
30
|
+
<Stack data-ouia-component-id={`${ouiaId}-stack`} {...props}>
|
|
14
31
|
{React.Children.map(children, (child, index) => (
|
|
15
32
|
<StackItem data-ouia-component-id={`${ouiaId}-stack-item-${index}`}>
|
|
16
33
|
{child}
|
|
@@ -19,4 +36,10 @@ export const DataView: React.FC<DataViewProps> = ({
|
|
|
19
36
|
</Stack>
|
|
20
37
|
)
|
|
21
38
|
|
|
39
|
+
export const DataView: React.FC<DataViewProps> = ({ children, selection, activeState, ...props }: DataViewProps) => (
|
|
40
|
+
<InternalContextProvider selection={selection} activeState={activeState} >
|
|
41
|
+
<DataViewImplementation {...props}>{children}</DataViewImplementation>
|
|
42
|
+
</InternalContextProvider>
|
|
43
|
+
);
|
|
44
|
+
|
|
22
45
|
export default DataView;
|
|
@@ -7,7 +7,7 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
7
7
|
<div>
|
|
8
8
|
<div
|
|
9
9
|
class="pf-v6-l-stack"
|
|
10
|
-
data-ouia-component-id="DataView-stack
|
|
10
|
+
data-ouia-component-id="DataView-stack"
|
|
11
11
|
>
|
|
12
12
|
<div
|
|
13
13
|
class="pf-v6-l-stack__item"
|
|
@@ -45,7 +45,7 @@ exports[`DataView component should render correctly 1`] = `
|
|
|
45
45
|
"container": <div>
|
|
46
46
|
<div
|
|
47
47
|
class="pf-v6-l-stack"
|
|
48
|
-
data-ouia-component-id="DataView-stack
|
|
48
|
+
data-ouia-component-id="DataView-stack"
|
|
49
49
|
>
|
|
50
50
|
<div
|
|
51
51
|
class="pf-v6-l-stack__item"
|