Remove `qs` dependency from layout Controller,
use native `URLSearchParams` instead.
This commit is contained in:
parent
e470c62650
commit
c3888d658e
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
import { Suspense, lazy } from '@wordpress/element';
|
||||
import { useRef, useEffect } from 'react';
|
||||
import { parse, stringify } from 'qs';
|
||||
import { find, isEqual, last, omit } from 'lodash';
|
||||
import { applyFilters } from '@wordpress/hooks';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
@ -356,18 +355,22 @@ export const Controller = ( { ...props } ) => {
|
|||
*/
|
||||
export function updateLinkHref( item, nextQuery, excludedScreens ) {
|
||||
if ( isWCAdmin( item.href ) ) {
|
||||
// If we accept a full HTMLAnchorElement, then we should be able to use `.search`.
|
||||
// const query = new URLSearchParams( item.search );
|
||||
// but to remain backward compatible, we support any object with `href` property.
|
||||
const search = last( item.href.split( '?' ) );
|
||||
const query = parse( search );
|
||||
const path = query.path || 'homescreen';
|
||||
let query = new URLSearchParams( search );
|
||||
const path = query.get( 'path' ) || 'homescreen';
|
||||
const screen = getScreenFromPath( path );
|
||||
|
||||
const isExcludedScreen = excludedScreens.includes( screen );
|
||||
if ( ! excludedScreens.includes( screen ) ) {
|
||||
query = new URLSearchParams( {
|
||||
...Object.fromEntries( query ),
|
||||
...nextQuery,
|
||||
} );
|
||||
}
|
||||
|
||||
const href =
|
||||
'admin.php?' +
|
||||
stringify(
|
||||
Object.assign( query, isExcludedScreen ? {} : nextQuery )
|
||||
);
|
||||
const href = 'admin.php?' + query.toString();
|
||||
|
||||
// Replace the href so you can see the url on hover.
|
||||
item.href = href;
|
||||
|
|
Loading…
Reference in New Issue