From f755c393a448956df1f91cc3c2b3c20528d19449 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 5 Jan 2017 16:31:50 +1300 Subject: [PATCH] Removed unnecessary urlQuery(), expose qs instead The asset-admin module uses a simpler algo now --- admin/client/src/bundles/vendor.js | 1 + admin/client/src/lib/DataFormat.js | 26 ------------------- admin/client/src/lib/tests/DataFormat-test.js | 17 +----------- webpack.config.js | 1 + 4 files changed, 3 insertions(+), 42 deletions(-) diff --git a/admin/client/src/bundles/vendor.js b/admin/client/src/bundles/vendor.js index fa74b9e46..10081f5cf 100644 --- a/admin/client/src/bundles/vendor.js +++ b/admin/client/src/bundles/vendor.js @@ -32,6 +32,7 @@ require('expose?ApolloClient!apollo-client'); require('expose?ReactApollo!react-apollo'); require('expose?GraphQLTag!graphql-tag'); require('expose?GraphQLFragments!graphql-fragments'); +require('expose?qs!qs'); require('../../../thirdparty/jquery-ondemand/jquery.ondemand.js'); require('../../../thirdparty/jquery-ui/jquery-ui.js'); diff --git a/admin/client/src/lib/DataFormat.js b/admin/client/src/lib/DataFormat.js index 48018a904..503e3d89b 100644 --- a/admin/client/src/lib/DataFormat.js +++ b/admin/client/src/lib/DataFormat.js @@ -1,32 +1,6 @@ import i18n from 'i18n'; import qs from 'qs'; -/** - * Merge existing querystring with new querystring object. - * Does not deep merge. - * - * Example: - * `urlQuery({ foo: 1 }, { bar: 2 })` returns `'?foo=1&bar=2'` - * - * @param {Object} locationQuery - Current browser querystring object (window.location.query) - * @param {Object} newQuery - New object to update. Set to null to clear instead of merge. - * @returns {String} - */ -export function urlQuery(locationQuery, newQuery) { - if (newQuery === null) { - return ''; - } - let mergedQuery = locationQuery || {}; - if (newQuery) { - mergedQuery = Object.assign({}, mergedQuery, newQuery); - } - const query = qs.stringify(mergedQuery); - if (query) { - return `?${query}`; - } - return ''; -} - /** * Turn flatterned querystring object into recursive nested objects, * similarly to how PHP handles nested querystring objects. diff --git a/admin/client/src/lib/tests/DataFormat-test.js b/admin/client/src/lib/tests/DataFormat-test.js index eddb27369..e818ca744 100644 --- a/admin/client/src/lib/tests/DataFormat-test.js +++ b/admin/client/src/lib/tests/DataFormat-test.js @@ -6,26 +6,11 @@ jest.unmock('../DataFormat'); jest.unmock('qs'); jest.unmock('merge'); -import { urlQuery, decodeQuery } from '../DataFormat'; +import { decodeQuery } from '../DataFormat'; describe('DataFormat', () => { - describe('urlQuery()', () => { - it('should return empty string when no newQuery is given', () => { - expect(urlQuery({}, null)).toBe(''); - }); - it('should add new keys', () => { - expect(urlQuery({ foo: 1 }, { bar: 2 })).toBe('?foo=1&bar=2'); - }); - it('should overwrite existing keys', () => { - expect(urlQuery({ foo: 1 }, { foo: 2 })).toBe('?foo=2'); - }); - it('should not deep merge nested keys', () => { - expect(urlQuery({ foo: { bar: 1 } }, { foo: { baz: 2 } })).toBe('?foo%5Bbaz%5D=2'); - }); - }); - describe('decodeQuery', () => { it('should decode flat keys', () => { expect(decodeQuery('?foo=1')).toEqual({ foo: '1' }); diff --git a/webpack.config.js b/webpack.config.js index 9268e422d..8afe2a151 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -97,6 +97,7 @@ const config = [ redux: 'Redux', config: 'Config', 'lib/Router': 'Router', + qs: 'qs', }, module: { loaders: [