Commit 7eabb7a9 authored by Phil Hughes's avatar Phil Hughes

Use reduce instead of a forEach

Changed an isArray check to use -1
Added comment to boards search manager to explain behaviour
parent 236d6595
...@@ -62,7 +62,13 @@ $(() => { ...@@ -62,7 +62,13 @@ $(() => {
created () { created () {
gl.boardService = new BoardService(this.endpoint, this.bulkUpdatePath, this.boardId); gl.boardService = new BoardService(this.endpoint, this.bulkUpdatePath, this.boardId);
gl.boardsFilterManager = new FilteredSearchBoards(Store.filter, true); this.filterManager = new FilteredSearchBoards(Store.filter, true);
// Listen for updateTokens event
this.$on('updateTokens', this.updateTokens);
},
beforeDestroy() {
this.$off('updateTokens', this.updateTokens);
}, },
mounted () { mounted () {
Store.disabled = this.disabled; Store.disabled = this.disabled;
...@@ -81,7 +87,12 @@ $(() => { ...@@ -81,7 +87,12 @@ $(() => {
Store.addBlankState(); Store.addBlankState();
this.loading = false; this.loading = false;
}); });
},
methods: {
updateTokens() {
this.filterManager.updateTokens();
} }
},
}); });
gl.IssueBoardsSearch = new Vue({ gl.IssueBoardsSearch = new Vue({
......
...@@ -17,7 +17,8 @@ export default { ...@@ -17,7 +17,8 @@ export default {
:list="list" :list="list"
:issue="issue" :issue="issue"
:issue-link-base="issueLinkBase" :issue-link-base="issueLinkBase"
:root-path="rootPath" /> :root-path="rootPath"
:update-filters="true" />
</li> </li>
`, `,
components: { components: {
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
type: String, type: String,
required: true, required: true,
}, },
updateFilters: {
type: Boolean,
required: false,
default: false,
},
}, },
methods: { methods: {
showLabel(label) { showLabel(label) {
...@@ -31,6 +36,8 @@ ...@@ -31,6 +36,8 @@
return !this.list.label || label.id !== this.list.label.id; return !this.list.label || label.id !== this.list.label.id;
}, },
filterByLabel(label, e) { filterByLabel(label, e) {
if (!this.updateFilters) return;
const filterPath = gl.issueBoards.BoardsStore.filter.path.split('&'); const filterPath = gl.issueBoards.BoardsStore.filter.path.split('&');
const labelTitle = encodeURIComponent(label.title); const labelTitle = encodeURIComponent(label.title);
const param = `label_name[]=${labelTitle}`; const param = `label_name[]=${labelTitle}`;
...@@ -46,7 +53,8 @@ ...@@ -46,7 +53,8 @@
gl.issueBoards.BoardsStore.filter.path = filterPath.join('&'); gl.issueBoards.BoardsStore.filter.path = filterPath.join('&');
Store.updateFiltersUrl(); Store.updateFiltersUrl();
gl.boardsFilterManager.updateTokens();
gl.IssueBoardsApp.$emit('updateTokens');
}, },
labelStyle(label) { labelStyle(label) {
return { return {
......
...@@ -4,6 +4,9 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager { ...@@ -4,6 +4,9 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager {
this.store = store; this.store = store;
this.updateUrl = updateUrl; this.updateUrl = updateUrl;
// Issue boards is slightly different, we handle all the requests async
// instead or reloading the page, we just re-fire the list ajax requests
this.isHandledAsync = true; this.isHandledAsync = true;
} }
......
...@@ -64,16 +64,14 @@ class List { ...@@ -64,16 +64,14 @@ class List {
} }
getIssues (emptyIssues = true) { getIssues (emptyIssues = true) {
const data = { page: this.page }; const data = gl.issueBoards.BoardsStore.filter.path.split('&').reduce((data, filterParam) => {
gl.issueBoards.BoardsStore.filter.path.split('&').forEach((filterParam) => { if (filterParam === '') return data;
if (filterParam === '') return;
const paramSplit = filterParam.split('='); const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', ''); const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]'); const isArray = paramSplit[0].indexOf('[]');
let value = decodeURIComponent(paramSplit[1]); const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
value = value.replace(/\+/g, ' ');
if (isArray >= 0) { if (isArray !== -1) {
if (!data[paramKeyNormalized]) { if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = []; data[paramKeyNormalized] = [];
} }
...@@ -82,7 +80,9 @@ class List { ...@@ -82,7 +80,9 @@ class List {
} else { } else {
data[paramKeyNormalized] = value; data[paramKeyNormalized] = value;
} }
});
return data;
}, { page: this.page });
if (this.label && data.label_name) { if (this.label && data.label_name) {
data.label_name = data.label_name.filter(label => label !== this.label.title); data.label_name = data.label_name.filter(label => label !== this.label.title);
......
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