From 1341f64863af8aca86bc6f3581a939711e071f7a Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:04:02 -0300 Subject: [PATCH 01/19] feat(b-pagination): if number of pages changes, try and keep current page active --- src/components/pagination/pagination.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 08688e2cb24..7eefd90e7cf 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -52,13 +52,17 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ } }, watch: { - numberOfPages(newVal) { - if (newVal === this.localNumberOfPages) { + numberOfPages(newNumberOfPages) { + if (newNumberOfPages === this.localNumberOfPages) { /* istanbul ignore next */ return } - this.localNumberOfPages = newVal - this.currentPage = 1 + this.localNumberOfPages = newNumberOfPages + if (this.currentPage > newNumberOfPages) { + // Try an keep the current page number if possible + // Otherwise set it to the first page + this.currentPage = 1 + } } }, created() { From 52db00e5da89136fa13dbf10fa3494185a67a2f3 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:16:18 -0300 Subject: [PATCH 02/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 36 ++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index 48aa7bcdd1a..0a3bc14ac9b 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -679,7 +679,7 @@ describe('pagination', () => { wrapper.destroy() }) - it('changing the pagesize resets to page 1', async () => { + it('changing the number of pages to less than current page number resets to page 1', async () => { // https://github.com/bootstrap-vue/bootstrap-vue/issues/2987 const wrapper = mount(BPagination, { propsData: { @@ -695,13 +695,30 @@ describe('pagination', () => { expect(wrapper.emitted('input')).not.toBeDefined() wrapper.setProps({ - perPage: 3 + totalRows: 20 }) await waitNT(wrapper.vm) - expect(wrapper.vm.currentPage).toBe(1) + expect(wrapper.vm.currentPage).toBe(10) expect(wrapper.emitted('input')).toBeDefined() expect(wrapper.emitted('input').length).toBe(1) - expect(wrapper.emitted('input')[0][0]).toBe(1) + expect(wrapper.emitted('input')[0][0]).toBe(10) + + // Change to page 20 + wrapper.setProps({ + value: 20 + }) + await waitNT(wrapper.vm) + expect(wrapper.vm.currentPage).toBe(20) + expect(wrapper.emitted('input').length).toBe(1) + + // Decrease number of pages should reset to page 1 + wrapper.setProps({ + totalRows: 10 + }) + await waitNT(wrapper.vm) + expect(wrapper.vm.currentPage).toBe(1) + expect(wrapper.emitted('input').length).toBe(2) + expect(wrapper.emitted('input')[1][0]).toBe(1) // Change to page 3 wrapper.setProps({ @@ -709,17 +726,16 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(3) - expect(wrapper.emitted('input').length).toBe(2) - expect(wrapper.emitted('input')[1][0]).toBe(3) + expect(wrapper.emitted('input').length).toBe(3) + expect(wrapper.emitted('input')[2][0]).toBe(3) - // Increasing number of pages should reset to page 1 + // Decrease number of pages to 5 should not reset to page 1 wrapper.setProps({ - perPage: 1 + totalRows: 5 }) await waitNT(wrapper.vm) - expect(wrapper.vm.currentPage).toBe(1) + expect(wrapper.vm.currentPage).toBe(3) expect(wrapper.emitted('input').length).toBe(3) - expect(wrapper.emitted('input')[2][0]).toBe(1) wrapper.destroy() }) From d18bd851088cec26aa1edec4a7d0e11257ad70cb Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:20:43 -0300 Subject: [PATCH 03/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index 0a3bc14ac9b..1521f0c0ca8 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -694,14 +694,13 @@ describe('pagination', () => { expect(wrapper.vm.currentPage).toBe(10) expect(wrapper.emitted('input')).not.toBeDefined() + // Change total rows to larger value. Should not change page number wrapper.setProps({ totalRows: 20 }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(10) - expect(wrapper.emitted('input')).toBeDefined() - expect(wrapper.emitted('input').length).toBe(1) - expect(wrapper.emitted('input')[0][0]).toBe(10) + expect(wrapper.emitted('input')).not.toBeDefined() // Change to page 20 wrapper.setProps({ @@ -709,7 +708,7 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(20) - expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input')).not.toBeDefined() // Decrease number of pages should reset to page 1 wrapper.setProps({ @@ -717,8 +716,8 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(1) - expect(wrapper.emitted('input').length).toBe(2) - expect(wrapper.emitted('input')[1][0]).toBe(1) + expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input')[0][0]).toBe(1) // Change to page 3 wrapper.setProps({ @@ -726,8 +725,7 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(3) - expect(wrapper.emitted('input').length).toBe(3) - expect(wrapper.emitted('input')[2][0]).toBe(3) + expect(wrapper.emitted('input').length).toBe(1) // Decrease number of pages to 5 should not reset to page 1 wrapper.setProps({ @@ -735,7 +733,7 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(3) - expect(wrapper.emitted('input').length).toBe(3) + expect(wrapper.emitted('input').length).toBe(1) wrapper.destroy() }) From 589cffda1629209dd004aa6e22f6a18181151de9 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:24:31 -0300 Subject: [PATCH 04/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index 1521f0c0ca8..b51b37f78cd 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -708,7 +708,9 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(20) - expect(wrapper.emitted('input')).not.toBeDefined() + expect(wrapper.emitted('input')).toBeDefined() + expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input')[0][0]).toBe(20) // Decrease number of pages should reset to page 1 wrapper.setProps({ @@ -716,8 +718,8 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(1) - expect(wrapper.emitted('input').length).toBe(1) - expect(wrapper.emitted('input')[0][0]).toBe(1) + expect(wrapper.emitted('input').length).toBe(2) + expect(wrapper.emitted('input')[1][0]).toBe(1) // Change to page 3 wrapper.setProps({ @@ -725,7 +727,8 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(3) - expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input').length).toBe(3) + expect(wrapper.emitted('input')[2][0]).toBe(3) // Decrease number of pages to 5 should not reset to page 1 wrapper.setProps({ @@ -733,7 +736,7 @@ describe('pagination', () => { }) await waitNT(wrapper.vm) expect(wrapper.vm.currentPage).toBe(3) - expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input').length).toBe(3) wrapper.destroy() }) From 3de1c6d2dc502e9b228c78e6800bb6d2d5ce2f4c Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:43:51 -0300 Subject: [PATCH 05/19] Update pagination.js --- src/components/pagination/pagination.js | 34 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 7eefd90e7cf..c933c70e777 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -1,6 +1,7 @@ import Vue from '../../utils/vue' import { getComponentConfig } from '../../utils/config' import { isVisible } from '../../utils/dom' +import { isUndefinedOrNull } from '../../utils/inspect' import paginationMixin from '../../mixins/pagination' const NAME = 'BPagination' @@ -49,19 +50,32 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ numberOfPages() { const result = Math.ceil(sanitizeTotalRows(this.totalRows) / sanitizePerPage(this.perPage)) return result < 1 ? 1 : result + }, + pageSizeNumberOfPages() { + // Used forwarching changes to perPage and numberOfPages + return { + perPage: sanitizePerPage(this.perPage), + numberOfPages: this.numberOfPages + } } }, watch: { - numberOfPages(newNumberOfPages) { - if (newNumberOfPages === this.localNumberOfPages) { - /* istanbul ignore next */ - return - } - this.localNumberOfPages = newNumberOfPages - if (this.currentPage > newNumberOfPages) { - // Try an keep the current page number if possible - // Otherwise set it to the first page - this.currentPage = 1 + pageSizeNumberOfPages(newVal, oldVal) { + if (!isUndefinedOrNull(oldVal)) { + if (newVal.pageSize !== oldVal.pageSize) { + // If the page size changes, reset to page 1 + this.currentPage = 1 + } else if (newVal.numberOfPages === this.localNumberOfPages) { + /* istanbul ignore next */ + return + } else if (newVal.numberOfPages !== oldVal.numberOfPages) { + this.localNumberOfPages = newVal.numberOfPages + if (this.currentPage > newVal.numberOfPages) { + // If numberOfPages changes and is less than + // the currentPage number, reset to page 1 + this.currentPage = 1 + } + } } } }, From 96aa450d6c906c587bdcb3e271288dc49af554ac Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:49:48 -0300 Subject: [PATCH 06/19] Update pagination.js --- src/components/pagination/pagination.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index c933c70e777..bbd40b622c4 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -66,8 +66,8 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // If the page size changes, reset to page 1 this.currentPage = 1 } else if (newVal.numberOfPages === this.localNumberOfPages) { - /* istanbul ignore next */ - return + /* istanbul ignore next */ + return // eslint-disable-line no-useless-return } else if (newVal.numberOfPages !== oldVal.numberOfPages) { this.localNumberOfPages = newVal.numberOfPages if (this.currentPage > newVal.numberOfPages) { From bd6a43c3d2d5bf09c35886c460f183cb884c2300 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 01:51:00 -0300 Subject: [PATCH 07/19] Update pagination.js --- src/components/pagination/pagination.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index bbd40b622c4..9bea77e6644 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -65,10 +65,10 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ if (newVal.pageSize !== oldVal.pageSize) { // If the page size changes, reset to page 1 this.currentPage = 1 - } else if (newVal.numberOfPages === this.localNumberOfPages) { - /* istanbul ignore next */ - return // eslint-disable-line no-useless-return - } else if (newVal.numberOfPages !== oldVal.numberOfPages) { + } else if ( + newVal.numberOfPages !== this.localNumberOfPages && + newVal.numberOfPages !== oldVal.numberOfPages + ) { this.localNumberOfPages = newVal.numberOfPages if (this.currentPage > newVal.numberOfPages) { // If numberOfPages changes and is less than From 5591e678eb70fbb790527cee24bf35f93f6017ec Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:07:15 -0300 Subject: [PATCH 08/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 48 +++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index b51b37f78cd..e0eba74f9e9 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -680,7 +680,6 @@ describe('pagination', () => { }) it('changing the number of pages to less than current page number resets to page 1', async () => { - // https://github.com/bootstrap-vue/bootstrap-vue/issues/2987 const wrapper = mount(BPagination, { propsData: { totalRows: 10, @@ -741,6 +740,53 @@ describe('pagination', () => { wrapper.destroy() }) + it('changing per-page resets to page 1', async () => { + // https://github.com/bootstrap-vue/bootstrap-vue/issues/2987 + const wrapper = mount(BPagination, { + propsData: { + totalRows: 10, + perPage: 1, + value: 4, + limit: 20 + } + }) + expect(wrapper.isVueInstance()).toBe(true) + + expect(wrapper.vm.currentPage).toBe(10) + expect(wrapper.emitted('input')).not.toBeDefined() + + // Change perPage + wrapper.setProps({ + perPage: 2 + }) + await waitNT(wrapper.vm) + expect(wrapper.vm.currentPage).toBe(1) + expect(wrapper.emitted('input')).toBeDefined() + expect(wrapper.emitted('input').length).toBe(1) + expect(wrapper.emitted('input')[0][0]).toBe(1) + + // Change page to 3 + wrapper.setProps({ + value: 3 + }) + await waitNT(wrapper.vm) + expect(wrapper.vm.currentPage).toBe(3) + expect(wrapper.emitted('input').length).toBe(2) + expect(wrapper.emitted('input')[1][0]).toBe(3) + + // Change perPage. Should reset to page 1, even though + // current page is within range of numberOfPages + wrapper.setProps({ + perPage: 1 + }) + await waitNT(wrapper.vm) + expect(wrapper.vm.currentPage).toBe(1) + expect(wrapper.emitted('input').length).toBe(3) + expect(wrapper.emitted('input')[2][0]).toBe(1) + + wrapper.destroy() + }) + // These tests are wrapped in a new describe to limit the scope of the getBCR Mock describe('pagination keyboard navigation', () => { const origGetBCR = Element.prototype.getBoundingClientRect From bfbd4bbf33bc4e014bfee16655d714e5537a7e29 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:08:26 -0300 Subject: [PATCH 09/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index e0eba74f9e9..24a0b826507 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -680,6 +680,7 @@ describe('pagination', () => { }) it('changing the number of pages to less than current page number resets to page 1', async () => { + // https://github.com/bootstrap-vue/bootstrap-vue/issues/3716 const wrapper = mount(BPagination, { propsData: { totalRows: 10, From d4a29aa012cf51600438f05f6a429bb5dca1c09c Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:10:39 -0300 Subject: [PATCH 10/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index 24a0b826507..45aca313bf2 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -753,7 +753,7 @@ describe('pagination', () => { }) expect(wrapper.isVueInstance()).toBe(true) - expect(wrapper.vm.currentPage).toBe(10) + expect(wrapper.vm.currentPage).toBe(4) expect(wrapper.emitted('input')).not.toBeDefined() // Change perPage From 19256163b284bfcc7fa490eb7c1f6854f06be5b8 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:16:28 -0300 Subject: [PATCH 11/19] Update pagination.js --- src/components/pagination/pagination.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 9bea77e6644..45c71061b2b 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -55,14 +55,15 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // Used forwarching changes to perPage and numberOfPages return { perPage: sanitizePerPage(this.perPage), - numberOfPages: this.numberOfPages + numberOfPages: this.numberOfPages, + totalRows: sanitizeTotalRows(this.totalRows) } } }, watch: { pageSizeNumberOfPages(newVal, oldVal) { if (!isUndefinedOrNull(oldVal)) { - if (newVal.pageSize !== oldVal.pageSize) { + if (newVal.pageSize !== oldVal.pageSize && newVal.totalRows === oldVal.totalRows) { // If the page size changes, reset to page 1 this.currentPage = 1 } else if ( From e6879557b8bda8fd414427f1c324d73ffbbba116 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:23:01 -0300 Subject: [PATCH 12/19] Update pagination.js --- src/components/pagination/pagination.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 45c71061b2b..a1687a103a4 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -55,8 +55,8 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // Used forwarching changes to perPage and numberOfPages return { perPage: sanitizePerPage(this.perPage), - numberOfPages: this.numberOfPages, - totalRows: sanitizeTotalRows(this.totalRows) + totalRows: sanitizeTotalRows(this.totalRows), + numberOfPages: this.numberOfPages } } }, From e726a3a1085b09a3b9df24b6ce94b2a0c867afc7 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:25:18 -0300 Subject: [PATCH 13/19] Update pagination.js --- src/components/pagination/pagination.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index a1687a103a4..48d2df87a54 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -63,7 +63,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ watch: { pageSizeNumberOfPages(newVal, oldVal) { if (!isUndefinedOrNull(oldVal)) { - if (newVal.pageSize !== oldVal.pageSize && newVal.totalRows === oldVal.totalRows) { + if (newVal.perPage !== oldVal.perPage && newVal.totalRows === oldVal.totalRows) { // If the page size changes, reset to page 1 this.currentPage = 1 } else if ( From 201296ce974ce291501d1160e2fbe40497b58e94 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:28:25 -0300 Subject: [PATCH 14/19] Update pagination.js --- src/components/pagination/pagination.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 48d2df87a54..a5d2ab0978a 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -55,7 +55,6 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // Used forwarching changes to perPage and numberOfPages return { perPage: sanitizePerPage(this.perPage), - totalRows: sanitizeTotalRows(this.totalRows), numberOfPages: this.numberOfPages } } @@ -63,7 +62,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ watch: { pageSizeNumberOfPages(newVal, oldVal) { if (!isUndefinedOrNull(oldVal)) { - if (newVal.perPage !== oldVal.perPage && newVal.totalRows === oldVal.totalRows) { + if (newVal.perPage !== oldVal.perPage) { // If the page size changes, reset to page 1 this.currentPage = 1 } else if ( From e81be20a3c58ebf3c0bf39816bb750d9a1ac099b Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:40:32 -0300 Subject: [PATCH 15/19] Update pagination.js --- src/components/pagination/pagination.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index a5d2ab0978a..48d2df87a54 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -55,6 +55,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // Used forwarching changes to perPage and numberOfPages return { perPage: sanitizePerPage(this.perPage), + totalRows: sanitizeTotalRows(this.totalRows), numberOfPages: this.numberOfPages } } @@ -62,7 +63,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ watch: { pageSizeNumberOfPages(newVal, oldVal) { if (!isUndefinedOrNull(oldVal)) { - if (newVal.perPage !== oldVal.perPage) { + if (newVal.perPage !== oldVal.perPage && newVal.totalRows === oldVal.totalRows) { // If the page size changes, reset to page 1 this.currentPage = 1 } else if ( From 6d4ecb3d08a98963e7361584b1fb8d22d8a12e4b Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 02:57:04 -0300 Subject: [PATCH 16/19] Update pagination.js --- src/components/pagination/pagination.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 48d2df87a54..286c4b7a5a4 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -70,7 +70,6 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ newVal.numberOfPages !== this.localNumberOfPages && newVal.numberOfPages !== oldVal.numberOfPages ) { - this.localNumberOfPages = newVal.numberOfPages if (this.currentPage > newVal.numberOfPages) { // If numberOfPages changes and is less than // the currentPage number, reset to page 1 @@ -78,6 +77,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ } } } + this.localNumberOfPages = newVal.numberOfPages } }, created() { From 486a3c64960ab9bce40366dc2030350cf3e40c6b Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 03:08:25 -0300 Subject: [PATCH 17/19] Update pagination.js --- src/components/pagination/pagination.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index 286c4b7a5a4..a75fed6a763 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -67,14 +67,12 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ // If the page size changes, reset to page 1 this.currentPage = 1 } else if ( - newVal.numberOfPages !== this.localNumberOfPages && - newVal.numberOfPages !== oldVal.numberOfPages + newVal.numberOfPages !== oldVal.numberOfPages && + this.currentPage > newVal.numberOfPages ) { - if (this.currentPage > newVal.numberOfPages) { - // If numberOfPages changes and is less than - // the currentPage number, reset to page 1 - this.currentPage = 1 - } + // If numberOfPages changes and is less than + // the currentPage number, reset to page 1 + this.currentPage = 1 } } this.localNumberOfPages = newVal.numberOfPages From 7d80fdfec79a9b49b8eb347b7f09b6ca8a715f38 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Sat, 31 Aug 2019 03:32:59 -0300 Subject: [PATCH 18/19] Update pagination.spec.js --- src/components/pagination/pagination.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/pagination/pagination.spec.js b/src/components/pagination/pagination.spec.js index 45aca313bf2..2ac943a6084 100644 --- a/src/components/pagination/pagination.spec.js +++ b/src/components/pagination/pagination.spec.js @@ -150,6 +150,7 @@ describe('pagination', () => { wrapper.setProps({ totalRows: 4 }) + await waitNT(wrapper.vm) expect(wrapper.is('ul')).toBe(true) expect(wrapper.findAll('li').length).toBe(8) @@ -157,6 +158,7 @@ describe('pagination', () => { wrapper.setProps({ perPage: 2 }) + await waitNT(wrapper.vm) expect(wrapper.is('ul')).toBe(true) expect(wrapper.findAll('li').length).toBe(6) From 7a593b3d828ea4da4e89c543fee9ec6942e85313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20M=C3=BCller?= Date: Sat, 31 Aug 2019 08:55:10 +0200 Subject: [PATCH 19/19] chore(docs): minor updates to the table docs --- src/components/pagination/pagination.js | 36 ++++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/components/pagination/pagination.js b/src/components/pagination/pagination.js index a75fed6a763..3da697a5d1c 100644 --- a/src/components/pagination/pagination.js +++ b/src/components/pagination/pagination.js @@ -4,23 +4,13 @@ import { isVisible } from '../../utils/dom' import { isUndefinedOrNull } from '../../utils/inspect' import paginationMixin from '../../mixins/pagination' +// --- Constants --- + const NAME = 'BPagination' const DEFAULT_PER_PAGE = 20 const DEFAULT_TOTAL_ROWS = 0 -// Sanitize the provided per page number (converting to a number) -const sanitizePerPage = val => { - const perPage = parseInt(val, 10) || DEFAULT_PER_PAGE - return perPage < 1 ? 1 : perPage -} - -// Sanitize the provided total rows number (converting to a number) -const sanitizeTotalRows = val => { - const totalRows = parseInt(val, 10) || DEFAULT_TOTAL_ROWS - return totalRows < 0 ? 0 : totalRows -} - const props = { size: { type: String, @@ -40,7 +30,21 @@ const props = { } } -// The render function is brought in via the pagination mixin +// --- Helper functions --- + +// Sanitize the provided per page number (converting to a number) +const sanitizePerPage = val => { + const perPage = parseInt(val, 10) || DEFAULT_PER_PAGE + return perPage < 1 ? 1 : perPage +} + +// Sanitize the provided total rows number (converting to a number) +const sanitizeTotalRows = val => { + const totalRows = parseInt(val, 10) || DEFAULT_TOTAL_ROWS + return totalRows < 0 ? 0 : totalRows +} + +// The render function is brought in via the `paginationMixin` // @vue/component export const BPagination = /*#__PURE__*/ Vue.extend({ name: NAME, @@ -52,7 +56,7 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ return result < 1 ? 1 : result }, pageSizeNumberOfPages() { - // Used forwarching changes to perPage and numberOfPages + // Used for watching changes to `perPage` and `numberOfPages` return { perPage: sanitizePerPage(this.perPage), totalRows: sanitizeTotalRows(this.totalRows), @@ -70,8 +74,8 @@ export const BPagination = /*#__PURE__*/ Vue.extend({ newVal.numberOfPages !== oldVal.numberOfPages && this.currentPage > newVal.numberOfPages ) { - // If numberOfPages changes and is less than - // the currentPage number, reset to page 1 + // If `numberOfPages` changes and is less than + // the `currentPage` number, reset to page 1 this.currentPage = 1 } }