Commit 08a09c6b authored by Alfredo Sumaran's avatar Alfredo Sumaran

Remove IIFEs in filtered_search_bundle.js

parent eeaeb275
...@@ -2,8 +2,7 @@ import Filter from '~/droplab/plugins/filter'; ...@@ -2,8 +2,7 @@ import Filter from '~/droplab/plugins/filter';
require('./filtered_search_dropdown'); require('./filtered_search_dropdown');
(() => { class DropdownHint extends gl.FilteredSearchDropdown {
class DropdownHint extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input, filter) { constructor(droplab, dropdown, input, filter) {
super(droplab, dropdown, input, filter); super(droplab, dropdown, input, filter);
this.config = { this.config = {
...@@ -76,8 +75,7 @@ require('./filtered_search_dropdown'); ...@@ -76,8 +75,7 @@ require('./filtered_search_dropdown');
init() { init() {
this.droplab.addHook(this.input, this.dropdown, [Filter], this.config).init(); this.droplab.addHook(this.input, this.dropdown, [Filter], this.config).init();
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.DropdownHint = DropdownHint; gl.DropdownHint = DropdownHint;
})();
...@@ -5,8 +5,7 @@ import Filter from '~/droplab/plugins/filter'; ...@@ -5,8 +5,7 @@ import Filter from '~/droplab/plugins/filter';
require('./filtered_search_dropdown'); require('./filtered_search_dropdown');
(() => { class DropdownNonUser extends gl.FilteredSearchDropdown {
class DropdownNonUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input, filter, endpoint, symbol) { constructor(droplab, dropdown, input, filter, endpoint, symbol) {
super(droplab, dropdown, input, filter); super(droplab, dropdown, input, filter);
this.symbol = symbol; this.symbol = symbol;
...@@ -45,8 +44,7 @@ require('./filtered_search_dropdown'); ...@@ -45,8 +44,7 @@ require('./filtered_search_dropdown');
this.droplab this.droplab
.addHook(this.input, this.dropdown, [Ajax, Filter], this.config).init(); .addHook(this.input, this.dropdown, [Ajax, Filter], this.config).init();
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.DropdownNonUser = DropdownNonUser; gl.DropdownNonUser = DropdownNonUser;
})();
...@@ -4,8 +4,7 @@ import AjaxFilter from '~/droplab/plugins/ajax_filter'; ...@@ -4,8 +4,7 @@ import AjaxFilter from '~/droplab/plugins/ajax_filter';
require('./filtered_search_dropdown'); require('./filtered_search_dropdown');
(() => { class DropdownUser extends gl.FilteredSearchDropdown {
class DropdownUser extends gl.FilteredSearchDropdown {
constructor(droplab, dropdown, input, filter) { constructor(droplab, dropdown, input, filter) {
super(droplab, dropdown, input, filter); super(droplab, dropdown, input, filter);
this.config = { this.config = {
...@@ -65,8 +64,7 @@ require('./filtered_search_dropdown'); ...@@ -65,8 +64,7 @@ require('./filtered_search_dropdown');
init() { init() {
this.droplab.addHook(this.input, this.dropdown, [AjaxFilter], this.config).init(); this.droplab.addHook(this.input, this.dropdown, [AjaxFilter], this.config).init();
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.DropdownUser = DropdownUser; gl.DropdownUser = DropdownUser;
})();
import FilteredSearchContainer from './container'; import FilteredSearchContainer from './container';
(() => { class DropdownUtils {
class DropdownUtils {
static getEscapedText(text) { static getEscapedText(text) {
let escapedText = text; let escapedText = text;
const hasSpace = text.indexOf(' ') !== -1; const hasSpace = text.indexOf(' ') !== -1;
...@@ -176,8 +175,7 @@ import FilteredSearchContainer from './container'; ...@@ -176,8 +175,7 @@ import FilteredSearchContainer from './container';
right, right,
}; };
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.DropdownUtils = DropdownUtils; gl.DropdownUtils = DropdownUtils;
})();
(() => { const DATA_DROPDOWN_TRIGGER = 'data-dropdown-trigger';
const DATA_DROPDOWN_TRIGGER = 'data-dropdown-trigger';
class FilteredSearchDropdown { class FilteredSearchDropdown {
constructor(droplab, dropdown, input, filter) { constructor(droplab, dropdown, input, filter) {
this.droplab = droplab; this.droplab = droplab;
this.hookId = input && input.id; this.hookId = input && input.id;
...@@ -117,8 +116,7 @@ ...@@ -117,8 +116,7 @@
hook.list.render(results); hook.list.render(results);
} }
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.FilteredSearchDropdown = FilteredSearchDropdown; gl.FilteredSearchDropdown = FilteredSearchDropdown;
})();
import DropLab from '~/droplab/drop_lab'; import DropLab from '~/droplab/drop_lab';
import FilteredSearchContainer from './container'; import FilteredSearchContainer from './container';
(() => { class FilteredSearchDropdownManager {
class FilteredSearchDropdownManager {
constructor(baseEndpoint = '', page) { constructor(baseEndpoint = '', page) {
this.container = FilteredSearchContainer.container; this.container = FilteredSearchContainer.container;
this.baseEndpoint = baseEndpoint.replace(/\/$/, ''); this.baseEndpoint = baseEndpoint.replace(/\/$/, '');
...@@ -184,8 +183,7 @@ import FilteredSearchContainer from './container'; ...@@ -184,8 +183,7 @@ import FilteredSearchContainer from './container';
destroyDroplab() { destroyDroplab() {
this.droplab.destroy(); this.droplab.destroy();
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.FilteredSearchDropdownManager = FilteredSearchDropdownManager; gl.FilteredSearchDropdownManager = FilteredSearchDropdownManager;
})();
...@@ -6,8 +6,7 @@ import RecentSearchesStore from './stores/recent_searches_store'; ...@@ -6,8 +6,7 @@ import RecentSearchesStore from './stores/recent_searches_store';
import RecentSearchesService from './services/recent_searches_service'; import RecentSearchesService from './services/recent_searches_service';
import eventHub from './event_hub'; import eventHub from './event_hub';
(() => { class FilteredSearchManager {
class FilteredSearchManager {
constructor(page) { constructor(page) {
this.container = FilteredSearchContainer.container; this.container = FilteredSearchContainer.container;
this.filteredSearchInput = this.container.querySelector('.filtered-search'); this.filteredSearchInput = this.container.querySelector('.filtered-search');
...@@ -487,8 +486,7 @@ import eventHub from './event_hub'; ...@@ -487,8 +486,7 @@ import eventHub from './event_hub';
this.filteredSearchInput.dispatchEvent(new CustomEvent('input')); this.filteredSearchInput.dispatchEvent(new CustomEvent('input'));
this.search(); this.search();
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.FilteredSearchManager = FilteredSearchManager; gl.FilteredSearchManager = FilteredSearchManager;
})();
(() => { const tokenKeys = [{
const tokenKeys = [{
key: 'author', key: 'author',
type: 'string', type: 'string',
param: 'username', param: 'username',
symbol: '@', symbol: '@',
}, { }, {
key: 'assignee', key: 'assignee',
type: 'string', type: 'string',
param: 'username', param: 'username',
symbol: '@', symbol: '@',
}, { }, {
key: 'milestone', key: 'milestone',
type: 'string', type: 'string',
param: 'title', param: 'title',
symbol: '%', symbol: '%',
}, { }, {
key: 'label', key: 'label',
type: 'array', type: 'array',
param: 'name[]', param: 'name[]',
symbol: '~', symbol: '~',
}]; }];
const alternativeTokenKeys = [{ const alternativeTokenKeys = [{
key: 'label', key: 'label',
type: 'string', type: 'string',
param: 'name', param: 'name',
symbol: '~', symbol: '~',
}]; }];
const tokenKeysWithAlternative = tokenKeys.concat(alternativeTokenKeys); const tokenKeysWithAlternative = tokenKeys.concat(alternativeTokenKeys);
const conditions = [{ const conditions = [{
url: 'assignee_id=0', url: 'assignee_id=0',
tokenKey: 'assignee', tokenKey: 'assignee',
value: 'none', value: 'none',
}, { }, {
url: 'milestone_title=No+Milestone', url: 'milestone_title=No+Milestone',
tokenKey: 'milestone', tokenKey: 'milestone',
value: 'none', value: 'none',
}, { }, {
url: 'milestone_title=%23upcoming', url: 'milestone_title=%23upcoming',
tokenKey: 'milestone', tokenKey: 'milestone',
value: 'upcoming', value: 'upcoming',
}, { }, {
url: 'milestone_title=%23started', url: 'milestone_title=%23started',
tokenKey: 'milestone', tokenKey: 'milestone',
value: 'started', value: 'started',
}, { }, {
url: 'label_name[]=No+Label', url: 'label_name[]=No+Label',
tokenKey: 'label', tokenKey: 'label',
value: 'none', value: 'none',
}]; }];
class FilteredSearchTokenKeys { class FilteredSearchTokenKeys {
static get() { static get() {
return tokenKeys; return tokenKeys;
} }
...@@ -93,8 +92,7 @@ ...@@ -93,8 +92,7 @@
return conditions return conditions
.find(condition => condition.tokenKey === key && condition.value === value) || null; .find(condition => condition.tokenKey === key && condition.value === value) || null;
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.FilteredSearchTokenKeys = FilteredSearchTokenKeys; gl.FilteredSearchTokenKeys = FilteredSearchTokenKeys;
})();
require('./filtered_search_token_keys'); require('./filtered_search_token_keys');
(() => { class FilteredSearchTokenizer {
class FilteredSearchTokenizer {
static processTokens(input) { static processTokens(input) {
const allowedKeys = gl.FilteredSearchTokenKeys.get().map(i => i.key); const allowedKeys = gl.FilteredSearchTokenKeys.get().map(i => i.key);
// Regex extracts `(token):(symbol)(value)` // Regex extracts `(token):(symbol)(value)`
...@@ -51,8 +50,7 @@ require('./filtered_search_token_keys'); ...@@ -51,8 +50,7 @@ require('./filtered_search_token_keys');
searchToken, searchToken,
}; };
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.FilteredSearchTokenizer = FilteredSearchTokenizer; gl.FilteredSearchTokenizer = FilteredSearchTokenizer;
})();
...@@ -3,8 +3,7 @@ require('~/filtered_search/filtered_search_tokenizer'); ...@@ -3,8 +3,7 @@ require('~/filtered_search/filtered_search_tokenizer');
require('~/filtered_search/filtered_search_dropdown'); require('~/filtered_search/filtered_search_dropdown');
require('~/filtered_search/dropdown_user'); require('~/filtered_search/dropdown_user');
(() => { describe('Dropdown User', () => {
describe('Dropdown User', () => {
describe('getSearchInput', () => { describe('getSearchInput', () => {
let dropdownUser; let dropdownUser;
...@@ -67,5 +66,4 @@ require('~/filtered_search/dropdown_user'); ...@@ -67,5 +66,4 @@ require('~/filtered_search/dropdown_user');
window.gon = {}; window.gon = {};
}); });
}); });
}); });
})();
...@@ -3,8 +3,7 @@ require('~/filtered_search/dropdown_utils'); ...@@ -3,8 +3,7 @@ require('~/filtered_search/dropdown_utils');
require('~/filtered_search/filtered_search_tokenizer'); require('~/filtered_search/filtered_search_tokenizer');
require('~/filtered_search/filtered_search_dropdown_manager'); require('~/filtered_search/filtered_search_dropdown_manager');
(() => { describe('Dropdown Utils', () => {
describe('Dropdown Utils', () => {
describe('getEscapedText', () => { describe('getEscapedText', () => {
it('should return same word when it has no space', () => { it('should return same word when it has no space', () => {
const escaped = gl.DropdownUtils.getEscapedText('textWithoutSpace'); const escaped = gl.DropdownUtils.getEscapedText('textWithoutSpace');
...@@ -306,5 +305,4 @@ require('~/filtered_search/filtered_search_dropdown_manager'); ...@@ -306,5 +305,4 @@ require('~/filtered_search/filtered_search_dropdown_manager');
}); });
}); });
}); });
}); });
})();
...@@ -3,8 +3,7 @@ require('~/filtered_search/filtered_search_visual_tokens'); ...@@ -3,8 +3,7 @@ require('~/filtered_search/filtered_search_visual_tokens');
require('~/filtered_search/filtered_search_tokenizer'); require('~/filtered_search/filtered_search_tokenizer');
require('~/filtered_search/filtered_search_dropdown_manager'); require('~/filtered_search/filtered_search_dropdown_manager');
(() => { describe('Filtered Search Dropdown Manager', () => {
describe('Filtered Search Dropdown Manager', () => {
describe('addWordToInput', () => { describe('addWordToInput', () => {
function getInputValue() { function getInputValue() {
return document.querySelector('.filtered-search').value; return document.querySelector('.filtered-search').value;
...@@ -97,5 +96,4 @@ require('~/filtered_search/filtered_search_dropdown_manager'); ...@@ -97,5 +96,4 @@ require('~/filtered_search/filtered_search_dropdown_manager');
}); });
}); });
}); });
}); });
})();
...@@ -6,8 +6,7 @@ require('~/filtered_search/filtered_search_dropdown_manager'); ...@@ -6,8 +6,7 @@ require('~/filtered_search/filtered_search_dropdown_manager');
require('~/filtered_search/filtered_search_manager'); require('~/filtered_search/filtered_search_manager');
const FilteredSearchSpecHelper = require('../helpers/filtered_search_spec_helper'); const FilteredSearchSpecHelper = require('../helpers/filtered_search_spec_helper');
(() => { describe('Filtered Search Manager', () => {
describe('Filtered Search Manager', () => {
let input; let input;
let manager; let manager;
let tokensContainer; let tokensContainer;
...@@ -272,5 +271,4 @@ const FilteredSearchSpecHelper = require('../helpers/filtered_search_spec_helper ...@@ -272,5 +271,4 @@ const FilteredSearchSpecHelper = require('../helpers/filtered_search_spec_helper
expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(false); expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(false);
}); });
}); });
}); });
})();
require('~/extensions/array'); require('~/extensions/array');
require('~/filtered_search/filtered_search_token_keys'); require('~/filtered_search/filtered_search_token_keys');
(() => { describe('Filtered Search Token Keys', () => {
describe('Filtered Search Token Keys', () => {
describe('get', () => { describe('get', () => {
let tokenKeys; let tokenKeys;
...@@ -106,5 +105,4 @@ require('~/filtered_search/filtered_search_token_keys'); ...@@ -106,5 +105,4 @@ require('~/filtered_search/filtered_search_token_keys');
expect(result).toEqual(conditions[0]); expect(result).toEqual(conditions[0]);
}); });
}); });
}); });
})();
...@@ -2,8 +2,7 @@ require('~/extensions/array'); ...@@ -2,8 +2,7 @@ require('~/extensions/array');
require('~/filtered_search/filtered_search_token_keys'); require('~/filtered_search/filtered_search_token_keys');
require('~/filtered_search/filtered_search_tokenizer'); require('~/filtered_search/filtered_search_tokenizer');
(() => { describe('Filtered Search Tokenizer', () => {
describe('Filtered Search Tokenizer', () => {
describe('processTokens', () => { describe('processTokens', () => {
it('returns for input containing only search value', () => { it('returns for input containing only search value', () => {
const results = gl.FilteredSearchTokenizer.processTokens('searchTerm'); const results = gl.FilteredSearchTokenizer.processTokens('searchTerm');
...@@ -131,5 +130,4 @@ require('~/filtered_search/filtered_search_tokenizer'); ...@@ -131,5 +130,4 @@ require('~/filtered_search/filtered_search_tokenizer');
expect(results.tokens[0].symbol).toBe('~'); expect(results.tokens[0].symbol).toBe('~');
}); });
}); });
}); });
})();
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