From dbc065593ffa9c0d14195c98330438cc1cc6f873 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Thu, 5 Dec 2019 11:11:17 -0800 Subject: [PATCH 1/9] hiding pagination when needed --- src-docs/src/views/tables/data_store.js | 2 +- src-docs/src/views/tables/paginated/paginated.js | 4 +++- src/components/basic_table/basic_table.js | 14 +++++++++++--- src/components/basic_table/pagination_bar.js | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src-docs/src/views/tables/data_store.js b/src-docs/src/views/tables/data_store.js index ece0bdf5f7f..20f4bd30c06 100644 --- a/src-docs/src/views/tables/data_store.js +++ b/src-docs/src/views/tables/data_store.js @@ -73,7 +73,7 @@ const github = [ const dob = new Date(1980, 1, 1); const createUsers = countries => { - return times(20, index => { + return times(4, index => { return { id: index, firstName: index < 10 ? firstNames[index] : firstNames[index - 10], diff --git a/src-docs/src/views/tables/paginated/paginated.js b/src-docs/src/views/tables/paginated/paginated.js index d658a6c3714..63e4702554e 100644 --- a/src-docs/src/views/tables/paginated/paginated.js +++ b/src-docs/src/views/tables/paginated/paginated.js @@ -43,7 +43,7 @@ export class Table extends Component { this.state = { pageIndex: 0, - pageSize: 5, + pageSize: 3, showPerPageOptions: true, }; } @@ -74,6 +74,8 @@ export class Table extends Component { pageSize ); + console.log(store.findUsers(pageIndex, pageSize), 'hi'); + const columns = [ { field: 'firstName', diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index 532d0f2566d..af4bf9e5b08 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -384,7 +384,7 @@ export class EuiBasicTable extends Component { ); const table = this.renderTable(); - const paginationBar = this.renderPaginationBar(); + const paginationBar = this.renderPaginationBar(items); return (
@@ -1049,9 +1049,17 @@ export class EuiBasicTable extends Component { return profile.align; } - renderPaginationBar() { + renderPaginationBar(items) { const { error, pagination, onChange } = this.props; - if (!error && pagination) { + if (pagination) { + console.log(pagination.totalItemCount, 'jex'); + } + if ( + !error && + pagination && + items.length > 0 && + pagination.totalItemCount > Math.min(...pagination.pageSizeOptions) + ) { if (!onChange) { throw new Error(`The Basic Table is configured with pagination but [onChange] is not configured. This callback must be implemented to handle pagination changes`); diff --git a/src/components/basic_table/pagination_bar.js b/src/components/basic_table/pagination_bar.js index 321acc99894..14ce50b2fa2 100644 --- a/src/components/basic_table/pagination_bar.js +++ b/src/components/basic_table/pagination_bar.js @@ -23,6 +23,7 @@ export const PaginationBar = ({ ? pagination.pageSizeOptions : defaults.pageSizeOptions; const pageCount = Math.ceil(pagination.totalItemCount / pagination.pageSize); + return (
From b55ef3f8f2c1dc7bc3c4f1dd13fb6045376ddefa Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Thu, 5 Dec 2019 18:13:43 -0800 Subject: [PATCH 2/9] hiding pagination when there are not enough rows --- src-docs/src/views/tables/data_store.js | 2 +- .../src/views/tables/paginated/paginated.js | 4 +- .../__snapshots__/pagination_bar.test.js.snap | 43 ------------------- src/components/basic_table/basic_table.js | 10 +---- src/components/basic_table/pagination_bar.js | 14 ++++-- 5 files changed, 13 insertions(+), 60 deletions(-) diff --git a/src-docs/src/views/tables/data_store.js b/src-docs/src/views/tables/data_store.js index 20f4bd30c06..ece0bdf5f7f 100644 --- a/src-docs/src/views/tables/data_store.js +++ b/src-docs/src/views/tables/data_store.js @@ -73,7 +73,7 @@ const github = [ const dob = new Date(1980, 1, 1); const createUsers = countries => { - return times(4, index => { + return times(20, index => { return { id: index, firstName: index < 10 ? firstNames[index] : firstNames[index - 10], diff --git a/src-docs/src/views/tables/paginated/paginated.js b/src-docs/src/views/tables/paginated/paginated.js index 63e4702554e..d658a6c3714 100644 --- a/src-docs/src/views/tables/paginated/paginated.js +++ b/src-docs/src/views/tables/paginated/paginated.js @@ -43,7 +43,7 @@ export class Table extends Component { this.state = { pageIndex: 0, - pageSize: 3, + pageSize: 5, showPerPageOptions: true, }; } @@ -74,8 +74,6 @@ export class Table extends Component { pageSize ); - console.log(store.findUsers(pageIndex, pageSize), 'hi'); - const columns = [ { field: 'firstName', diff --git a/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap b/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap index 5e0c5eb64e9..1a627362652 100644 --- a/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap +++ b/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap @@ -5,20 +5,6 @@ exports[`PaginationBar render - custom page size options 1`] = ` -
`; @@ -27,21 +13,6 @@ exports[`PaginationBar render - hiding per page options 1`] = ` -
`; @@ -50,19 +21,5 @@ exports[`PaginationBar render 1`] = ` - `; diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index af4bf9e5b08..0d1f047a858 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -1051,15 +1051,7 @@ export class EuiBasicTable extends Component { renderPaginationBar(items) { const { error, pagination, onChange } = this.props; - if (pagination) { - console.log(pagination.totalItemCount, 'jex'); - } - if ( - !error && - pagination && - items.length > 0 && - pagination.totalItemCount > Math.min(...pagination.pageSizeOptions) - ) { + if (!error && pagination && items.length > 0) { if (!onChange) { throw new Error(`The Basic Table is configured with pagination but [onChange] is not configured. This callback must be implemented to handle pagination changes`); diff --git a/src/components/basic_table/pagination_bar.js b/src/components/basic_table/pagination_bar.js index 14ce50b2fa2..fce93fdee6e 100644 --- a/src/components/basic_table/pagination_bar.js +++ b/src/components/basic_table/pagination_bar.js @@ -23,10 +23,9 @@ export const PaginationBar = ({ ? pagination.pageSizeOptions : defaults.pageSizeOptions; const pageCount = Math.ceil(pagination.totalItemCount / pagination.pageSize); - - return ( -
- + let paginationElement; + if (pagination.totalItemCount > Math.min(...pageSizeOptions)) { + paginationElement = ( + ); + } + + return ( +
+ + {paginationElement}
); }; From 243a566c263cbf7473e64763ab14c090414fffd3 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Thu, 5 Dec 2019 19:58:00 -0800 Subject: [PATCH 3/9] cl --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a8e76f134..a4b042bb320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Updated React peerDependencies to version 16.12 ([#2571](https://github.com/elastic/eui/pull/2571)) - Changed to generated `id` value for `EuiFormRow` to ensure uniqueness ([#2588](https://github.com/elastic/eui/pull/2588)) +**Bug fixes** + +- Fixed pagination in `EuiBasicTable` to display it only when there is enough rows of data ([#2598](https://github.com/elastic/eui/pull/#2598)) + ## [`16.2.1`](https://github.com/elastic/eui/tree/v16.2.1) **Bug fixes** From 2bbd44dc35b19adebc6af34cc9eb9d1c3292a769 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Fri, 6 Dec 2019 12:01:02 -0800 Subject: [PATCH 4/9] show EuiPagination when there is 1 page --- CHANGELOG.md | 2 +- .../__snapshots__/pagination_bar.test.js.snap | 43 ++++++++++++++ src/components/basic_table/pagination_bar.js | 14 ++--- .../__snapshots__/pagination.test.tsx.snap | 58 ++++++++++++++++++- src/components/pagination/pagination.tsx | 2 +- 5 files changed, 106 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b042bb320..183f4681b62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ **Bug fixes** -- Fixed pagination in `EuiBasicTable` to display it only when there is enough rows of data ([#2598](https://github.com/elastic/eui/pull/#2598)) +- Hide `paginationBar` in `EuiBasicTable` when there is no data ([#2598](https://github.com/elastic/eui/pull/#2598)) ## [`16.2.1`](https://github.com/elastic/eui/tree/v16.2.1) diff --git a/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap b/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap index 1a627362652..5e0c5eb64e9 100644 --- a/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap +++ b/src/components/basic_table/__snapshots__/pagination_bar.test.js.snap @@ -5,6 +5,20 @@ exports[`PaginationBar render - custom page size options 1`] = ` +
`; @@ -13,6 +27,21 @@ exports[`PaginationBar render - hiding per page options 1`] = ` + `; @@ -21,5 +50,19 @@ exports[`PaginationBar render 1`] = ` + `; diff --git a/src/components/basic_table/pagination_bar.js b/src/components/basic_table/pagination_bar.js index fce93fdee6e..14ce50b2fa2 100644 --- a/src/components/basic_table/pagination_bar.js +++ b/src/components/basic_table/pagination_bar.js @@ -23,9 +23,10 @@ export const PaginationBar = ({ ? pagination.pageSizeOptions : defaults.pageSizeOptions; const pageCount = Math.ceil(pagination.totalItemCount / pagination.pageSize); - let paginationElement; - if (pagination.totalItemCount > Math.min(...pageSizeOptions)) { - paginationElement = ( + + return ( +
+ - ); - } - - return ( -
- - {paginationElement}
); }; diff --git a/src/components/pagination/__snapshots__/pagination.test.tsx.snap b/src/components/pagination/__snapshots__/pagination.test.tsx.snap index 284ef9963a2..44652ea6603 100644 --- a/src/components/pagination/__snapshots__/pagination.test.tsx.snap +++ b/src/components/pagination/__snapshots__/pagination.test.tsx.snap @@ -1,3 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EuiPagination is rendered 1`] = ``; +exports[`EuiPagination is rendered 1`] = ` +
+ + + +
+`; diff --git a/src/components/pagination/pagination.tsx b/src/components/pagination/pagination.tsx index 0e0517d4573..5eadfff33ff 100644 --- a/src/components/pagination/pagination.tsx +++ b/src/components/pagination/pagination.tsx @@ -173,7 +173,7 @@ export const EuiPagination: FunctionComponent = ({ ); - if (pages.length > 1) { + if (pages.length > 0) { const selectablePages = pages; if (compressed) { return ( From 664bf2b0449fe10050ca6deef6a539e1bb6a984a Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Fri, 6 Dec 2019 12:03:22 -0800 Subject: [PATCH 5/9] update cl --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b81593828..20f6bb15309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ **Bug fixes** - Fixed UX/focus bug in `EuiDataGrid` when using keyboard shortcuts to paginate ([#2602](https://github.com/elastic/eui/pull/2602)) +- Hide `paginationBar` in `EuiBasicTable` when there is no data ([#2598](https://github.com/elastic/eui/pull/#2598)) +- Display `EuiPagination` in `EuiBasicTable` when there is only 1 page ([#2598](https://github.com/elastic/eui/pull/#2598)) ## [`17.0.0`](https://github.com/elastic/eui/tree/v17.0.0) @@ -13,10 +15,6 @@ - Updated React peerDependencies to version 16.12 ([#2571](https://github.com/elastic/eui/pull/2571)) - Changed to generated `id` value for `EuiFormRow` to ensure uniqueness ([#2588](https://github.com/elastic/eui/pull/2588)) -**Bug fixes** - -- Hide `paginationBar` in `EuiBasicTable` when there is no data ([#2598](https://github.com/elastic/eui/pull/#2598)) - ## [`16.2.1`](https://github.com/elastic/eui/tree/v16.2.1) **Bug fixes** From d63690fa3ee88bbe13e2cfe9cbe1d226f80013e9 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Fri, 6 Dec 2019 12:05:26 -0800 Subject: [PATCH 6/9] extra line --- src/components/basic_table/pagination_bar.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/basic_table/pagination_bar.js b/src/components/basic_table/pagination_bar.js index 14ce50b2fa2..321acc99894 100644 --- a/src/components/basic_table/pagination_bar.js +++ b/src/components/basic_table/pagination_bar.js @@ -23,7 +23,6 @@ export const PaginationBar = ({ ? pagination.pageSizeOptions : defaults.pageSizeOptions; const pageCount = Math.ceil(pagination.totalItemCount / pagination.pageSize); - return (
From d98a56f4b0a7f1485524fa8baac7b28d20d483f9 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Sun, 8 Dec 2019 16:15:35 -0800 Subject: [PATCH 7/9] cleanup --- CHANGELOG.md | 3 +-- src/components/basic_table/basic_table.js | 6 ++--- src/components/pagination/pagination.tsx | 29 ++++++++++------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f6bb15309..ebf810b5676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ **Bug fixes** - Fixed UX/focus bug in `EuiDataGrid` when using keyboard shortcuts to paginate ([#2602](https://github.com/elastic/eui/pull/2602)) -- Hide `paginationBar` in `EuiBasicTable` when there is no data ([#2598](https://github.com/elastic/eui/pull/#2598)) -- Display `EuiPagination` in `EuiBasicTable` when there is only 1 page ([#2598](https://github.com/elastic/eui/pull/#2598)) +- Improved pagination in `EuiBasicTable`. `paginationBar` is hidden when there is no data and `EuiPagination` is displayed even when there is only one page ([#2598](https://github.com/elastic/eui/pull/#2598)) ## [`17.0.0`](https://github.com/elastic/eui/tree/v17.0.0) diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index 0d1f047a858..7cc6de0c0d8 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -384,7 +384,7 @@ export class EuiBasicTable extends Component { ); const table = this.renderTable(); - const paginationBar = this.renderPaginationBar(items); + const paginationBar = this.renderPaginationBar(items.length); return (
@@ -1049,9 +1049,9 @@ export class EuiBasicTable extends Component { return profile.align; } - renderPaginationBar(items) { + renderPaginationBar(itemsLength) { const { error, pagination, onChange } = this.props; - if (!error && pagination && items.length > 0) { + if (!error && pagination && itemsLength > 0) { if (!onChange) { throw new Error(`The Basic Table is configured with pagination but [onChange] is not configured. This callback must be implemented to handle pagination changes`); diff --git a/src/components/pagination/pagination.tsx b/src/components/pagination/pagination.tsx index 5eadfff33ff..c4ae11a58c0 100644 --- a/src/components/pagination/pagination.tsx +++ b/src/components/pagination/pagination.tsx @@ -173,28 +173,23 @@ export const EuiPagination: FunctionComponent = ({ ); - if (pages.length > 0) { - const selectablePages = pages; - if (compressed) { - return ( -
- {previousButton} - {nextButton} -
- ); - } - + const selectablePages = pages; + if (compressed) { return ( -
+
{previousButton} - {firstPageButtons} - {selectablePages} - {lastPageButtons} {nextButton}
); } - // Don't render pagination if it isn't needed. Then span is here for a docs bug. - return ; + return ( +
+ {previousButton} + {firstPageButtons} + {selectablePages} + {lastPageButtons} + {nextButton} +
+ ); }; From 60286e2cd58a5572e7b4ff4d1969b24fcf5c60c7 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Mon, 9 Dec 2019 09:50:04 -0800 Subject: [PATCH 8/9] fix ts error --- src/components/basic_table/basic_table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/basic_table/basic_table.tsx b/src/components/basic_table/basic_table.tsx index 1628771c5e2..d21a0243a12 100644 --- a/src/components/basic_table/basic_table.tsx +++ b/src/components/basic_table/basic_table.tsx @@ -1092,7 +1092,7 @@ export class EuiBasicTable extends Component< return profile.align; } - renderPaginationBar(itemsLength) { + renderPaginationBar(itemsLength: number) { const { error, pagination, onChange } = this.props; if (!error && pagination && itemsLength > 0) { if (!onChange) { From 3d195a2ddca55cebd3f9ce5ca36d8e4f7a2bbf19 Mon Sep 17 00:00:00 2001 From: Andrea Del Rio Date: Mon, 9 Dec 2019 12:47:37 -0800 Subject: [PATCH 9/9] updated snaps --- .../pagination/__snapshots__/pagination.test.tsx.snap | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/pagination/__snapshots__/pagination.test.tsx.snap b/src/components/pagination/__snapshots__/pagination.test.tsx.snap index 44652ea6603..7bf338a5fcd 100644 --- a/src/components/pagination/__snapshots__/pagination.test.tsx.snap +++ b/src/components/pagination/__snapshots__/pagination.test.tsx.snap @@ -15,9 +15,11 @@ exports[`EuiPagination is rendered 1`] = ` >