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 @@ $(() => {
created () {
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 () {
Store.disabled = this.disabled;
......@@ -81,7 +87,12 @@ $(() => {
Store.addBlankState();
this.loading = false;
});
},
methods: {
updateTokens() {
this.filterManager.updateTokens();
}
},
});
gl.IssueBoardsSearch = new Vue({
......
......@@ -17,7 +17,8 @@ export default {
:list="list"
:issue="issue"
:issue-link-base="issueLinkBase"
:root-path="rootPath" />
:root-path="rootPath"
:update-filters="true" />
</li>
`,
components: {
......
......@@ -23,6 +23,11 @@
type: String,
required: true,
},
updateFilters: {
type: Boolean,
required: false,
default: false,
},
},
methods: {
showLabel(label) {
......@@ -31,6 +36,8 @@
return !this.list.label || label.id !== this.list.label.id;
},
filterByLabel(label, e) {
if (!this.updateFilters) return;
const filterPath = gl.issueBoards.BoardsStore.filter.path.split('&');
const labelTitle = encodeURIComponent(label.title);
const param = `label_name[]=${labelTitle}`;
......@@ -46,7 +53,8 @@
gl.issueBoards.BoardsStore.filter.path = filterPath.join('&');
Store.updateFiltersUrl();
gl.boardsFilterManager.updateTokens();
gl.IssueBoardsApp.$emit('updateTokens');
},
labelStyle(label) {
return {
......
......@@ -4,6 +4,9 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager {
this.store = store;
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;
}
......
......@@ -64,16 +64,14 @@ class List {
}
getIssues (emptyIssues = true) {
const data = { page: this.page };
gl.issueBoards.BoardsStore.filter.path.split('&').forEach((filterParam) => {
if (filterParam === '') return;
const data = gl.issueBoards.BoardsStore.filter.path.split('&').reduce((data, filterParam) => {
if (filterParam === '') return data;
const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
let value = decodeURIComponent(paramSplit[1]);
value = value.replace(/\+/g, ' ');
const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
if (isArray >= 0) {
if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
......@@ -82,7 +80,9 @@ class List {
} else {
data[paramKeyNormalized] = value;
}
});
return data;
}, { page: this.page });
if (this.label && data.label_name) {
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