mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
delete qs utils that are no longer used
This commit is contained in:
@@ -113,44 +113,6 @@ function encodeValue(key, value) {
|
|||||||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert query param object to url query string, adding namespace and
|
|
||||||
* removing defaults. Used to put into url bar after ui route
|
|
||||||
* @param {object} qs config object for namespacing params, filtering defaults
|
|
||||||
* @param {object} query param object
|
|
||||||
* @param {object} any non-namespaced params to append
|
|
||||||
* @return {string} url query string
|
|
||||||
*/
|
|
||||||
export const encodeNonDefaultQueryString = (
|
|
||||||
config,
|
|
||||||
params,
|
|
||||||
nonNamespacedParams = {}
|
|
||||||
) => {
|
|
||||||
if (!params) return '';
|
|
||||||
const paramsWithoutDefaults = removeParams({}, params, config.defaultParams);
|
|
||||||
return encodeQueryString({
|
|
||||||
...namespaceParams(config.namespace, paramsWithoutDefaults),
|
|
||||||
...nonNamespacedParams,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* helper function to namespace params object
|
|
||||||
* @param {string} namespace to append to params
|
|
||||||
* @param {object} params object to append namespace to
|
|
||||||
* @return {object} params object with namespaced keys
|
|
||||||
*/
|
|
||||||
const namespaceParams = (namespace, params) => {
|
|
||||||
if (!namespace) return params;
|
|
||||||
|
|
||||||
const namespaced = {};
|
|
||||||
Object.keys(params).forEach(key => {
|
|
||||||
namespaced[`${namespace}.${key}`] = params[key];
|
|
||||||
});
|
|
||||||
|
|
||||||
return namespaced;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes params from the search string and returns the updated list of params
|
* Removes params from the search string and returns the updated list of params
|
||||||
* @param {object} qs config object (used for getting defaults, current query params etc.)
|
* @param {object} qs config object (used for getting defaults, current query params etc.)
|
||||||
@@ -242,20 +204,6 @@ function dedupeArray(arr) {
|
|||||||
return deduped;
|
return deduped;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Join old and new params together, replacing old values with new ones where
|
|
||||||
* necessary
|
|
||||||
* @param {object} namespaced params object of old params
|
|
||||||
* @param {object} namespaced params object of new params
|
|
||||||
* @return {object} joined namespaced params object
|
|
||||||
*/
|
|
||||||
export function replaceParams(oldParams, newParams) {
|
|
||||||
return {
|
|
||||||
...oldParams,
|
|
||||||
...newParams,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update namespaced param(s), returning a new query string. Leaves params
|
* Update namespaced param(s), returning a new query string. Leaves params
|
||||||
* from other namespaces unaltered
|
* from other namespaces unaltered
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
encodeQueryString,
|
encodeQueryString,
|
||||||
encodeNonDefaultQueryString,
|
|
||||||
parseQueryString,
|
parseQueryString,
|
||||||
getQSConfig,
|
getQSConfig,
|
||||||
removeParams,
|
removeParams,
|
||||||
_stringToObject,
|
_stringToObject,
|
||||||
_addDefaultsToObject,
|
_addDefaultsToObject,
|
||||||
mergeParams,
|
mergeParams,
|
||||||
replaceParams,
|
|
||||||
updateQueryString,
|
updateQueryString,
|
||||||
} from './qs';
|
} from './qs';
|
||||||
|
|
||||||
@@ -48,70 +46,6 @@ describe('qs (qs.js)', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('encodeNonDefaultQueryString', () => {
|
|
||||||
const config = {
|
|
||||||
namespace: null,
|
|
||||||
defaultParams: { page: 1, page_size: 5, order_by: 'name' },
|
|
||||||
integerFields: ['page'],
|
|
||||||
};
|
|
||||||
|
|
||||||
test('should return the expected queryString', () => {
|
|
||||||
[
|
|
||||||
[null, ''],
|
|
||||||
[{}, ''],
|
|
||||||
[{ order_by: 'name', page: 1, page_size: 5 }, ''],
|
|
||||||
[{ order_by: '-name', page: 1, page_size: 5 }, 'order_by=-name'],
|
|
||||||
[
|
|
||||||
{ order_by: '-name', page: 3, page_size: 10 },
|
|
||||||
'order_by=-name&page=3&page_size=10',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
{ order_by: '-name', page: 3, page_size: 10, foo: 'bar' },
|
|
||||||
'foo=bar&order_by=-name&page=3&page_size=10',
|
|
||||||
],
|
|
||||||
].forEach(([params, expectedQueryString]) => {
|
|
||||||
const actualQueryString = encodeNonDefaultQueryString(config, params);
|
|
||||||
|
|
||||||
expect(actualQueryString).toEqual(expectedQueryString);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should omit null values', () => {
|
|
||||||
const vals = {
|
|
||||||
order_by: 'foo',
|
|
||||||
page: null,
|
|
||||||
};
|
|
||||||
expect(encodeNonDefaultQueryString(config, vals)).toEqual('order_by=foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should namespace encoded params', () => {
|
|
||||||
const conf = {
|
|
||||||
namespace: 'item',
|
|
||||||
defaultParams: { page: 1 },
|
|
||||||
};
|
|
||||||
const params = {
|
|
||||||
page: 1,
|
|
||||||
foo: 'bar',
|
|
||||||
};
|
|
||||||
expect(encodeNonDefaultQueryString(conf, params)).toEqual('item.foo=bar');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should handle array values', () => {
|
|
||||||
const vals = {
|
|
||||||
foo: ['one', 'two'],
|
|
||||||
bar: ['alpha', 'beta'],
|
|
||||||
};
|
|
||||||
const conf = {
|
|
||||||
defaultParams: {
|
|
||||||
foo: ['one', 'two'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
expect(encodeNonDefaultQueryString(conf, vals)).toEqual(
|
|
||||||
'bar=alpha&bar=beta'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getQSConfig', () => {
|
describe('getQSConfig', () => {
|
||||||
test('should get default QS config object', () => {
|
test('should get default QS config object', () => {
|
||||||
expect(getQSConfig('organization')).toEqual({
|
expect(getQSConfig('organization')).toEqual({
|
||||||
@@ -803,54 +737,6 @@ describe('qs (qs.js)', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('replaceParams', () => {
|
|
||||||
it('should collect params into one object', () => {
|
|
||||||
const oldParams = { foo: 'one' };
|
|
||||||
const newParams = { bar: 'two' };
|
|
||||||
expect(replaceParams(oldParams, newParams)).toEqual({
|
|
||||||
foo: 'one',
|
|
||||||
bar: 'two',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should retain unaltered params', () => {
|
|
||||||
const oldParams = {
|
|
||||||
foo: 'one',
|
|
||||||
bar: 'baz',
|
|
||||||
};
|
|
||||||
const newParams = { foo: 'two' };
|
|
||||||
expect(replaceParams(oldParams, newParams)).toEqual({
|
|
||||||
foo: 'two',
|
|
||||||
bar: 'baz',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should override old values with new ones', () => {
|
|
||||||
const oldParams = {
|
|
||||||
foo: 'one',
|
|
||||||
bar: 'three',
|
|
||||||
};
|
|
||||||
const newParams = {
|
|
||||||
foo: 'two',
|
|
||||||
baz: 'four',
|
|
||||||
};
|
|
||||||
expect(replaceParams(oldParams, newParams)).toEqual({
|
|
||||||
foo: 'two',
|
|
||||||
bar: 'three',
|
|
||||||
baz: 'four',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle exact duplicates', () => {
|
|
||||||
const oldParams = { foo: 'one' };
|
|
||||||
const newParams = { foo: 'one', bar: 'two' };
|
|
||||||
expect(replaceParams(oldParams, newParams)).toEqual({
|
|
||||||
foo: 'one',
|
|
||||||
bar: 'two',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('updateQueryString', () => {
|
describe('updateQueryString', () => {
|
||||||
const config = {
|
const config = {
|
||||||
namespace: 'template',
|
namespace: 'template',
|
||||||
|
|||||||
Reference in New Issue
Block a user