FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(PaginationTableDemo): add Spinner and empty state to demo by nicolethoen · Pull Request #3294 · patternfly/patternfly-react · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
129 changes: 115 additions & 14 deletions packages/patternfly-4/react-core/src/demos/PaginationTable.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,85 @@
title: 'Pagination table'
section: 'demos'
---
import { Pagination, PaginationVariant, Title } from '@patternfly/react-core';
import { Table, TableHeader, TableBody} from '@patternfly/react-table';

## Examples
```
Note: This demo uses the experimental Spinner component while data is loading.
```
import {
Pagination,
PaginationVariant,
Title,
EmptyState,
EmptyStateIcon,
EmptyStateBody,
EmptyStateSecondaryActions,
Bullseye
} from '@patternfly/react-core';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import { global_danger_color_200 as globalDangerColor200 } from '@patternfly/react-tokens';
import { Table, TableHeader, TableBody} from '@patternfly/react-table';
import { Spinner } from '@patternfly/react-core/dist/esm/experimental';

```js title=Basic
import React from 'react';
import { Pagination, PaginationVariant, Title } from '@patternfly/react-core';
import {
Pagination,
PaginationVariant,
Title,
EmptyState,
EmptyStateIcon,
EmptyStateBody,
EmptyStateSecondaryActions,
Bullseye,
Radio
} from '@patternfly/react-core';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import { global_breakpoint_lg as globalBreakpointLg } from '@patternfly/react-tokens';
import { Table, TableHeader, TableBody} from '@patternfly/react-table';
import { Spinner } from '@patternfly/react-core/dist/esm/experimental';

class ComplexPaginationTableDemo extends React.Component {
constructor(props) {
this.state = {
res: [],
perPage: 20,
total: 100,
page: 1,
perPage: 0,
total: 0,
page: 0,
error: null,
loading: true
loading: true,
forceLoadingState: false,
};

this.handleCheckboxChange = (checked) => {
console.log(checked);
this.setState({ forceLoadingState: checked });
}
}

fetch(page, perPage) {
this.setState({ loading: true });
fetch(`https://jsonplaceholder.typicode.com/posts?_page=${page}&_limit=${perPage}`)
.then(resp => resp.json())
.then(resp => this.setState({ res: resp, perPage, page, loading: false }))
.catch(err => this.setState({ error: err, loading: false }));
.then(resp => this.setState({ res: resp, perPage, page, loading: false, total: 100 }))
.catch(err => this.setState({ error: err, loading: false, perPage: 0, page: 0, total: 0 }));
}

componentDidMount() {
this.fetch(this.state.page, this.state.perPage);
this.fetch(this.state.page || 1, this.state.perPage || 20);
}

renderLoadingStateCheckbox() {
return (
<Checkbox
label="View loading state"
isChecked={this.state.forceLoadingState}
onChange={this.handleCheckboxChange}
aria-label="view loading state checkbox"
id="check"
name="check"
/>
)
}

renderPagination(variant = 'top') {
Expand All @@ -50,17 +98,70 @@ class ComplexPaginationTableDemo extends React.Component {
}

render() {
const { loading } = this.state;
const { loading, res, error, forceLoadingState } = this.state;
if (error) {
const noResultsRows = [{
heightAuto: true,
cells: [
{
props: { colSpan: 8 },
title: (
<Bullseye>
<EmptyState variant={EmptyStateVariant.small}>
<EmptyStateIcon icon={ExclamationCircleIcon} color={globalDangerColor200.value} />
<Title headingLevel="h2" size="lg">
Unable to connect
</Title>
<EmptyStateBody>
There was an error retrieving data. Check your connection and try again.
</EmptyStateBody>
</EmptyState>
</Bullseye>
)
},
]
}]

return (
<React.Fragment>
<Table cells={['Title', 'Body']} rows={noResultsRows} aria-label="Pagination Table Demo">
<TableHeader />
<TableBody />
</Table>
</React.Fragment>
);
}

const loadingRows = [{
heightAuto: true,
cells: [
{
props: { colSpan: 8 },
title: (
<Bullseye>
<center><Spinner size="xl"/></center>
</Bullseye>
)
},
]
}];

return (
<React.Fragment>
{this.renderLoadingStateCheckbox()}
{this.renderPagination()}
{!loading && (
<Table cells={['Title', 'Body']} rows={this.state.res.map(post => [post.title, post.body])}>
{!(loading || forceLoadingState) && (
<Table cells={['Title', 'Body']} rows={res.map(post => [post.title, post.body])} aria-label="Pagination Table Demo">
<TableHeader />
<TableBody />
</Table>
)}
{(loading || forceLoadingState) && (
<Table cells={['Title', 'Body']} rows={loadingRows} aria-label="Pagination Table Demo">
<TableHeader />
<TableBody />
</Table>
)}
{loading && <center><Title size="3xl">Please wait while loading data</Title></center>}
</React.Fragment>
);
}
Expand Down

Back | FazBrowse Home | New Git URL