From 4ff4b329a6524b49f2e982c8717e33d98576d4fa Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 11 Jul 2019 11:22:26 -0600 Subject: [PATCH 1/2] Fix "page" parameter collision between routing and table pagination. --- client/analytics/report/revenue/table.js | 2 +- client/layout/controller.js | 10 +++++----- client/wc-api/reports/utils.js | 2 +- packages/components/src/table/index.js | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/analytics/report/revenue/table.js b/client/analytics/report/revenue/table.js index 2f7d2201406..dc9f1d02e3a 100644 --- a/client/analytics/report/revenue/table.js +++ b/client/analytics/report/revenue/table.js @@ -228,7 +228,7 @@ export default compose( interval: 'day', orderby: query.orderby || 'date', order: query.order || 'desc', - page: query.page || 1, + page: query.paged || 1, per_page: query.per_page || QUERY_DEFAULTS.pageSize, after: appendTimestamp( datesFromQuery.primary.after, 'start' ), before: appendTimestamp( datesFromQuery.primary.before, 'end' ), diff --git a/client/layout/controller.js b/client/layout/controller.js index f1ad44e3b7f..65791d4d3c2 100644 --- a/client/layout/controller.js +++ b/client/layout/controller.js @@ -4,7 +4,7 @@ */ import { Component, createElement } from '@wordpress/element'; import { parse, stringify } from 'qs'; -import { find, isEqual, last } from 'lodash'; +import { find, isEqual, last, omit } from 'lodash'; import { applyFilters } from '@wordpress/hooks'; import { __ } from '@wordpress/i18n'; @@ -89,8 +89,8 @@ export class Controller extends Component { const prevBaseQuery = this.getBaseQuery( prevProps.location.search ); const baseQuery = this.getBaseQuery( this.props.location.search ); - if ( prevQuery.page > 1 && ! isEqual( prevBaseQuery, baseQuery ) ) { - getHistory().replace( getNewPath( { page: 1 } ) ); + if ( prevQuery.paged > 1 && ! isEqual( prevBaseQuery, baseQuery ) ) { + getHistory().replace( getNewPath( { paged: 1 } ) ); } if ( prevProps.match.url !== this.props.match.url ) { @@ -109,14 +109,14 @@ export class Controller extends Component { getBaseQuery( searchString ) { const query = this.getQuery( searchString ); - delete query.page; + delete query.paged; return query; } render() { const { page, match, location } = this.props; const { url, params } = match; - const query = this.getBaseQuery( location.search ); + const query = omit( this.getQuery( location.search ), 'page' ); window.wpNavMenuUrlUpdate( page, query ); window.wpNavMenuClassChange( page, url ); diff --git a/client/wc-api/reports/utils.js b/client/wc-api/reports/utils.js index 738395a9433..4b70e3273ab 100644 --- a/client/wc-api/reports/utils.js +++ b/client/wc-api/reports/utils.js @@ -349,7 +349,7 @@ export function getReportTableQuery( options ) { order: query.order || 'desc', after: noIntervals ? undefined : appendTimestamp( datesFromQuery.primary.after, 'start' ), before: noIntervals ? undefined : appendTimestamp( datesFromQuery.primary.before, 'end' ), - page: query.page || 1, + page: query.paged || 1, per_page: query.per_page || QUERY_DEFAULTS.pageSize, ...filterQuery, ...tableQuery, diff --git a/packages/components/src/table/index.js b/packages/components/src/table/index.js index 98676607340..e27ebea3c24 100644 --- a/packages/components/src/table/index.js +++ b/packages/components/src/table/index.js @@ -175,7 +175,7 @@ class TableCard extends Component { onPageChange( ...params ); } if ( onQueryChange ) { - onQueryChange( 'page' )( ...params ); + onQueryChange( 'paged' )( ...params ); } } @@ -391,8 +391,8 @@ class TableCard extends Component { ) } Date: Thu, 11 Jul 2019 15:26:58 -0600 Subject: [PATCH 2/2] Remove unneeded query retrieval instance method. --- client/layout/controller.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/client/layout/controller.js b/client/layout/controller.js index 65791d4d3c2..f0d8df47b28 100644 --- a/client/layout/controller.js +++ b/client/layout/controller.js @@ -86,8 +86,8 @@ export class Controller extends Component { componentDidUpdate( prevProps ) { const prevQuery = this.getQuery( prevProps.location.search ); - const prevBaseQuery = this.getBaseQuery( prevProps.location.search ); - const baseQuery = this.getBaseQuery( this.props.location.search ); + const prevBaseQuery = omit( this.getQuery( prevProps.location.search ), 'paged' ); + const baseQuery = omit( this.getQuery( this.props.location.search ), 'paged' ); if ( prevQuery.paged > 1 && ! isEqual( prevBaseQuery, baseQuery ) ) { getHistory().replace( getNewPath( { paged: 1 } ) ); @@ -107,16 +107,10 @@ export class Controller extends Component { return parse( search ); } - getBaseQuery( searchString ) { - const query = this.getQuery( searchString ); - delete query.paged; - return query; - } - render() { const { page, match, location } = this.props; const { url, params } = match; - const query = omit( this.getQuery( location.search ), 'page' ); + const query = this.getQuery( location.search ); window.wpNavMenuUrlUpdate( page, query ); window.wpNavMenuClassChange( page, url );