From d8ab22f5f5c2c0fc9001f8535eff549d5eaf95ff Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 29 Aug 2022 10:28:02 -0400 Subject: [PATCH 1/2] docs(Table): update pagination demo to match core --- packages/react-table/src/docs/demos/Table.md | 169 +----------------- .../table-demos/StaticBottomPagination.jsx | 139 ++++++++++++++ 2 files changed, 141 insertions(+), 167 deletions(-) create mode 100644 packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx diff --git a/packages/react-table/src/docs/demos/Table.md b/packages/react-table/src/docs/demos/Table.md index e5dbdba7ce1..43735b5a24a 100644 --- a/packages/react-table/src/docs/demos/Table.md +++ b/packages/react-table/src/docs/demos/Table.md @@ -2612,174 +2612,9 @@ class ComplexPaginationTableDemo extends React.Component { } ``` -### Pagination +### Static bottom pagination -```js -import React from 'react'; -import { - Checkbox, - Pagination, - Title, - Toolbar, - ToolbarContent, - ToolbarItem, - EmptyState, - EmptyStateIcon, - EmptyStateBody, - EmptyStateVariant, - Bullseye -} from '@patternfly/react-core'; -import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; -import globalDangerColor200 from '@patternfly/react-tokens/dist/esm/global_danger_color_200'; -import { Table, TableHeader, TableBody } from '@patternfly/react-table'; -import { Spinner } from '@patternfly/react-core'; - -class ComplexPaginationTableDemo extends React.Component { - constructor(props) { - super(props); - this.state = { - res: [], - perPage: 0, - total: 0, - page: 0, - error: null, - 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, total: 100 })) - .catch(err => this.setState({ error: err, loading: false, perPage: 0, page: 0, total: 0 })); - } - - componentDidMount() { - this.fetch(this.state.page || 1, this.state.perPage || 20); - } - - renderPagination(variant = 'top') { - const { page, perPage, total } = this.state; - return ( - this.fetch(value, perPage)} - onPerPageSelect={(_evt, value) => this.fetch(1, value)} - variant={variant} - titles={{ - paginationTitle: `Pagination demo ${variant} pagination` - }} - /> - ); - } - - render() { - const { loading, res, error, forceLoadingState } = this.state; - - const toolbarItems = ( - - - - - - {this.renderPagination()} - - - ); - - if (error) { - const noResultsRows = [ - { - heightAuto: true, - cells: [ - { - props: { colSpan: 8 }, - title: ( - - - - - Check your connection and reload the page. - - - There was an error retrieving data. Check your connection and try again. - - - - ) - } - ] - } - ]; - - return ( - - - - -
-
- ); - } - - const loadingRows = [ - { - heightAuto: true, - cells: [ - { - props: { colSpan: 8 }, - title: ( - -
- -
-
- ) - } - ] - } - ]; - - return ( - - {toolbarItems} - {!(loading || forceLoadingState) && ( - [post.title, post.body])} - aria-label="Pagination Table Demo" - > - - -
- )} - {(loading || forceLoadingState) && ( - - - -
- )} -
- ); - } -} +```js isFullscreen file="table-demos/StaticBottomPagination.jsx" ``` ### Sticky header diff --git a/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx new file mode 100644 index 00000000000..ce18d113bcc --- /dev/null +++ b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx @@ -0,0 +1,139 @@ +import React from 'react'; +import { + Button, + Card, + Toolbar, + ToolbarContent, + ToolbarGroup, + ToolbarItem, + Pagination, + Select, + SelectVariant, + SelectOption, + PageSection +} from '@patternfly/react-core'; +import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; +import { rows, columns } from '../../examples/Data.jsx'; + +import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon'; +import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper'; + +export const StaticBottomPagination = () => { + const [isSelectOpen, setIsSelectOpen] = React.useState(false); + const [page, setPage] = React.useState(1); + const [perPage, setPerPage] = React.useState(10); + const [paginatedRows, setPaginatedRows] = React.useState(rows.slice(0, 10)); + const handleSetPage = (_evt, newPage, perPage, startIdx, endIdx) => { + setPaginatedRows(rows.slice(startIdx, endIdx)); + setPage(newPage); + }; + handlePerPageSelect = (_evt, newPerPage, newPage, startIdx, endIdx) => { + setPaginatedRows(rows.slice(startIdx, endIdx)); + setPage(newPage); + setPerPage(newPerPage); + }; + + + const renderPagination = (variant, isCompact) => ( + + ); + + const renderLabel = labelText => { + switch (labelText) { + case 'Running': + return ; + case 'Stopped': + return ; + case 'Needs Maintenance': + return ; + case 'Down': + return ; + } + }; + + const tableToolbar = ( + + + + + + + + + + + {renderPagination('top', true)} + + + ); + + return ( + + + + + {tableToolbar} + + + + {columns.map((column, columnIndex) => ( + {column} + ))} + + + + {paginatedRows.map((row, rowIndex) => ( + + {row.name} + {row.threads} + {row.applications} + {row.workspaces} + {renderLabel(row.status)} + {row.location} + {row.lastModified} + + + {row.url} + + + + ))} + + + {renderPagination('bottom', false)} + + + + + ); +}; From 05b83565d4de18a739858550923822a4c9f2059c Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Tue, 6 Sep 2022 11:31:38 -0400 Subject: [PATCH 2/2] wrap labels, add static modifier, update name --- packages/react-table/src/docs/demos/Table.md | 2 +- .../demos/table-demos/StaticBottomPagination.jsx | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/react-table/src/docs/demos/Table.md b/packages/react-table/src/docs/demos/Table.md index 43735b5a24a..fd0d3918b17 100644 --- a/packages/react-table/src/docs/demos/Table.md +++ b/packages/react-table/src/docs/demos/Table.md @@ -2612,7 +2612,7 @@ class ComplexPaginationTableDemo extends React.Component { } ``` -### Static bottom pagination +### Static bottom pagination on mobile ```js isFullscreen file="table-demos/StaticBottomPagination.jsx" ``` diff --git a/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx index ce18d113bcc..40e8c3e2864 100644 --- a/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx +++ b/packages/react-table/src/docs/demos/table-demos/StaticBottomPagination.jsx @@ -10,7 +10,8 @@ import { Select, SelectVariant, SelectOption, - PageSection + PageSection, + Label } from '@patternfly/react-core'; import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; import { rows, columns } from '../../examples/Data.jsx'; @@ -46,24 +47,25 @@ export const StaticBottomPagination = () => { titles={{ paginationTitle: `${variant} pagination` }} + isStatic /> ); const renderLabel = labelText => { switch (labelText) { case 'Running': - return ; + return ; case 'Stopped': - return ; + return ; case 'Needs Maintenance': - return ; + return ; case 'Down': - return ; + return ; } }; const tableToolbar = ( - +