From 4510429e8f67becae95cdc4e8b14a290fc29803d Mon Sep 17 00:00:00 2001 From: Simon Knox Date: Wed, 14 Mar 2018 17:37:03 +1100 Subject: fix board filters for No Milestone and Label values --- app/assets/javascripts/boards/utils/query_data.js | 15 ++++- ...oard-to-no-milestone-makes-all-lists-show-0.yml | 5 ++ spec/javascripts/boards/utils/query_data_spec.js | 76 +++++++++++++++++----- 3 files changed, 78 insertions(+), 18 deletions(-) create mode 100644 changelogs/unreleased/43317-scoping-issue-board-to-no-milestone-makes-all-lists-show-0.yml diff --git a/app/assets/javascripts/boards/utils/query_data.js b/app/assets/javascripts/boards/utils/query_data.js index 65315979df7..7788af09120 100644 --- a/app/assets/javascripts/boards/utils/query_data.js +++ b/app/assets/javascripts/boards/utils/query_data.js @@ -1,13 +1,22 @@ +import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; + export default (path, extraData) => path.split('&').reduce((dataParam, filterParam) => { if (filterParam === '') return dataParam; const data = dataParam; const paramSplit = filterParam.split('='); const paramKeyNormalized = paramSplit[0].replace('[]', ''); - const isArray = paramSplit[0].indexOf('[]'); - const value = decodeURIComponent(paramSplit[1].replace(/\+/g, ' ')); + const isArray = paramSplit[0].includes('[]'); + + let value = paramSplit[1]; + + if (FilteredSearchTokenKeys.searchByConditionUrl(dataParam)) { + value = decodeURIComponent(value).replace(/\+/g, ' '); + } else { + value = decodeURIComponent(value.replace(/\+/g, ' ')); + } - if (isArray !== -1) { + if (isArray) { if (!data[paramKeyNormalized]) { data[paramKeyNormalized] = []; } diff --git a/changelogs/unreleased/43317-scoping-issue-board-to-no-milestone-makes-all-lists-show-0.yml b/changelogs/unreleased/43317-scoping-issue-board-to-no-milestone-makes-all-lists-show-0.yml new file mode 100644 index 00000000000..141f3b2c7e7 --- /dev/null +++ b/changelogs/unreleased/43317-scoping-issue-board-to-no-milestone-makes-all-lists-show-0.yml @@ -0,0 +1,5 @@ +--- +title: Fix board filters for No Milestone and No Label +merge_request: 17736 +author: +type: fixed diff --git a/spec/javascripts/boards/utils/query_data_spec.js b/spec/javascripts/boards/utils/query_data_spec.js index 922215ffc1d..b354b074962 100644 --- a/spec/javascripts/boards/utils/query_data_spec.js +++ b/spec/javascripts/boards/utils/query_data_spec.js @@ -1,27 +1,73 @@ import queryData from '~/boards/utils/query_data'; describe('queryData', () => { - it('parses path for label with trailing +', () => { - expect( - queryData('label_name[]=label%2B', {}), - ).toEqual({ - label_name: ['label+'], + describe('filters milestones', () => { + it('by No Milestone', () => { + expect( + queryData('milestone_title=No+Milestone', {}), + ).toEqual({ + milestone_title: 'No Milestone', + }); + }); + + it('by Upcoming Milestone', () => { + expect( + queryData('milestone_title=%23upcoming', {}), + ).toEqual({ + milestone_title: '#upcoming', + }); + }); + + it('by Started Milestone', () => { + expect( + queryData('milestone_title=%23started', {}), + ).toEqual({ + milestone_title: '#started', + }); + }); + + it('with + in the name', () => { + expect( + queryData('milestone_title=A%2B', {}), + ).toEqual({ + milestone_title: 'A+', + }); + }); + + it('with space in the name', () => { + expect( + queryData('milestone_title=Milestone%20with%20spaces', {}), + ).toEqual({ + milestone_title: 'Milestone with spaces', + }); }); }); - it('parses path for milestone with trailing +', () => { - expect( - queryData('milestone_title=A%2B', {}), - ).toEqual({ - milestone_title: 'A+', + describe('filters labels', () => { + it('by No Label', () => { + expect( + queryData('label_name[]=No+Label', {}), + ).toEqual({ + label_name: ['No Label'], + }); + }); + + it('with + in label name', () => { + expect( + queryData('label_name[]=label%2B', {}), + ).toEqual({ + label_name: ['label+'], + }); }); }); - it('parses path for search terms with spaces', () => { - expect( - queryData('search=two+words', {}), - ).toEqual({ - search: 'two words', + describe('text search', () => { + it('with spaces', () => { + expect( + queryData('search=two+words', {}), + ).toEqual({ + search: 'two words', + }); }); }); }); -- cgit v1.2.1