Persist time queries when clicking on breadcrumbs links (https://github.com/woocommerce/woocommerce-admin/pull/759)
* Make breadcrumbs links persist date queries * Add tests to getTimeRelatedQuery() when query parameter not set * Add comment explanation about navUtils self-import
This commit is contained in:
parent
aac90a8aae
commit
70e7e14e7a
|
@ -15,6 +15,7 @@ import PropTypes from 'prop-types';
|
|||
import './style.scss';
|
||||
import ActivityPanel from './activity-panel';
|
||||
import { Link } from '@woocommerce/components';
|
||||
import { getNewPath, getTimeRelatedQuery } from 'lib/nav-utils';
|
||||
|
||||
class Header extends Component {
|
||||
constructor() {
|
||||
|
@ -83,7 +84,10 @@ class Header extends Component {
|
|||
</span>
|
||||
{ _sections.map( ( section, i ) => {
|
||||
const sectionPiece = Array.isArray( section ) ? (
|
||||
<Link href={ section[ 0 ] } type={ isEmbedded ? 'wp-admin' : 'wc-admin' }>
|
||||
<Link
|
||||
href={ getNewPath( getTimeRelatedQuery(), section[ 0 ], {} ) }
|
||||
type={ isEmbedded ? 'wp-admin' : 'wc-admin' }
|
||||
>
|
||||
{ section[ 1 ] }
|
||||
</Link>
|
||||
) : (
|
||||
|
|
|
@ -6,6 +6,12 @@ import history from 'lib/history';
|
|||
import { parse, stringify } from 'qs';
|
||||
import { isEmpty, pick, uniq } from 'lodash';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
// Import the module into itself. Functions consumed from this import can be mocked in tests.
|
||||
import * as navUtils from './index';
|
||||
|
||||
/**
|
||||
* Returns a string with the site's wp-admin URL appended. JS version of `admin_url`.
|
||||
*
|
||||
|
@ -35,7 +41,7 @@ export const stringifyQuery = query => ( isEmpty( query ) ? '' : '?' + stringify
|
|||
* @param {Object} query Query containing the parameters.
|
||||
* @return {Object} Object containing the time related queries.
|
||||
*/
|
||||
export const getTimeRelatedQuery = query =>
|
||||
export const getTimeRelatedQuery = ( query = navUtils.getQuery() ) =>
|
||||
pick( query, [ 'period', 'compare', 'before', 'after' ] );
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
*/
|
||||
import { getTimeRelatedQuery } from '../index';
|
||||
|
||||
jest.mock( '../index', () => ( {
|
||||
...require.requireActual( '../index' ),
|
||||
getQuery: jest.fn().mockReturnValue( {
|
||||
filter: 'advanced',
|
||||
product_includes: 127,
|
||||
period: 'year',
|
||||
compare: 'previous_year',
|
||||
after: '2018-02-01',
|
||||
before: '2018-01-01',
|
||||
} ),
|
||||
} ) );
|
||||
|
||||
describe( 'getTimeRelatedQuery', () => {
|
||||
it( "should return an empty object it the query doesn't contain any time related parameters", () => {
|
||||
const query = {
|
||||
|
@ -33,4 +45,15 @@ describe( 'getTimeRelatedQuery', () => {
|
|||
|
||||
expect( getTimeRelatedQuery( query ) ).toEqual( timeRelatedQuery );
|
||||
} );
|
||||
|
||||
it( 'should get the query from getQuery() when none is provided in the params', () => {
|
||||
const timeRelatedQuery = {
|
||||
period: 'year',
|
||||
compare: 'previous_year',
|
||||
after: '2018-02-01',
|
||||
before: '2018-01-01',
|
||||
};
|
||||
|
||||
expect( getTimeRelatedQuery() ).toEqual( timeRelatedQuery );
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue