@patternfly/react-data-view 7.0.0-prerelease.6 → 7.0.0-prerelease.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +1 -1
  2. package/dist/esm/DataViewToolbar/DataViewToolbar.js +1 -1
  3. package/package.json +5 -5
  4. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
  5. package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
  6. package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
  7. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
  8. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +142 -0
  9. package/src/DataViewToolbar/DataViewToolbar.tsx +4 -4
  10. package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
  11. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -108
  12. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
  13. package/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md +0 -33
  14. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -150
  15. package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -40
  16. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -89
  17. /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
  18. /package/patternfly-docs/content/extensions/data-view/examples/{EventsContext → DataView}/EventsExample.tsx +0 -0
  19. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Table}/DataViewTableEmptyExample.tsx +0 -0
  20. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Table}/DataViewTableErrorExample.tsx +0 -0
  21. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Table}/DataViewTableExample.tsx +0 -0
  22. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Table}/DataViewTableLoadingExample.tsx +0 -0
  23. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Table}/DataViewTableTreeExample.tsx +0 -0
  24. /package/patternfly-docs/content/extensions/data-view/examples/{Functionality → Table}/SortingExample.tsx +0 -0
  25. /package/patternfly-docs/content/extensions/data-view/examples/{Components → Toolbar}/DataViewToolbarActionsExample.tsx +0 -0
  26. /package/patternfly-docs/content/extensions/data-view/examples/{Functionality → Toolbar}/FiltersExample.tsx +0 -0
  27. /package/patternfly-docs/content/extensions/data-view/examples/{Functionality → Toolbar}/PaginationExample.tsx +0 -0
  28. /package/patternfly-docs/content/extensions/data-view/examples/{Functionality → Toolbar}/SelectionExample.tsx +0 -0
@@ -44,8 +44,8 @@ const DataViewToolbar = (_a) => {
44
44
  return (react_1.default.createElement(react_core_1.Toolbar, Object.assign({ ouiaId: ouiaId, className: className, customLabelGroupContent: customLabelGroupContent !== null && customLabelGroupContent !== void 0 ? customLabelGroupContent : defaultClearFilters.current }, props),
45
45
  react_1.default.createElement(react_core_1.ToolbarContent, null,
46
46
  bulkSelect && (react_1.default.createElement(react_core_1.ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
47
- actions && (react_1.default.createElement(react_core_1.ToolbarItem, null, actions)),
48
47
  filters && (react_1.default.createElement(react_core_1.ToolbarItem, null, filters)),
48
+ actions && (react_1.default.createElement(react_core_1.ToolbarItem, null, actions)),
49
49
  pagination && (react_1.default.createElement(react_core_1.ToolbarItem, { variant: react_core_1.ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
50
50
  children)));
51
51
  };
@@ -18,8 +18,8 @@ export const DataViewToolbar = (_a) => {
18
18
  return (React.createElement(Toolbar, Object.assign({ ouiaId: ouiaId, className: className, customLabelGroupContent: customLabelGroupContent !== null && customLabelGroupContent !== void 0 ? customLabelGroupContent : defaultClearFilters.current }, props),
19
19
  React.createElement(ToolbarContent, null,
20
20
  bulkSelect && (React.createElement(ToolbarItem, { "data-ouia-component-id": `${ouiaId}-bulk-select` }, bulkSelect)),
21
- actions && (React.createElement(ToolbarItem, null, actions)),
22
21
  filters && (React.createElement(ToolbarItem, null, filters)),
22
+ actions && (React.createElement(ToolbarItem, null, actions)),
23
23
  pagination && (React.createElement(ToolbarItem, { variant: ToolbarItemVariant.pagination, "data-ouia-component-id": `${ouiaId}-pagination` }, pagination)),
24
24
  children)));
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-data-view",
3
- "version": "7.0.0-prerelease.6",
3
+ "version": "7.0.0-prerelease.7",
4
4
  "description": "Data view used for Red Hat projects.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -47,13 +47,13 @@
47
47
  "@patternfly/patternfly": "^6.0.0",
48
48
  "@patternfly/react-code-editor": "^6.0.0",
49
49
  "@patternfly/patternfly-a11y": "^5.0.0",
50
- "@types/react": "^18.3.1",
51
- "@types/react-dom": "^18.3.0",
50
+ "@types/react": "^18.3.18",
51
+ "@types/react-dom": "^18.3.5",
52
52
  "@types/react-router-dom": "^5.3.3",
53
53
  "react": "^18.3.1",
54
54
  "react-dom": "^18.3.1",
55
- "react-router": "^6.23.0",
56
- "react-router-dom": "^6.28.0",
55
+ "react-router": "^6.28.1",
56
+ "react-router-dom": "^6.28.1",
57
57
  "rimraf": "^6.0.1",
58
58
  "typescript": "^5.4.5"
59
59
  }
@@ -0,0 +1,63 @@
1
+ ---
2
+ section: extensions
3
+ subsection: Data view
4
+ id: Overview
5
+ title: Data view overview
6
+ propComponents: ['DataView']
7
+ sortValue: 1
8
+ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md
9
+ ---
10
+ import { useState, useEffect, useRef, useMemo } from 'react';
11
+ import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
12
+ import { CubesIcon } from '@patternfly/react-icons';
13
+ import { useDataViewPagination, useDataViewSelection, useDataViewFilters, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
14
+ import { BulkSelect, BulkSelectValue, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
15
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
16
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
17
+ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
18
+ import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
19
+ import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
20
+ import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
21
+ import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
22
+
23
+ **Note:** Data view lives in its own package [`@patternfly/react-data-view`](https://www.npmjs.com/package/@patternfly/react-data-view)
24
+
25
+ If you notice a bug, or if you have a suggestion for improving the data view extension or its documentation, please file an issue in the [react-data-view](https://github.com/patternfly/react-data-view/issues) repository. Before doing so, please make sure there is not already a pre-existing issue.
26
+
27
+ ---
28
+
29
+ The **data view** extension enables you to display datasets in organized layouts, with data representations and interactive toolbars for actions like selection and pagination.
30
+
31
+ ### Layout
32
+
33
+ A data view should contain a header, the data representation, and a footer. These parts are organized in a [stack layout](/layouts/stack).
34
+
35
+ The data view toolbars and sub-components that display the data (like a card view or table) are always passed as `children` to the `<DataView>` component.
36
+
37
+ ```js file="./AbstractLayoutExample.tsx"
38
+
39
+ ```
40
+
41
+ ### Modularity
42
+
43
+ The extension's modular architecture lets you efficiently create consistent data views, either by using predefined sub-components and hooks, or by defining your own. You can choose the tools that suit your needs and easily replace any part with a custom implementation.
44
+
45
+ The `<DataViewToolbar>` component extends the [PatternFly toolbar](/components/toolbar) to support the most common needs. For more details, refer to the [data view toolbar](/extensions/data-view/toolbar) examples. You can also use a custom toolbar component if needed for your use case.
46
+
47
+ Data can be presented using the predefined `<DataViewTable>` component, which is an abstraction above the [PatternFly table](/components/table). For more details, refer to the [data view table](/extensions/data-view/table) examples. If you have more specific data display needs, you can pass a custom implementation as a `<DataView>` child. In the near future, we are also planning to introduce a predefined card view component.
48
+
49
+ ```js file="./PredefinedLayoutFullExample.tsx"
50
+
51
+ ```
52
+
53
+ ## Events context
54
+
55
+ The `<DataViewEventsContext>` component is an advanced feature that enables external listening of data view events. In order to share data view context with your other UI components, both your components and your data view should be wrapped with the `<DataViewEventsProvider>`. This is demonstrated in the following example.
56
+
57
+ ### Row click subscription example
58
+ This example uses the `<DataViewEventsProvider>` to display details about a selected row in a [drawer component](/components/drawer).
59
+
60
+
61
+ ```js file="./EventsExample.tsx"
62
+
63
+ ```
@@ -0,0 +1,275 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import React, { useEffect, useState, useRef, useMemo } from 'react';
3
+ import { Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentBody, DrawerHead, DrawerPanelContent, Title, Content, EmptyState, EmptyStateBody, EmptyStateFooter, EmptyStateActions, Button, } from '@patternfly/react-core';
4
+ import { ActionsColumn, Tbody, Td, ThProps, Tr } from '@patternfly/react-table';
5
+ import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
6
+ import { Pagination } from '@patternfly/react-core';
7
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
8
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
9
+ import { DataViewTable, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
10
+ import { DataViewEventsProvider, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
11
+ import { useDataViewPagination, useDataViewSelection, useDataViewFilters, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
12
+ import { ResponsiveAction, ResponsiveActions } from '@patternfly/react-component-groups';
13
+ import { DataViewFilterOption, DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
14
+ import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
15
+ import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
16
+ import { CubesIcon } from '@patternfly/react-icons';
17
+
18
+ const perPageOptions = [
19
+ { title: '5', value: 5 },
20
+ { title: '10', value: 10 }
21
+ ];
22
+
23
+ interface Repository {
24
+ name: string;
25
+ branch: string | null;
26
+ prs: string | null;
27
+ workspace: string;
28
+ lastCommit: string;
29
+ };
30
+
31
+ interface RepositoryFilters {
32
+ name: string,
33
+ branch: string,
34
+ workspace: string[]
35
+ };
36
+
37
+ const repositories: Repository[] = [
38
+ { name: 'Repository one', branch: 'Branch one', prs: 'Pull request one', workspace: 'Workspace one', lastCommit: 'Timestamp one' },
39
+ { name: 'Repository two', branch: 'Branch two', prs: 'Pull request two', workspace: 'Workspace two', lastCommit: 'Timestamp two' },
40
+ { name: 'Repository three', branch: 'Branch three', prs: 'Pull request three', workspace: 'Workspace three', lastCommit: 'Timestamp three' },
41
+ { name: 'Repository four', branch: 'Branch four', prs: 'Pull request four', workspace: 'Workspace four', lastCommit: 'Timestamp four' },
42
+ { name: 'Repository five', branch: 'Branch five', prs: 'Pull request five', workspace: 'Workspace five', lastCommit: 'Timestamp five' },
43
+ { name: 'Repository six', branch: 'Branch six', prs: 'Pull request six', workspace: 'Workspace six', lastCommit: 'Timestamp six' }
44
+ ];
45
+
46
+ const filterOptions: DataViewFilterOption[] = [
47
+ { label: 'Workspace one', value: 'workspace-one' },
48
+ { label: 'Workspace two', value: 'workspace-two' },
49
+ { label: 'Workspace three', value: 'workspace-three' }
50
+ ];
51
+
52
+ const COLUMNS = [
53
+ { label: 'Repository', key: 'name', index: 0 },
54
+ { label: 'Branch', key: 'branches', index: 1 },
55
+ { label: 'Pull request', key: 'prs', index: 2 },
56
+ { label: 'Workspace', key: 'workspaces', index: 3 },
57
+ { label: 'Last commit', key: 'lastCommit', index: 4 }
58
+ ];
59
+
60
+ const ouiaId = 'LayoutExample';
61
+
62
+ const sortData = (data: Repository[], sortBy: string | undefined, direction: 'asc' | 'desc' | undefined) =>
63
+ sortBy && direction
64
+ ? [ ...data ].sort((a, b) =>
65
+ direction === 'asc'
66
+ ? a[sortBy] < b[sortBy] ? -1 : a[sortBy] > b[sortBy] ? 1 : 0
67
+ : a[sortBy] > b[sortBy] ? -1 : a[sortBy] < b[sortBy] ? 1 : 0
68
+ )
69
+ : data;
70
+
71
+ const empty = (
72
+ <Tbody>
73
+ <Tr key="loading" ouiaId={`${ouiaId}-tr-loading`}>
74
+ <Td colSpan={COLUMNS.length}>
75
+ <EmptyState headingLevel="h4" icon={CubesIcon} titleText="No data found">
76
+ <EmptyStateBody>There are no matching data to be displayed.</EmptyStateBody>
77
+ <EmptyStateFooter>
78
+ <EmptyStateActions>
79
+ <Button variant="primary">Primary action</Button>
80
+ </EmptyStateActions>
81
+ <EmptyStateActions>
82
+ <Button variant="link">Multiple</Button>
83
+ <Button variant="link">Action Buttons</Button>
84
+ </EmptyStateActions>
85
+ </EmptyStateFooter>
86
+ </EmptyState>
87
+ </Td>
88
+ </Tr>
89
+ </Tbody>
90
+ );
91
+
92
+ interface RepositoryDetailProps {
93
+ selectedRepo?: Repository;
94
+ setSelectedRepo: React.Dispatch<React.SetStateAction<Repository | undefined>>;
95
+ }
96
+
97
+ const RepositoryDetail: React.FunctionComponent<RepositoryDetailProps> = ({ selectedRepo, setSelectedRepo }) => {
98
+ const context = useDataViewEventsContext();
99
+
100
+ useEffect(() => {
101
+ const unsubscribe = context.subscribe(EventTypes.rowClick, (repo: Repository) => {
102
+ setSelectedRepo(repo);
103
+ });
104
+
105
+ return () => unsubscribe();
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ }, []);
108
+
109
+ return (
110
+ <DrawerPanelContent>
111
+ <DrawerHead>
112
+ <Title className="pf-v5-u-mb-md" headingLevel="h2" ouiaId="detail-drawer-title">
113
+ Detail of {selectedRepo?.name}
114
+ </Title>
115
+ <Content component="p">Branch: {selectedRepo?.branch}</Content>
116
+ <Content component="p">Pull requests: {selectedRepo?.prs}</Content>
117
+ <Content component="p">Workspace: {selectedRepo?.workspace}</Content>
118
+ <Content component="p">Last commit: {selectedRepo?.lastCommit}</Content>
119
+ <DrawerActions>
120
+ <DrawerCloseButton onClick={() => setSelectedRepo(undefined)} data-ouia-component-id="detail-drawer-close-btn"/>
121
+ </DrawerActions>
122
+ </DrawerHead>
123
+ </DrawerPanelContent>
124
+ );
125
+ };
126
+
127
+ interface RepositoriesTableProps {
128
+ selectedRepo?: Repository;
129
+ }
130
+
131
+ const rowActions = [
132
+ {
133
+ title: 'Some action',
134
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
135
+ },
136
+ {
137
+ title: <div>Another action</div>,
138
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
139
+ },
140
+ {
141
+ isSeparator: true
142
+ },
143
+ {
144
+ title: 'Third action',
145
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
146
+ }
147
+ ];
148
+
149
+ const RepositoriesTable: React.FunctionComponent<RepositoriesTableProps> = ({ selectedRepo = undefined }) => {
150
+ const { filters, onSetFilters, clearAllFilters } = useDataViewFilters<RepositoryFilters>({ initialFilters: { name: '', branch: '', workspace: [] } });
151
+
152
+ const pagination = useDataViewPagination({ perPage: 5 });
153
+ const { page, perPage } = pagination;
154
+
155
+ const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
156
+ const { selected, onSelect, isSelected } = selection;
157
+
158
+ const { trigger } = useDataViewEventsContext();
159
+
160
+ const { sortBy, direction, onSort } = useDataViewSort();
161
+ const sortByIndex = useMemo(() => COLUMNS.findIndex(item => item.key === sortBy), [ sortBy ]);
162
+ const getSortParams = (columnIndex: number): ThProps['sort'] => ({
163
+ sortBy: {
164
+ index: sortByIndex,
165
+ direction,
166
+ defaultDirection: 'asc'
167
+ },
168
+ onSort: (_event, index, direction) => onSort(_event, COLUMNS[index].key, direction),
169
+ columnIndex
170
+ });
171
+
172
+ const columns: DataViewTh[] = COLUMNS.map((column, index) => ({
173
+ cell: column.label,
174
+ props: { sort: getSortParams(index) }
175
+ }));
176
+
177
+ const finalData = useMemo(() => sortData(repositories, sortBy, direction).filter(item =>
178
+ (!filters.name || item.name?.toLocaleLowerCase().includes(filters.name?.toLocaleLowerCase())) &&
179
+ (!filters.branch || item.branch?.toLocaleLowerCase().includes(filters.branch?.toLocaleLowerCase())) &&
180
+ (!filters.workspace || filters.workspace.length === 0 || filters.workspace.includes(String(filterOptions.find(option => option.label === item.workspace)?.value)))
181
+ ), [ filters, sortBy, direction ]);
182
+
183
+ const pageRows = useMemo(() => {
184
+ const handleRowClick = (event, repo: Repository | undefined) => {
185
+ // prevents drawer toggle on actions or checkbox click
186
+ (event.target.matches('td') || event.target.matches('tr')) && trigger(EventTypes.rowClick, repo);
187
+ };
188
+
189
+ return finalData.map(repo => ({
190
+ row: [ ...Object.values(repo), { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } } ],
191
+ props: {
192
+ isClickable: true,
193
+ onRowClick: (event) => handleRowClick(event, selectedRepo?.name === repo.name ? undefined : repo),
194
+ isRowSelected: selectedRepo?.name === repo.name
195
+ }
196
+ })).slice((page - 1) * perPage, ((page - 1) * perPage) + perPage);
197
+ }, [ selectedRepo?.name, trigger, page, perPage, finalData ]);
198
+
199
+ const handleBulkSelect = (value: BulkSelectValue) => {
200
+ value === BulkSelectValue.none && onSelect(false);
201
+ value === BulkSelectValue.nonePage && onSelect(false, pageRows);
202
+ value === BulkSelectValue.page && onSelect(true, pageRows);
203
+ };
204
+
205
+ return (
206
+ <DataView selection={selection} activeState={finalData.length > 0 ? undefined : 'empty'}>
207
+ <DataViewToolbar
208
+ ouiaId='LayoutExampleHeader'
209
+ clearAllFilters={clearAllFilters}
210
+ bulkSelect={
211
+ <BulkSelect
212
+ pageCount={pageRows.length}
213
+ totalCount={repositories.length}
214
+ selectedCount={selected.length}
215
+ pageSelected={pageRows.every(item => isSelected(item))}
216
+ pagePartiallySelected={pageRows.some(item => isSelected(item)) && !pageRows.every(item => isSelected(item))}
217
+ onSelect={handleBulkSelect}
218
+ />
219
+ }
220
+ filters={
221
+ <DataViewFilters onChange={(_e, values) => onSetFilters(values)} values={filters}>
222
+ <DataViewTextFilter filterId="name" title='Name' placeholder='Filter by name' />
223
+ <DataViewTextFilter filterId="branch" title='Branch' placeholder='Filter by branch' />
224
+ <DataViewCheckboxFilter filterId="workspace" title='Workspace' placeholder='Filter by workspace' options={filterOptions} />
225
+ </DataViewFilters>
226
+ }
227
+ actions={
228
+ <ResponsiveActions ouiaId="example-actions">
229
+ <ResponsiveAction>Add repository</ResponsiveAction>
230
+ <ResponsiveAction>Delete repository</ResponsiveAction>
231
+ </ResponsiveActions>
232
+ }
233
+ pagination={
234
+ <Pagination
235
+ isCompact
236
+ perPageOptions={perPageOptions}
237
+ itemCount={repositories.length}
238
+ {...pagination}
239
+ />
240
+ }
241
+ />
242
+ <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} bodyStates={{ empty }} />
243
+ <DataViewToolbar
244
+ ouiaId='LayoutExampleFooter'
245
+ pagination={
246
+ <Pagination
247
+ isCompact
248
+ perPageOptions={perPageOptions}
249
+ itemCount={repositories.length}
250
+ {...pagination}
251
+ />
252
+ }
253
+ />
254
+ </DataView>
255
+ );
256
+ };
257
+
258
+ export const BasicExample: React.FunctionComponent = () => {
259
+ const [ selectedRepo, setSelectedRepo ] = useState<Repository>();
260
+ const drawerRef = useRef<HTMLDivElement>(null);
261
+
262
+ return (
263
+ <DataViewEventsProvider>
264
+ <Drawer isExpanded={Boolean(selectedRepo)} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id="detail-drawer" >
265
+ <DrawerContent
266
+ panelContent={<RepositoryDetail selectedRepo={selectedRepo} setSelectedRepo={setSelectedRepo} />}
267
+ >
268
+ <DrawerContentBody>
269
+ <RepositoriesTable selectedRepo={selectedRepo} />
270
+ </DrawerContentBody>
271
+ </DrawerContent>
272
+ </Drawer>
273
+ </DataViewEventsProvider>
274
+ );
275
+ };
@@ -0,0 +1,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,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,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
+ ```
@@ -35,14 +35,14 @@ export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, oui
35
35
  {bulkSelect}
36
36
  </ToolbarItem>
37
37
  )}
38
- {actions && (
38
+ {filters && (
39
39
  <ToolbarItem>
40
- {actions}
40
+ {filters}
41
41
  </ToolbarItem>
42
42
  )}
43
- {filters && (
43
+ {actions && (
44
44
  <ToolbarItem>
45
- {filters}
45
+ {actions}
46
46
  </ToolbarItem>
47
47
  )}
48
48
  {pagination && (
@@ -1,14 +0,0 @@
1
- ---
2
- section: extensions
3
- subsection: Data view
4
- id: About data view
5
- sortValue: 1
6
- ---
7
-
8
- Data view lives in its own package [`@patternfly/react-data-view`](https://www.npmjs.com/package/@patternfly/react-data-view)
9
-
10
- # Data view
11
-
12
- The data view extension contains implementation of the data view component allowing to display record data in a configured layout.
13
-
14
- If you notice a bug or have a suggestion for the data view, feel free to file an issue in our [GitHub repository](https://github.com/patternfly/react-data-view/issues)! Please make sure to check if there is already a pre-existing issue before creating a new issue.
@@ -1,108 +0,0 @@
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: Components
9
- # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
- source: react
11
- # If you use typescript, the name of the interface to display props for
12
- # These are found through the sourceProps function provided in patternfly-docs.source.js
13
- sortValue: 4
14
- propComponents: ['DataViewToolbar', 'DataViewTableBasic', 'DataViewTableTree', 'DataViewTrTree', 'DataViewTrObject']
15
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
16
- ---
17
- import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter } from '@patternfly/react-core';
18
- import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
19
- import { BulkSelect, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
20
- import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
21
- import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
22
- import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
23
- import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
24
-
25
- ## Data view toolbar
26
-
27
- The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
28
-
29
- Data view toolbar can contain a `pagination`, `bulkSelect`, `filters`, `actions` or other children content passed. The preffered way of passing children toolbar items is using the [toolbar item](/components/toolbar#toolbar-items) component.
30
-
31
- ### Basic toolbar example
32
-
33
- ```js file="./DataViewToolbarExample.tsx"
34
-
35
- ```
36
-
37
- # Toolbar actions
38
- Data view toolbar can display actions using the `actions` property accepting a React node. You can make use of a predefined [responsive actions](/extensions/component-groups/responsive-actions) component from the [component groups](/extensions/component-groups/about-component-groups) extension.
39
-
40
- ### Actions configuration
41
-
42
- ### Actions example
43
-
44
- ```js file="./DataViewToolbarActionsExample.tsx"
45
-
46
- ```
47
-
48
- ## Data view table
49
-
50
- The **data view table** component renders your columns and rows definition into a [table](/components/table) component.
51
-
52
- ### Rows and columns customization
53
-
54
- This example shows possible formats of `rows` and `columns` passed to the `DataViewTable` which allow you various customizations of the table head and body.
55
-
56
- ```js file="./DataViewTableExample.tsx"
57
-
58
- ```
59
-
60
- The `DataViewTable` component accepts the following props:
61
-
62
- - `columns` defining the column heads of the table. Each item in the array can be a `ReactNode` (for simple heads) or an object with the following properties:
63
- - `cell` (`ReactNode`) content to display in the column head.
64
- - optional `props` (`ThProps`) to pass to the `<Th>` component, such as `width`, `sort`, and other table head cell properties.
65
-
66
- - `rows` defining the rows to be displayed in the table. Each item in the array can be either an array of `DataViewTd` (for simple rows) or an object with the following properties:
67
- - `row` (`DataViewTd[]`) defining the content for each cell in the row.
68
- - optional `id` (`string`) for the row (can be used to match items in selection).
69
- - optional `props` (`TrProps`) to pass to the `<Tr>` component, such as `isHoverable`, `isRowSelected`, and other table row properties.
70
-
71
- - optional `ouiaId`
72
-
73
- - optional `props` (`TableProps`) that are passed down to the `<Table>` component, except for `onSelect`, which is managed internally.
74
-
75
- It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component through `selection`.
76
-
77
- ### Tree table example
78
- This example shows the tree table variant with expandable rows, custom icons for leaf and parent nodes. Tree table is turned on by passing `isTreeTable` flag to the `DataViewTable` component. You can pass `collapsedIcon`, `expandedIcon` or `leafIcon` to be displayen rows with given status. The tree table rows have to be defined in a format of object with following keys:
79
- - `row` (`DataViewTd[]`) defining the content for each cell in the row.
80
- - `id` (`string`) for the row (used to match items in selection end expand the rows).
81
- - optional `children` (`DataViewTrTree[]`) defining the children rows.
82
-
83
- It is also possible to disable row selection using the `isSelectDisabled` function passed to the wrapping data view component through `selection`.
84
-
85
- ```js file="./DataViewTableTreeExample.tsx"
86
-
87
- ```
88
-
89
- ### Empty state example
90
- The data view table supports displaying a custom empty state. You can pass it using the the `headStates` and `bodyStates` properties and their `empty` key. It will be automatically displayed in case there are no rows to be rendered.
91
-
92
- ```js file="./DataViewTableEmptyExample.tsx"
93
-
94
- ```
95
-
96
- ### Error state example
97
- The data view table also supports displaying an error state. You can pass it using the the `headStates` and `bodyStates` properties and their `error` key. It will be displayed in case the data view recieves its `state` property set to `error`.
98
-
99
- ```js file="./DataViewTableErrorExample.tsx"
100
-
101
- ```
102
-
103
- ### Loading state example
104
- The data view table also supports displaying a custom loading state. You can pass it using the `headStates` and `bodyStates` properties and their `loading` key. Your state will be displayed in case the data view recieves its `state` property set to `loading`.
105
-
106
- ```js file="./DataViewTableLoadingExample.tsx"
107
-
108
- ```
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { Pagination } from '@patternfly/react-core';
3
- import { BulkSelect } from '@patternfly/react-component-groups';
4
- import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
5
-
6
-
7
- export const BasicExample: React.FunctionComponent = () => (
8
- <DataViewToolbar
9
- bulkSelect={
10
- <BulkSelect
11
- selectedCount={0}
12
- pageCount={5}
13
- onSelect={() => null}
14
- />
15
- }
16
- pagination={
17
- <Pagination page={1} perPage={10} />
18
- }
19
- />
20
- )
@@ -1,33 +0,0 @@
1
- ---
2
- # Sidenav top-level section
3
- # should be the same for all markdown files
4
- section: extensions
5
- subsection: Data view
6
- # Sidenav secondary level section
7
- # should be the same for all markdown files
8
- id: Events context
9
- # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
- source: react
11
- # If you use typescript, the name of the interface to display props for
12
- # These are found through the sourceProps function provided in patternfly-docs.source.js
13
- sortValue: 3
14
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/EventsContext/EventsContext.md
15
- ---
16
- import { useState, useEffect, useRef, useMemo } from 'react';
17
- import { Table, Tbody, Th, Thead, Tr, Td } from '@patternfly/react-table';
18
- import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
19
- import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
20
- import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext';
21
- import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
22
- import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core';
23
-
24
- The **data view events context** provides a way of listening to the data view events from the outside of the component.
25
-
26
- ### Row click subscription example
27
- The following example demonstrates how to use the `DataViewEventsContext` to manage shared state and handle events. The `DataViewEventsProvider` is used to wrap components that need access to the shared context. This example illustrates how to set up a layout that listens for data view row click events and displays detailed information about the selected row in a [drawer component](/components/drawer).
28
-
29
-
30
- ```js file="./EventsExample.tsx"
31
-
32
- ```
33
-
@@ -1,150 +0,0 @@
1
- ---
2
- # Sidenav top-level section
3
- # should be the same for all markdown files
4
- section: extensions
5
- subsection: Data view
6
- # Sidenav secondary level section
7
- # should be the same for all markdown files
8
- id: Functionality
9
- # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
- source: react
11
- # If you use typescript, the name of the interface to display props for
12
- # These are found through the sourceProps function provided in patternfly-docs.source.js
13
- sortValue: 3
14
- propComponents: ['DataViewFilters', 'DataViewTextFilter', 'DataViewCheckboxFilter']
15
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md
16
- ---
17
- import { useMemo } from 'react';
18
- import { BrowserRouter, useSearchParams } from 'react-router-dom';
19
- import { useDataViewPagination, useDataViewSelection, useDataViewFilters, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks';
20
- import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
21
- import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
22
- import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
23
- import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
24
- import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
25
- import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
26
- import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
27
-
28
- This is a list of functionality you can use to manage data displayed in the **data view**.
29
-
30
- # Pagination
31
- Allows to display data records on multiple pages and display the pagination state.
32
-
33
- ### Toolbar usage
34
- Data view toolbar can display a pagination using the `pagination` property accepting a React node. You can also pass a custom `ouiaId` for testing purposes.
35
-
36
- ### Pagination state
37
-
38
- The `useDataViewPagination` hook manages the pagination state of the data view.
39
-
40
- **Initial values:**
41
- - `perPage` initial value
42
- - optional `page` initial value
43
- - optional `searchParams` object
44
- - optional `setSearchParams` function
45
-
46
- While the hook works seamlessly with React Router library, you do not need to use it to take advantage of URL persistence. The `searchParams` and `setSearchParams` props can be managed using native browser APIs (`URLSearchParams` and `window.history.pushState`) or any other routing library of your choice. If you don't pass these two props, the pagination state will be stored internally without the URL usage.
47
-
48
- You can also pass custom `pageParam` or `perPageParam` names, renaming the pagination parameters in the URL.
49
-
50
- The retrieved values are named to match the PatternFly [pagination](/components/pagination) component props, so you can easily spread them to the component.
51
-
52
- **Return values:**
53
- - current `page` number
54
- - `onSetPage` to modify current page
55
- - items `perPage` value
56
- - `onPerPageSelect` to modify per page value
57
-
58
- ### Pagination example
59
- ```js file="./PaginationExample.tsx"
60
-
61
- ```
62
-
63
- # Selection
64
- Allows to select data records inside the data view and show the selection state.
65
-
66
- ### Toolbar usage
67
- Data view toolbar can display a bulk selection component using the `bulkSelect` property accepting a React node. You can make use of a predefined [bulk select](/extensions/component-groups/bulk-select) component from the [component groups](/extensions/component-groups/about-component-groups) extension.
68
-
69
- ### Selection state
70
-
71
- The `useDataViewSelection` hook manages the selection state of the data view.
72
-
73
- **Initial values:**
74
- - optional `initialSelected` array of record's identifiers selected by default
75
- - `matchOption` function to check if given record is selected
76
-
77
- *When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.*
78
-
79
- **Return values:**
80
- - `selected` array of currently selected records
81
- - `isSelected` function returning the selection state for given record
82
- - `onSelect` callback to modify the selection state and accepting `isSelecting` flag indicating if records are changing to selected or deselected and `items` containing affected records
83
-
84
- ### Selection example
85
-
86
- ```js file="./SelectionExample.tsx"
87
-
88
- ```
89
-
90
- # Filters
91
- Enables filtering of data records in the data view and displays the applied filter labels.
92
-
93
- ### Toolbar usage
94
- The data view toolbar can include a set of filters by passing a React node to the `filters` property. You can use predefined components `DataViewFilters`, `DataViewTextFilter` and `DataViewCheckboxFilter` to customize and handle filtering directly in the toolbar. The `DataViewFilters` is a wrapper allowing 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 at the bottom of this page.
95
-
96
- You can decide between passing `value` and `onChange` event to every filter separately or pass `values` and `onChange` to the `DataViewFilters` wrapper which make them available to its children. Props directly passed to child filters have a higher priority than the "inherited" ones.
97
-
98
- ### Filters state
99
-
100
- 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.
101
-
102
- **Initial values:**
103
- - `initialFilters` object with default filter values (if the filter param allows multiple values, pass an array)
104
- - optional `searchParams` object for managing URL-based filter state
105
- - optional `setSearchParams` function to update the URL when filters are modified
106
-
107
- The `useDataViewFilters` hook works well with the React Router library to support URL-based filtering. Alternatively, you can manage 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.
108
-
109
- **Return values:**
110
- - `filters` object representing the current filter values
111
- - `onSetFilters` function to update the filter state
112
- - `clearAllFilters` function to reset all filters to their initial values
113
-
114
- ### Filtering example
115
- 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.
116
-
117
- ```js file="./FiltersExample.tsx"
118
-
119
- ```
120
-
121
- ### Sort state
122
-
123
- The `useDataViewSort` hook manages the sorting state of a data view. It provides an easy way to handle sorting logic, including synchronization with URL parameters and defining default sorting behavior.
124
-
125
- **Initial values:**
126
- - `initialSort` object to set default `sortBy` and `direction` values:
127
- - `sortBy`: key of the initial column to sort.
128
- - `direction`: default sorting direction (`asc` or `desc`).
129
- - Optional `searchParams` object to manage URL-based synchronization of sort state.
130
- - Optional `setSearchParams` function to update the URL parameters when sorting changes.
131
- - `defaultDirection` to set the default direction when no direction is specified.
132
- - Customizable parameter names for the URL:
133
- - `sortByParam`: name of the URL parameter for the column key.
134
- - `directionParam`: name of the URL parameter for the sorting direction.
135
-
136
- The `useDataViewSort` hook integrates seamlessly with React Router to manage 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.
137
-
138
- **Return values:**
139
- - `sortBy`: key of the column currently being sorted.
140
- - `direction`: current sorting direction (`asc` or `desc`).
141
- - `onSort`: function to handle sorting changes programmatically or via user interaction.
142
-
143
- ### Sorting example
144
-
145
- This example demonstrates how to set up and use sorting functionality within a data view. The implementation includes dynamic sorting by column with persistence of sort state in the URL using React Router.
146
-
147
-
148
- ```js file="./SortingExample.tsx"
149
-
150
- ```
@@ -1,40 +0,0 @@
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: Layout
9
- # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
- source: react
11
- # If you use typescript, the name of the interface to display props for
12
- # These are found through the sourceProps function provided in patternfly-docs.source.js
13
- sortValue: 2
14
- propComponents: ['DataView', 'DataViewState']
15
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md
16
- ---
17
- import { useMemo } from 'react';
18
- import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
19
- import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
20
- import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
21
- import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
22
- import DataViewTable from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
23
-
24
- The **data view** component renders record data in a configured layout.
25
-
26
- ### Layout example
27
-
28
- Data view is expected to consist of header, data part and footer stacked below each other and passed as `children`.
29
-
30
- ```js file="./AbstractLayoutExample.tsx"
31
-
32
- ```
33
-
34
- ### Predefined layout components
35
-
36
- You can make use of the predefined layout components to display a default header and footer. See [data view toolbar](/extensions/data-view/components#dataviewtoolbar) for more information
37
-
38
- ```js file="./PredefinedLayoutExample.tsx"
39
-
40
- ```
@@ -1,89 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import { Pagination } from '@patternfly/react-core';
3
- import { useDataViewPagination, useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
4
- import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
5
- import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
6
- import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
7
- import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
8
-
9
- const perPageOptions = [
10
- { title: '5', value: 5 },
11
- { title: '10', value: 10 }
12
- ];
13
-
14
- interface Repository {
15
- name: string;
16
- branches: string | null;
17
- prs: string | null;
18
- workspaces: string;
19
- lastCommit: string;
20
- }
21
-
22
- const repositories: Repository[] = [
23
- { name: '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
- export const BasicExample: React.FunctionComponent = () => {
38
- const pagination = useDataViewPagination({ perPage: 5 });
39
- const { page, perPage } = pagination;
40
- const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
41
- const { selected, onSelect, isSelected } = selection;
42
-
43
- const pageRows = useMemo(() => rows.slice((page - 1) * perPage, ((page - 1) * perPage) + perPage), [ page, perPage ]);
44
-
45
- const handleBulkSelect = (value: BulkSelectValue) => {
46
- value === BulkSelectValue.none && onSelect(false);
47
- value === BulkSelectValue.all && onSelect(true, rows);
48
- value === BulkSelectValue.nonePage && onSelect(false, pageRows);
49
- value === BulkSelectValue.page && onSelect(true, pageRows);
50
- };
51
-
52
- return (
53
- <DataView selection={selection}>
54
- <DataViewToolbar
55
- ouiaId='LayoutExampleHeader'
56
- bulkSelect={
57
- <BulkSelect
58
- canSelectAll
59
- pageCount={pageRows.length}
60
- totalCount={repositories.length}
61
- selectedCount={selected.length}
62
- pageSelected={pageRows.every(item => isSelected(item))}
63
- pagePartiallySelected={pageRows.some(item => isSelected(item)) && !pageRows.every(item => isSelected(item))}
64
- onSelect={handleBulkSelect}
65
- />
66
- }
67
- pagination={
68
- <Pagination
69
- perPageOptions={perPageOptions}
70
- itemCount={repositories.length}
71
- {...pagination}
72
- />
73
- }
74
- />
75
- <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={pageRows} />
76
- <DataViewToolbar
77
- ouiaId='LayoutExampleFooter'
78
- pagination={
79
- <Pagination
80
- isCompact
81
- perPageOptions={perPageOptions}
82
- itemCount={repositories.length}
83
- {...pagination}
84
- />
85
- }
86
- />
87
- </DataView>
88
- );
89
- }