@patternfly/react-data-view 6.1.0-prerelease.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +13 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +31 -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 +75 -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 +13 -3
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +9 -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 +73 -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/AllSelectedExample.tsx +116 -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 +154 -0
- package/patternfly-docs/pages/index.js +1 -1
- package/release.config.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 +55 -22
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +52 -8
- package/src/Hooks/filters.test.tsx +89 -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,116 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Pagination, ToggleGroup, ToggleGroupItem, Tooltip } from '@patternfly/react-core';
|
|
3
|
+
import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
|
|
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
|
+
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups';
|
|
8
|
+
|
|
9
|
+
const TOGGLE_ALL = 'all';
|
|
10
|
+
const TOGGLE_SELECTED = 'selected';
|
|
11
|
+
|
|
12
|
+
const perPageOptions = [
|
|
13
|
+
{ title: '5', value: 5 },
|
|
14
|
+
{ title: '10', value: 10 }
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
interface Repository {
|
|
18
|
+
name: string;
|
|
19
|
+
branches: string | null;
|
|
20
|
+
prs: string | null;
|
|
21
|
+
workspaces: string;
|
|
22
|
+
lastCommit: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const repositories: Repository[] = [
|
|
26
|
+
{ name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one' },
|
|
27
|
+
{ name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two' },
|
|
28
|
+
{ name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three' },
|
|
29
|
+
{ name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four' },
|
|
30
|
+
{ name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five' },
|
|
31
|
+
{ name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six' }
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const rows = repositories.map(item => Object.values(item));
|
|
35
|
+
|
|
36
|
+
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
|
|
37
|
+
|
|
38
|
+
const ouiaId = 'LayoutExample';
|
|
39
|
+
|
|
40
|
+
export const BasicExample: React.FunctionComponent = () => {
|
|
41
|
+
const pagination = useDataViewPagination({ perPage: 5 });
|
|
42
|
+
const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
|
|
43
|
+
const [ selectedToggle, setSelectedToggle ] = useState(TOGGLE_ALL);
|
|
44
|
+
const { selected, onSelect } = selection;
|
|
45
|
+
const { page, perPage, onSetPage } = pagination;
|
|
46
|
+
|
|
47
|
+
const pageRows = useMemo(() => (selectedToggle === TOGGLE_SELECTED ? selected : rows).slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage, selectedToggle, selected ]);
|
|
48
|
+
|
|
49
|
+
const handleBulkSelect = (value: BulkSelectValue) => {
|
|
50
|
+
value === BulkSelectValue.none && onSelect(false);
|
|
51
|
+
value === BulkSelectValue.all && onSelect(true, rows);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleItemClick = (event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, _isSelected: boolean) => {
|
|
55
|
+
const id = event.currentTarget.id;
|
|
56
|
+
|
|
57
|
+
if (id === TOGGLE_SELECTED && selected.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (selectedToggle !== id) {
|
|
62
|
+
setSelectedToggle(id);
|
|
63
|
+
onSetPage(undefined, 1);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (selected.length === 0) {
|
|
69
|
+
setSelectedToggle(TOGGLE_ALL);
|
|
70
|
+
}
|
|
71
|
+
}, [ selected ]);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<DataView selection={selection}>
|
|
75
|
+
<DataViewToolbar
|
|
76
|
+
ouiaId='DataViewHeader'
|
|
77
|
+
bulkSelect={
|
|
78
|
+
<BulkSelect
|
|
79
|
+
canSelectAll
|
|
80
|
+
isDataPaginated={false}
|
|
81
|
+
totalCount={repositories.length}
|
|
82
|
+
selectedCount={selected.length}
|
|
83
|
+
onSelect={handleBulkSelect}
|
|
84
|
+
/>
|
|
85
|
+
}
|
|
86
|
+
toggleGroup={
|
|
87
|
+
<ToggleGroup aria-label="Toggle group to switch between all / selected table rows">
|
|
88
|
+
<ToggleGroupItem
|
|
89
|
+
text="All"
|
|
90
|
+
buttonId={TOGGLE_ALL}
|
|
91
|
+
isSelected={selectedToggle === TOGGLE_ALL}
|
|
92
|
+
onChange={handleItemClick}
|
|
93
|
+
/>
|
|
94
|
+
<ToggleGroupItem
|
|
95
|
+
id="selected-row-switch"
|
|
96
|
+
text="Selected"
|
|
97
|
+
buttonId={TOGGLE_SELECTED}
|
|
98
|
+
isSelected={selectedToggle === TOGGLE_SELECTED}
|
|
99
|
+
onChange={handleItemClick}
|
|
100
|
+
aria-disabled={selected.length === 0}
|
|
101
|
+
/>
|
|
102
|
+
</ToggleGroup>
|
|
103
|
+
}
|
|
104
|
+
pagination={<Pagination perPageOptions={perPageOptions} itemCount={repositories.length} {...pagination} />}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
{selected.length === 0 && (<Tooltip
|
|
108
|
+
id="selected-row-switch-tooltip"
|
|
109
|
+
content="Select at least one row to enable this filter"
|
|
110
|
+
triggerRef={() => document.getElementById('selected-row-switch') as HTMLButtonElement}
|
|
111
|
+
/>)}
|
|
112
|
+
|
|
113
|
+
<DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
|
|
114
|
+
</DataView>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -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
|
+
}
|