Merge pull request woocommerce/woocommerce-admin#2637 from woocommerce/fix/report-table-pagination

Fix "page" parameter collision between routing and table pagination.
This commit is contained in:
Jeff Stieler 2019-07-11 17:23:31 -06:00 committed by GitHub
commit 34e91de4ce
4 changed files with 11 additions and 17 deletions

View File

@ -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' ),

View File

@ -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';
@ -86,11 +86,11 @@ 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.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 ) {
@ -107,16 +107,10 @@ export class Controller extends Component {
return parse( search );
}
getBaseQuery( searchString ) {
const query = this.getQuery( searchString );
delete query.page;
return query;
}
render() {
const { page, match, location } = this.props;
const { url, params } = match;
const query = this.getBaseQuery( location.search );
const query = this.getQuery( location.search );
window.wpNavMenuUrlUpdate( page, query );
window.wpNavMenuClassChange( page, url );

View File

@ -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,

View File

@ -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 {
) }
<Pagination
key={ parseInt( query.page ) || 1 }
page={ parseInt( query.page ) || 1 }
key={ parseInt( query.paged ) || 1 }
page={ parseInt( query.paged ) || 1 }
perPage={ rowsPerPage }
total={ totalRows }
onPageChange={ this.onPageChange }