Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
defaultTableDateFormat,
getCurrentDates,
} from '@woocommerce/date';
import { stringify } from 'qs';
import { CurrencyContext } from '@woocommerce/currency';

/**
Expand Down Expand Up @@ -308,7 +307,7 @@ const formatProps = memoize(
[
isError,
isRequesting,
stringify( tableQuery ),
new URLSearchParams( tableQuery ).toString(),
get( revenueData, [ 'totalResults' ], 0 ),
get( revenueData, [ 'data', 'intervals' ], EMPTY_ARRAY ).length,
].join( ':' )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { parse, stringify } from 'qs';
import { DateRangeFilterPicker } from '@woocommerce/components';
import { useSettings } from '@woocommerce/data';
import {
Expand All @@ -20,11 +19,13 @@ const DefaultDate = ( { value, onChange } ) => {
onChange( {
target: {
name: 'woocommerce_default_date_range',
value: stringify( query ),
value: new URLSearchParams( query ).toString(),
},
} );
};
const query = parse( value.replace( /&/g, '&' ) );
const query = Object.fromEntries(
new URLSearchParams( value.replace( /&/g, '&' ) )
);
const { period, compare, before, after } = getDateParamsFromQuery(
query,
defaultDateRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { applyFilters } from '@wordpress/hooks';
import { useEffect } from '@wordpress/element';
import { triggerExitPageCesSurvey } from '@woocommerce/customer-effort-score';
import QueryString, { parse } from 'qs';

/**
* Internal dependencies
Expand All @@ -17,10 +16,8 @@ import './style.scss';

type QueryParams = EmbeddedBodyProps;

function isWPPage(
params: QueryParams | QueryString.ParsedQs
): params is QueryParams {
return ( params as QueryParams ).page !== undefined;
function isWPPage( params: URLSearchParams ): boolean {
return params.get( 'page' ) !== null;
}

const EMBEDDED_BODY_COMPONENT_LIST: React.ElementType[] = [
Expand All @@ -40,10 +37,10 @@ export const EmbeddedBodyLayout = () => {
triggerExitPageCesSurvey();
}, [] );

const query = parse( location.search.substring( 1 ) );
const query = new URLSearchParams( location.search );
let queryParams: QueryParams = { page: '', tab: '' };
if ( isWPPage( query ) ) {
queryParams = query;
queryParams = Object.fromEntries( query ) as QueryParams;
}
/**
* Filter an array of body components for WooCommerce non-react pages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { TourKit, TourKitTypes } from '@woocommerce/components';
import { recordEvent } from '@woocommerce/tracks';
import qs from 'qs';

/**
* Internal dependencies
Expand Down Expand Up @@ -294,7 +293,9 @@ export const ProductTour = () => {
recordEvent( 'walkthrough_product_enable_button_click' );
} );

const query = qs.parse( window.location.search.slice( 1 ) );
const query = Object.fromEntries(
new URLSearchParams( window.location.search )
);
if ( query && query.tutorial === 'true' ) {
const intervalId = waitUntilElementTopNotChange(
tourConfig.steps[ 0 ].referenceElements?.desktop || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { TourKit, TourKitTypes } from '@woocommerce/components';
import { recordEvent } from '@woocommerce/tracks';
import { useDispatch } from '@wordpress/data';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
import qs from 'qs';

/**
* Internal dependencies
Expand All @@ -25,8 +24,8 @@ const WCAddonsTour = () => {
const defaultAutoScrollBlock: ScrollLogicalPosition = 'center';

useEffect( () => {
const query = qs.parse( window.location.search.slice( 1 ) );
if ( query?.tutorial === 'true' ) {
const query = new URLSearchParams( location.search );
if ( query.get( 'tutorial' ) === 'true' ) {
const intervalId = waitUntilElementTopNotChange(
steps[ 0 ].referenceElements?.desktop || '',
() => {
Expand Down
21 changes: 12 additions & 9 deletions plugins/woocommerce-admin/client/layout/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -424,18 +423,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;
Expand Down
14 changes: 3 additions & 11 deletions plugins/woocommerce-admin/client/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import { get, isFunction, identity, memoize } from 'lodash';
import { parse } from 'qs';
import {
CustomerEffortScoreModalContainer,
triggerExitPageCesSurvey,
Expand Down Expand Up @@ -186,15 +185,6 @@ class _Layout extends Component {
} );
}

getQuery( searchString ) {
if ( ! searchString ) {
return {};
}

const search = searchString.substring( 1 );
return parse( search );
}

isWCPaySettingsPage() {
const { page, section, tab } = getQuery();
return (
Expand All @@ -208,7 +198,9 @@ class _Layout extends Component {
const { isEmbedded, ...restProps } = this.props;
const { location, page } = this.props;
const { breadcrumbs } = page;
const query = this.getQuery( location && location.search );
const query = Object.fromEntries(
new URLSearchParams( location && location.search )
);

return (
<LayoutContextProvider
Expand Down
1 change: 0 additions & 1 deletion plugins/woocommerce-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"history": "^5.3.0",
"lodash": "^4.17.21",
"memize": "^1.1.0",
"qs": "^6.10.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
Expand Down
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/remove-qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Remove `qs` dependency from `woocommerce-admin`
Loading