Skip to content

Commit 5655881

Browse files
committed
feat(states): Enhance docs
1 parent 9646a11 commit 5655881

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/mod
1616
---
1717
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateIcon } from '@patternfly/react-core';
1818
import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
19-
import { BulkSelect } from '@patternfly/react-component-groups';
19+
import { BulkSelect, ErrorState } from '@patternfly/react-component-groups';
2020
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
2121
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2222
import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
23-
import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
23+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
2424

2525
## Data view toolbar
2626

@@ -74,8 +74,15 @@ It is also possible to disable row selection using the `isSelectDisabled` functi
7474
```
7575

7676
### Empty state example
77-
The data view table also supports displaying a custom empty state. You can pass it using the `emptyState` property and it will be displayed in case there are no rows to be rendered.
77+
The data view table supports displaying a custom empty state. You can pass it using the `states` property and `empty` key. It will be automatically displayed in case there are no rows to be rendered.
7878

7979
```js file="./DataViewTableEmptyExample.tsx"
8080

8181
```
82+
83+
### Error state example
84+
The data view table also supports displaying an error state. You can pass it using the `states` property and `error` key. It will be displayed in case the data view recieves its `state` property set to `error`.
85+
86+
```js file="./DataViewTableErrorExample.tsx"
87+
88+
```

packages/module/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableEmptyExample.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
23
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
34
import { CubesIcon } from '@patternfly/react-icons';
45
import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter, EmptyStateHeader, EmptyStateIcon } from '@patternfly/react-core';
@@ -21,7 +22,7 @@ const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Wo
2122

2223
const ouiaId = 'TableExample';
2324

24-
const emptyState = (
25+
const empty = (
2526
<EmptyState>
2627
<EmptyStateHeader titleText="No data found" headingLevel="h4" icon={<EmptyStateIcon icon={CubesIcon} />} />
2728
<EmptyStateBody>There are no matching data to be displayed.</EmptyStateBody>
@@ -38,11 +39,13 @@ const emptyState = (
3839
);
3940

4041
export const BasicExample: React.FunctionComponent = () => (
41-
<DataViewTable
42-
aria-label='Repositories table'
43-
ouiaId={ouiaId}
44-
columns={columns}
45-
rows={rows}
46-
emptyState={emptyState}
47-
/>
42+
<DataView activeState={DataViewState.empty}>
43+
<DataViewTable
44+
aria-label='Repositories table'
45+
ouiaId={ouiaId}
46+
columns={columns}
47+
rows={rows}
48+
states={{ empty }}
49+
/>
50+
</DataView>
4851
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynamic/DataView';
3+
import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
4+
import { ErrorState } from '@patternfly/react-component-groups';
5+
6+
interface Repository {
7+
id: number;
8+
name: string;
9+
branches: string | null;
10+
prs: string | null;
11+
workspaces: string;
12+
lastCommit: string;
13+
}
14+
15+
const repositories: Repository[] = [];
16+
17+
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
18+
const rows: DataViewTr[] = repositories.map((repository) => Object.values(repository));
19+
20+
const columns: DataViewTh[] = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
21+
22+
const ouiaId = 'TableErrorExample';
23+
24+
const error = (
25+
<ErrorState errorTitle='Unable to load data' errorDescription='There was an error retrieving data. Check your connection and reload the page.' />
26+
);
27+
28+
export const BasicExample: React.FunctionComponent = () => (
29+
<DataView activeState={DataViewState.error}>
30+
<DataViewTable
31+
aria-label='Repositories table'
32+
ouiaId={ouiaId}
33+
columns={columns}
34+
rows={rows}
35+
states={{ error }}
36+
/>
37+
</DataView>
38+
);

packages/module/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ source: react
1111
# If you use typescript, the name of the interface to display props for
1212
# These are found through the sourceProps function provided in patternfly-docs.source.js
1313
sortValue: 2
14-
propComponents: ['DataView']
14+
propComponents: ['DataView', 'DataViewState']
1515
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md
1616
---
1717
import { useMemo } from 'react';

0 commit comments

Comments
 (0)