Add page parameter to getNewPath to override default page wc-admin (https://github.com/woocommerce/woocommerce-admin/pull/5821)
* Add page parameter to getNewPath to override default page wc-admin * Updated readme.txt
This commit is contained in:
parent
5874c73a90
commit
db598dafc4
|
@ -93,14 +93,16 @@ export function getSearchWords( query = navUtils.getQuery() ) {
|
||||||
* @param {Object} query object of params to be updated.
|
* @param {Object} query object of params to be updated.
|
||||||
* @param {string} path Relative path (defaults to current path).
|
* @param {string} path Relative path (defaults to current path).
|
||||||
* @param {Object} currentQuery object of current query params (defaults to current querystring).
|
* @param {Object} currentQuery object of current query params (defaults to current querystring).
|
||||||
|
* @param {string} page Page key (defaults to "wc-admin")
|
||||||
* @return {string} Updated URL merging query params into existing params.
|
* @return {string} Updated URL merging query params into existing params.
|
||||||
*/
|
*/
|
||||||
export function getNewPath(
|
export function getNewPath(
|
||||||
query,
|
query,
|
||||||
path = getPath(),
|
path = getPath(),
|
||||||
currentQuery = getQuery()
|
currentQuery = getQuery(),
|
||||||
|
page = 'wc-admin'
|
||||||
) {
|
) {
|
||||||
const args = { page: 'wc-admin', ...currentQuery, ...query };
|
const args = { page, ...currentQuery, ...query };
|
||||||
if ( path !== '/' ) {
|
if ( path !== '/' ) {
|
||||||
args.path = path;
|
args.path = path;
|
||||||
}
|
}
|
||||||
|
@ -156,13 +158,15 @@ export function onQueryChange( param, path = getPath(), query = getQuery() ) {
|
||||||
* @param {Object} query object of params to be updated.
|
* @param {Object} query object of params to be updated.
|
||||||
* @param {string} path Relative path (defaults to current path).
|
* @param {string} path Relative path (defaults to current path).
|
||||||
* @param {Object} currentQuery object of current query params (defaults to current querystring).
|
* @param {Object} currentQuery object of current query params (defaults to current querystring).
|
||||||
|
* @param {string} page Page key (defaults to "wc-admin")
|
||||||
*/
|
*/
|
||||||
export function updateQueryString(
|
export function updateQueryString(
|
||||||
query,
|
query,
|
||||||
path = getPath(),
|
path = getPath(),
|
||||||
currentQuery = getQuery()
|
currentQuery = getQuery(),
|
||||||
|
page = 'wc-admin'
|
||||||
) {
|
) {
|
||||||
const newPath = getNewPath( query, path, currentQuery );
|
const newPath = getNewPath( query, path, currentQuery, page );
|
||||||
getHistory().push( newPath );
|
getHistory().push( newPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { getPersistedQuery, getSearchWords } from '../index';
|
import { getPersistedQuery, getSearchWords, getNewPath } from '../index';
|
||||||
|
|
||||||
jest.mock( '../index', () => ( {
|
jest.mock( '../index', () => ( {
|
||||||
...require.requireActual( '../index' ),
|
...require.requireActual( '../index' ),
|
||||||
|
@ -108,3 +108,30 @@ describe( 'getSearchWords', () => {
|
||||||
expect( () => getSearchWords( query ) ).toThrow( Error );
|
expect( () => getSearchWords( query ) ).toThrow( Error );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
describe( 'getNewPath', () => {
|
||||||
|
it( 'should have default page as "wc-admin"', () => {
|
||||||
|
const path = getNewPath( {}, '', {} );
|
||||||
|
|
||||||
|
expect( path ).toEqual( 'admin.php?page=wc-admin&path=' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should override default page when page parameter is specified', () => {
|
||||||
|
const path = getNewPath( {}, '', {}, 'custom-page' );
|
||||||
|
|
||||||
|
expect( path ).toEqual( 'admin.php?page=custom-page&path=' );
|
||||||
|
} );
|
||||||
|
|
||||||
|
it( 'should override default page by query parameter over page parameter', () => {
|
||||||
|
const path = getNewPath(
|
||||||
|
{
|
||||||
|
page: 'custom-page',
|
||||||
|
},
|
||||||
|
'',
|
||||||
|
{},
|
||||||
|
'default-page'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect( path ).toEqual( 'admin.php?page=custom-page&path=' );
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
|
@ -74,6 +74,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
|
||||||
== Unreleased ==
|
== Unreleased ==
|
||||||
|
|
||||||
- Enhancement: Tasks extensibility in Home Screen. #5794
|
- Enhancement: Tasks extensibility in Home Screen. #5794
|
||||||
|
- Enhancement: Add page parameter to override default wc-admin page in Navigation API. #5821
|
||||||
- Fix: Invalidate product count if the last product was updated in the list. #5790
|
- Fix: Invalidate product count if the last product was updated in the list. #5790
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
Loading…
Reference in New Issue