Commit 2d376247 authored by Miguel Rincon's avatar Miguel Rincon

Disable legacySpacesDecode in urlQueryToFilter

This change passes the legacySpacesDecode parameter in the URL filters
to the urlQueryToFilter clients, so the function can reused without
using the legacy space parsing.
parent 9ee6c875
...@@ -43,7 +43,6 @@ export const fromUrlQueryToSearch = (query = window.location.search) => { ...@@ -43,7 +43,6 @@ export const fromUrlQueryToSearch = (query = window.location.search) => {
urlQueryToFilter(query, { urlQueryToFilter(query, {
filterNamesAllowList: [PARAM_KEY_STATUS, PARAM_KEY_RUNNER_TYPE, PARAM_KEY_TAG], filterNamesAllowList: [PARAM_KEY_STATUS, PARAM_KEY_RUNNER_TYPE, PARAM_KEY_TAG],
filteredSearchTermKey: PARAM_KEY_SEARCH, filteredSearchTermKey: PARAM_KEY_SEARCH,
legacySpacesDecode: false,
}), }),
), ),
sort: params[PARAM_KEY_SORT] || DEFAULT_SORT, sort: params[PARAM_KEY_SORT] || DEFAULT_SORT,
......
...@@ -177,12 +177,13 @@ function filteredSearchTermValue(value) { ...@@ -177,12 +177,13 @@ function filteredSearchTermValue(value) {
* @param {Object} options * @param {Object} options
* @param {String} [options.filteredSearchTermKey] if set, a FILTERED_SEARCH_TERM filter is created to this parameter. `'search'` is suggested * @param {String} [options.filteredSearchTermKey] if set, a FILTERED_SEARCH_TERM filter is created to this parameter. `'search'` is suggested
* @param {String[]} [options.filterNamesAllowList] if set, only this list of filters names is mapped * @param {String[]} [options.filterNamesAllowList] if set, only this list of filters names is mapped
* @param {Boolean} [options.legacySpacesDecode] if set, plus symbols (+) are not encoded as spaces. `false` is suggested * @param {Boolean} [options.legacySpacesDecode] if set to true, plus symbols (+) are not encoded as spaces.
* @return {Object} filter object with filter names and their values * @return {Object} filter object with filter names and their values
*/ */
export function urlQueryToFilter(query = '', options = {}) { export function urlQueryToFilter(
const { filteredSearchTermKey, filterNamesAllowList, legacySpacesDecode = true } = options; query = '',
{ filteredSearchTermKey, filterNamesAllowList, legacySpacesDecode = false } = {},
) {
const filters = queryToObject(query, { gatherArrays: true, legacySpacesDecode }); const filters = queryToObject(query, { gatherArrays: true, legacySpacesDecode });
return Object.keys(filters).reduce((memo, key) => { return Object.keys(filters).reduce((memo, key) => {
const value = filters[key]; const value = filters[key];
......
...@@ -20,7 +20,9 @@ export default () => { ...@@ -20,7 +20,9 @@ export default () => {
labelsEndpoint: labelsPath, labelsEndpoint: labelsPath,
projectEndpoint: projectPath, projectEndpoint: projectPath,
}); });
const { milestone_title = null, label_name = [] } = urlQueryToFilter(window.location.search); const { milestone_title = null, label_name = [] } = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('filters/initialize', { store.dispatch('filters/initialize', {
selectedMilestone: milestone_title, selectedMilestone: milestone_title,
selectedLabelList: label_name, selectedLabelList: label_name,
......
...@@ -28,7 +28,9 @@ export default () => { ...@@ -28,7 +28,9 @@ export default () => {
sort, sort,
direction, direction,
page, page,
} = urlQueryToFilter(window.location.search); } = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('initializeCycleAnalytics', { store.dispatch('initializeCycleAnalytics', {
...initialData, ...initialData,
......
...@@ -35,7 +35,9 @@ export default () => { ...@@ -35,7 +35,9 @@ export default () => {
author_username = null, author_username = null,
milestone_title = null, milestone_title = null,
label_name = [], label_name = [],
} = urlQueryToFilter(window.location.search); } = urlQueryToFilter(window.location.search, {
legacySpacesDecode: true,
});
store.dispatch('filters/initialize', { store.dispatch('filters/initialize', {
selectedSourceBranch: source_branch_name, selectedSourceBranch: source_branch_name,
selectedTargetBranch: target_branch_name, selectedTargetBranch: target_branch_name,
......
...@@ -309,7 +309,14 @@ describe('urlQueryToFilter', () => { ...@@ -309,7 +309,14 @@ describe('urlQueryToFilter', () => {
{ {
[FILTERED_SEARCH_TERM]: [{ value: 'my' }, { value: 'terms' }], [FILTERED_SEARCH_TERM]: [{ value: 'my' }, { value: 'terms' }],
}, },
{ filteredSearchTermKey: 'search', legacySpacesDecode: false }, { filteredSearchTermKey: 'search' },
],
[
'search=my+terms',
{
[FILTERED_SEARCH_TERM]: [{ value: 'my+terms' }],
},
{ filteredSearchTermKey: 'search', legacySpacesDecode: true },
], ],
[ [
'search=my terms&foo=bar&nop=xxx', 'search=my terms&foo=bar&nop=xxx',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment