From 7a865412efad5a46bb25d36dbed209716b48db09 Mon Sep 17 00:00:00 2001 From: Jessie Date: Mon, 5 Aug 2019 10:27:16 -0400 Subject: [PATCH 1/4] Fix pagination to update page count --- .../react-core/src/components/Pagination/Navigation.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx index 2322c5e647c..409b05b0d5d 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx @@ -93,6 +93,13 @@ export class Navigation extends React.Component Date: Mon, 5 Aug 2019 10:30:43 -0400 Subject: [PATCH 2/4] Remove comment --- .../react-core/src/components/Pagination/Navigation.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx index 409b05b0d5d..71e666f0a50 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx @@ -94,7 +94,6 @@ export class Navigation extends React.Component Date: Mon, 5 Aug 2019 14:25:13 -0400 Subject: [PATCH 3/4] Fix issues with input and page selection --- .../src/components/Pagination/Navigation.tsx | 8 ++++---- .../src/components/Pagination/Pagination.tsx | 9 +++++++++ .../Pagination/__snapshots__/Pagination.test.js.snap | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx index 71e666f0a50..f768eac2099 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Navigation.tsx @@ -29,7 +29,7 @@ export interface NavigationProps extends React.HTMLProps { paginationTitle?: string; /** The number of the current page */ page: React.ReactText; - /** Function called when user sets page */ + /** Function called when page is changed */ onSetPage: (event: React.SyntheticEvent, page: number) => void; /** Function called when user clicks to navigate to next page */ onNextClick?: (event: React.SyntheticEvent, page: number) => void; @@ -93,8 +93,8 @@ export class Navigation extends React.Component this.onKeyDown(event, page, lastPage, onPageInput, onSetPage)} diff --git a/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx b/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx index 6d324517681..8c8e83cc5f7 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx +++ b/packages/patternfly-4/react-core/src/components/Pagination/Pagination.tsx @@ -64,6 +64,8 @@ export interface PaginationProps extends React.HTMLProps { perPage?: number; /** Select from options to number of items per page. */ perPageOptions?: PerPageOptions[]; + /** Page we start at. */ + firstPage?: number; /** Current page number. */ page?: number; /** First index of items on current page. */ @@ -112,6 +114,7 @@ export const Pagination: React.FunctionComponent = ({ currPage: 'Current page', paginationTitle: 'Pagination' }, + firstPage = 1, page = 1, itemCount, itemsStart = null, @@ -130,6 +133,12 @@ export const Pagination: React.FunctionComponent = ({ ...props }: PaginationProps) => { const lastPage = Math.ceil(itemCount / perPage); + if (page < firstPage) { + page = firstPage; + } else if (page > lastPage) { + page = lastPage; + } + const firstIndex = itemCount <= 0 ? 0 : (page - 1) * perPage + 1; let lastIndex; if (itemCount <= 0) { diff --git a/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap b/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap index 4a50bc2bb20..1c759690874 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap @@ -9,6 +9,7 @@ exports[`component render custom pagination toggle 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -711,6 +712,7 @@ exports[`component render custom perPageOptions 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -1348,6 +1350,7 @@ exports[`component render custom start end 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -2094,6 +2097,7 @@ exports[`component render empty per page options 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -2452,6 +2456,7 @@ exports[`component render last page 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 2 < 2
@@ -3198,6 +3203,7 @@ exports[`component render limited number of pages 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 1
@@ -3943,6 +3949,7 @@ exports[`component render no items 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 0 < 0
@@ -4692,6 +4699,7 @@ exports[`component render should render correctly bottom 1`] = ` className="pf-c-pagination pf-m-footer" id="pagination-options-menu" > + 1 < 1 < 2 + 1 < 1 < 2
@@ -6183,6 +6192,7 @@ exports[`component render titles 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -6929,6 +6939,7 @@ exports[`component render up drop direction 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 1 < 4
@@ -7674,6 +7685,7 @@ exports[`component render zero results 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > + 1 < 0 < 0
From 8765a3783bd3c91d28c3633c9984daa8af08e9d1 Mon Sep 17 00:00:00 2001 From: Jessie Date: Mon, 5 Aug 2019 14:36:31 -0400 Subject: [PATCH 4/4] Update snapshots --- .../Pagination/__snapshots__/Pagination.test.js.snap | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap b/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap index 1c759690874..4a50bc2bb20 100644 --- a/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/Pagination/__snapshots__/Pagination.test.js.snap @@ -9,7 +9,6 @@ exports[`component render custom pagination toggle 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -712,7 +711,6 @@ exports[`component render custom perPageOptions 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -1350,7 +1348,6 @@ exports[`component render custom start end 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -2097,7 +2094,6 @@ exports[`component render empty per page options 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -2456,7 +2452,6 @@ exports[`component render last page 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 2 < 2
@@ -3203,7 +3198,6 @@ exports[`component render limited number of pages 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 1
@@ -3949,7 +3943,6 @@ exports[`component render no items 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 0 < 0
@@ -4699,7 +4692,6 @@ exports[`component render should render correctly bottom 1`] = ` className="pf-c-pagination pf-m-footer" id="pagination-options-menu" > - 1 < 1 < 2 - 1 < 1 < 2
@@ -6192,7 +6183,6 @@ exports[`component render titles 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -6939,7 +6929,6 @@ exports[`component render up drop direction 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 1 < 4
@@ -7685,7 +7674,6 @@ exports[`component render zero results 1`] = ` className="pf-c-pagination" id="pagination-options-menu" > - 1 < 0 < 0