Commit ceb79e3c authored by Clement Ho's avatar Clement Ho

Reset filters after clear search

parent bbad61b9
...@@ -71,6 +71,20 @@ ...@@ -71,6 +71,20 @@
this.unbindEvents(); this.unbindEvents();
} }
show() {
const currentHook = this.getCurrentHook();
if (currentHook) {
currentHook.list.show();
}
}
hide() {
const currentHook = this.getCurrentHook();
if (currentHook) {
currentHook.list.hide();
}
}
dismissDropdown() { dismissDropdown() {
this.input.focus(); this.input.focus();
// Propogate input change to FilteredSearchManager // Propogate input change to FilteredSearchManager
...@@ -104,7 +118,7 @@ ...@@ -104,7 +118,7 @@
droplab.setConfig(this.getFilterConfig(this.filterKeyword)); droplab.setConfig(this.getFilterConfig(this.filterKeyword));
} }
render() { render(hide) {
this.setAsDropdown(); this.setAsDropdown();
const firstTimeInitialized = this.getCurrentHook() === undefined; const firstTimeInitialized = this.getCurrentHook() === undefined;
...@@ -115,6 +129,28 @@ ...@@ -115,6 +129,28 @@
droplab.changeHookList(this.hookId, `#${this.listId}`); droplab.changeHookList(this.hookId, `#${this.listId}`);
this.renderContent(); this.renderContent();
} }
if (hide) {
this.hide();
} else {
this.show();
}
}
resetFilters() {
const currentHook = this.getCurrentHook();
if (currentHook) {
const list = currentHook.list;
if (list.data) {
const data = list.data.map((item) => {
item.droplab_hidden = false;
});
list.render(data);
}
}
} }
} }
......
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
((global) => { ((global) => {
function clearSearch(e) {
e.stopPropagation();
e.preventDefault();
document.querySelector('.filtered-search').value = '';
document.querySelector('.clear-search').classList.add('hidden');
}
function toggleClearSearchButton(e) { function toggleClearSearchButton(e) {
const clearSearchButton = document.querySelector('.clear-search'); const clearSearchButton = document.querySelector('.clear-search');
...@@ -170,7 +162,13 @@ ...@@ -170,7 +162,13 @@
dropdownHint = new gl.DropdownHint(document.querySelector('#js-dropdown-hint'), filteredSearch, this.currentDropdown); dropdownHint = new gl.DropdownHint(document.querySelector('#js-dropdown-hint'), filteredSearch, this.currentDropdown);
} }
dropdownHint.setOffset(dropdownOffset); dropdownHint.setOffset(dropdownOffset);
dropdownHint.render(); dropdownHint.render(hideDropdown);
}
}
dismissCurrentDropdown() {
if (this.currentDropdown === 'hint') {
dropdownHint.destroy();
} }
} }
...@@ -198,7 +196,17 @@ ...@@ -198,7 +196,17 @@
filteredSearchInput.addEventListener('input', this.setDropdown.bind(this)); filteredSearchInput.addEventListener('input', this.setDropdown.bind(this));
filteredSearchInput.addEventListener('input', toggleClearSearchButton); filteredSearchInput.addEventListener('input', toggleClearSearchButton);
filteredSearchInput.addEventListener('keydown', this.checkForEnter.bind(this)); filteredSearchInput.addEventListener('keydown', this.checkForEnter.bind(this));
document.querySelector('.clear-search').addEventListener('click', clearSearch); document.querySelector('.clear-search').addEventListener('click', this.clearSearch.bind(this));
}
clearSearch(e) {
e.stopPropagation();
e.preventDefault();
document.querySelector('.filtered-search').value = '';
document.querySelector('.clear-search').classList.add('hidden');
dropdownHint.resetFilters();
this.loadDropdown('hint', true);
} }
checkDropdownToken(e) { checkDropdownToken(e) {
...@@ -208,7 +216,6 @@ ...@@ -208,7 +216,6 @@
// Check for dropdown token // Check for dropdown token
if (lastToken[lastToken.length - 1] === ':') { if (lastToken[lastToken.length - 1] === ':') {
const token = lastToken.slice(0, -1); const token = lastToken.slice(0, -1);
} }
} }
......
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