Commit e5732925 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Phil Hughes

Remove EE-specific parts from FilteredSearchManager

parent a881ffad
import _ from 'underscore';
import { getParameterByName, getUrlParamsArray } from '~/lib/utils/common_utils';
import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
import recentSearchesStorageKeys from 'ee_else_ce/filtered_search/recent_searches_storage_keys';
import { visitUrl } from '../lib/utils/url_utility';
import Flash from '../flash';
import FilteredSearchContainer from './container';
......@@ -36,13 +37,11 @@ export default class FilteredSearchManager {
this.tokensContainer = this.container.querySelector('.tokens-container');
this.filteredSearchTokenKeys = filteredSearchTokenKeys;
this.stateFiltersSelector = stateFiltersSelector;
this.recentsStorageKeyNames = {
issues: 'issue-recent-searches',
merge_requests: 'merge-request-recent-searches',
};
// EE specific setup
this.initEE();
const { multipleAssignees } = this.filteredSearchInput.dataset;
if (multipleAssignees && this.filteredSearchTokenKeys.enableMultipleAssignees) {
this.filteredSearchTokenKeys.enableMultipleAssignees();
}
this.recentSearchesStore = new RecentSearchesStore({
isLocalStorageAvailable: RecentSearchesService.isAvailable(),
......@@ -54,30 +53,10 @@ export default class FilteredSearchManager {
const fullPath = this.searchHistoryDropdownElement
? this.searchHistoryDropdownElement.dataset.fullPath
: 'project';
const recentSearchesKey = `${fullPath}-${this.recentsStorageKeyNames[this.page]}`;
const recentSearchesKey = `${fullPath}-${recentSearchesStorageKeys[this.page]}`;
this.recentSearchesService = new RecentSearchesService(recentSearchesKey);
}
/**
* Do EE specific initializations
*/
initEE() {
// Setup token keys for multiple-assignees support
if (typeof this.filteredSearchTokenKeys.init === 'function') {
this.filteredSearchTokenKeys.init({
multipleAssignees: this.filteredSearchInput.dataset.multipleAssignees,
});
}
// Add localStorage key name for Epics recent searches
this.recentsStorageKeyNames.epics = 'epics-recent-searches';
// Update `isGroup` from DOM info
if (this.filteredSearchInput) {
this.isGroup = !!this.filteredSearchInput.getAttribute('data-group-id');
}
}
setup() {
// Fetch recent searches from localStorage
this.fetchingRecentSearchesPromise = this.recentSearchesService
......
export default {
issues: 'issue-recent-searches',
merge_requests: 'merge-request-recent-searches',
};
......@@ -29,23 +29,23 @@ const weightConditions = [
/**
* Filter tokens for issues in EE.
*
* @type {FilteredSearchTokenKeys}
*/
const IssuesFilteredSearchTokenKeysEE = new FilteredSearchTokenKeys(
[...tokenKeys, weightTokenKey],
alternativeTokenKeys,
[...conditions, ...weightConditions],
);
class IssuesFilteredSearchTokenKeysEE extends FilteredSearchTokenKeys {
constructor() {
super([...tokenKeys, weightTokenKey], alternativeTokenKeys, [
...conditions,
...weightConditions,
]);
}
// cannot be an arrow function because it needs FilteredSearchTokenKeys instance
IssuesFilteredSearchTokenKeysEE.init = function init(availableFeatures) {
// Enable multiple assignees when available
if (availableFeatures && availableFeatures.multipleAssignees) {
/**
* Changes assignee token to accept multiple values.
*/
enableMultipleAssignees() {
const assigneeTokenKey = this.tokenKeys.find(tk => tk.key === 'assignee');
assigneeTokenKey.type = 'array';
assigneeTokenKey.param = 'username[]';
}
};
}
export default IssuesFilteredSearchTokenKeysEE;
export default new IssuesFilteredSearchTokenKeysEE();
import recentSearchesStorageKeysCE from '~/filtered_search/recent_searches_storage_keys';
export default {
...recentSearchesStorageKeysCE,
epics: 'epics-recent-searches',
};
......@@ -14,9 +14,7 @@ describe('Filtered Search Token Keys (Issues EE)', () => {
let tokenKeys;
beforeEach(() => {
IssuableFilteredSearchTokenKeys.init({
multipleAssignees: true,
});
IssuableFilteredSearchTokenKeys.enableMultipleAssignees();
tokenKeys = IssuableFilteredSearchTokenKeys.get();
});
......
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