Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2637 from woocommerce/fix/report-table-pagination
Browse files Browse the repository at this point in the history
Fix "page" parameter collision between routing and table pagination.
  • Loading branch information
jeffstieler authored Jul 11, 2019
2 parents c5ccd0b + 697b8a7 commit 306e7a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/analytics/report/revenue/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
18 changes: 6 additions & 12 deletions client/layout/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion client/wc-api/reports/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class TableCard extends Component {
onPageChange( ...params );
}
if ( onQueryChange ) {
onQueryChange( 'page' )( ...params );
onQueryChange( 'paged' )( ...params );
}
}

Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 306e7a0

Please sign in to comment.