mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Removed unnecessary urlQuery(), expose qs instead
The asset-admin module uses a simpler algo now
This commit is contained in:
parent
9e8e6314da
commit
f755c393a4
@ -32,6 +32,7 @@ require('expose?ApolloClient!apollo-client');
|
|||||||
require('expose?ReactApollo!react-apollo');
|
require('expose?ReactApollo!react-apollo');
|
||||||
require('expose?GraphQLTag!graphql-tag');
|
require('expose?GraphQLTag!graphql-tag');
|
||||||
require('expose?GraphQLFragments!graphql-fragments');
|
require('expose?GraphQLFragments!graphql-fragments');
|
||||||
|
require('expose?qs!qs');
|
||||||
|
|
||||||
require('../../../thirdparty/jquery-ondemand/jquery.ondemand.js');
|
require('../../../thirdparty/jquery-ondemand/jquery.ondemand.js');
|
||||||
require('../../../thirdparty/jquery-ui/jquery-ui.js');
|
require('../../../thirdparty/jquery-ui/jquery-ui.js');
|
||||||
|
@ -1,32 +1,6 @@
|
|||||||
import i18n from 'i18n';
|
import i18n from 'i18n';
|
||||||
import qs from 'qs';
|
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,
|
* Turn flatterned querystring object into recursive nested objects,
|
||||||
* similarly to how PHP handles nested querystring objects.
|
* similarly to how PHP handles nested querystring objects.
|
||||||
|
@ -6,26 +6,11 @@ jest.unmock('../DataFormat');
|
|||||||
jest.unmock('qs');
|
jest.unmock('qs');
|
||||||
jest.unmock('merge');
|
jest.unmock('merge');
|
||||||
|
|
||||||
import { urlQuery, decodeQuery } from '../DataFormat';
|
import { decodeQuery } from '../DataFormat';
|
||||||
|
|
||||||
|
|
||||||
describe('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', () => {
|
describe('decodeQuery', () => {
|
||||||
it('should decode flat keys', () => {
|
it('should decode flat keys', () => {
|
||||||
expect(decodeQuery('?foo=1')).toEqual({ foo: '1' });
|
expect(decodeQuery('?foo=1')).toEqual({ foo: '1' });
|
||||||
|
@ -97,6 +97,7 @@ const config = [
|
|||||||
redux: 'Redux',
|
redux: 'Redux',
|
||||||
config: 'Config',
|
config: 'Config',
|
||||||
'lib/Router': 'Router',
|
'lib/Router': 'Router',
|
||||||
|
qs: 'qs',
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
loaders: [
|
||||||
|
Loading…
Reference in New Issue
Block a user