Commit fbf1cc6a authored by Phil Hughes's avatar Phil Hughes

Moved reduce function to a util

Fixed issue with modal window including main search bars tokens
parent 4e5bf7d6
...@@ -13,6 +13,7 @@ export default { ...@@ -13,6 +13,7 @@ export default {
FilteredSearchContainer.container = this.$el; FilteredSearchContainer.container = this.$el;
this.filteredSearch = new FilteredSearchBoards(this.store); this.filteredSearch = new FilteredSearchBoards(this.store);
this.filteredSearch.removeTokens();
}, },
beforeDestroy() { beforeDestroy() {
this.filteredSearch.cleanup(); this.filteredSearch.cleanup();
......
/* global Vue */ import Vue from 'vue';
import modalFilters from './filters'; import modalFilters from './filters';
require('./tabs'); require('./tabs');
......
/* global Vue */ /* global Vue */
/* global ListIssue */ /* global ListIssue */
import queryData from '../../utils/query_data';
require('./header'); require('./header');
require('./list'); require('./list');
...@@ -72,29 +73,10 @@ require('./empty_state'); ...@@ -72,29 +73,10 @@ require('./empty_state');
loadIssues(clearIssues = false) { loadIssues(clearIssues = false) {
if (!this.showAddIssuesModal) return false; if (!this.showAddIssuesModal) return false;
const queryData = this.filter.path.split('&').reduce((dataParam, filterParam) => { return gl.boardService.getBacklog(queryData(this.filter.path, {
if (filterParam === '') return dataParam; page: this.page,
per: this.perPage,
const data = dataParam; })).then((res) => {
const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
data[paramKeyNormalized].push(value);
} else {
data[paramKeyNormalized] = value;
}
return data;
}, { page: this.page, per: this.perPage });
return gl.boardService.getBacklog(queryData).then((res) => {
const data = res.json(); const data = res.json();
if (clearIssues) { if (clearIssues) {
......
import FilteredSearchContainer from '../filtered_search/container';
export default class FilteredSearchBoards extends gl.FilteredSearchManager { export default class FilteredSearchBoards extends gl.FilteredSearchManager {
constructor(store, updateUrl = false) { constructor(store, updateUrl = false) {
super('boards'); super('boards');
...@@ -18,13 +20,17 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager { ...@@ -18,13 +20,17 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager {
} }
} }
updateTokens() { removeTokens() {
const tokens = document.querySelectorAll('.js-visual-token'); const tokens = FilteredSearchContainer.container.querySelectorAll('.js-visual-token');
// Remove all the tokens as they will be replaced by the search manager // Remove all the tokens as they will be replaced by the search manager
[].forEach.call(tokens, (el) => { [].forEach.call(tokens, (el) => {
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
}); });
}
updateTokens() {
this.removeTokens();
this.loadSearchParamsFromURL(); this.loadSearchParamsFromURL();
......
/* eslint-disable space-before-function-paren, no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow, no-param-reassign, max-len, no-unused-vars */ /* eslint-disable space-before-function-paren, no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow, no-param-reassign, max-len, no-unused-vars */
/* global ListIssue */ /* global ListIssue */
/* global ListLabel */ /* global ListLabel */
import queryData from '../utils/query_data';
class List { class List {
constructor (obj) { constructor (obj) {
...@@ -64,25 +65,7 @@ class List { ...@@ -64,25 +65,7 @@ class List {
} }
getIssues (emptyIssues = true) { getIssues (emptyIssues = true) {
const data = gl.issueBoards.BoardsStore.filter.path.split('&').reduce((data, filterParam) => { const data = queryData(gl.issueBoards.BoardsStore.filter.path, { page: this.page });
if (filterParam === '') return data;
const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
data[paramKeyNormalized].push(value);
} else {
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);
......
export default (path, extraData) => {
return path.split('&').reduce((data, filterParam) => {
if (filterParam === '') return data;
const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
data[paramKeyNormalized].push(value);
} else {
data[paramKeyNormalized] = value;
}
return data;
}, extraData);
}
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