summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/search_settings/components/search_settings.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/search_settings/components/search_settings.vue')
-rw-r--r--app/assets/javascripts/search_settings/components/search_settings.vue52
1 files changed, 39 insertions, 13 deletions
diff --git a/app/assets/javascripts/search_settings/components/search_settings.vue b/app/assets/javascripts/search_settings/components/search_settings.vue
index 820055dc656..116967a62c8 100644
--- a/app/assets/javascripts/search_settings/components/search_settings.vue
+++ b/app/assets/javascripts/search_settings/components/search_settings.vue
@@ -3,20 +3,37 @@ import { GlSearchBoxByType } from '@gitlab/ui';
import { uniq } from 'lodash';
import { EXCLUDED_NODES, HIDE_CLASS, HIGHLIGHT_CLASS, TYPING_DELAY } from '../constants';
+const origExpansions = new Map();
+
const findSettingsSection = (sectionSelector, node) => {
return node.parentElement.closest(sectionSelector);
};
-const resetSections = ({ sectionSelector, expandSection, collapseSection }) => {
- document.querySelectorAll(sectionSelector).forEach((section, index) => {
- section.classList.remove(HIDE_CLASS);
-
- if (index === 0) {
+const restoreExpansionState = ({ expandSection, collapseSection }) => {
+ origExpansions.forEach((isExpanded, section) => {
+ if (isExpanded) {
expandSection(section);
} else {
collapseSection(section);
}
});
+
+ origExpansions.clear();
+};
+
+const saveExpansionState = (sections, { isExpanded }) => {
+ // If we've saved expansions before, don't override it.
+ if (origExpansions.size > 0) {
+ return;
+ }
+
+ sections.forEach((section) => origExpansions.set(section, isExpanded(section)));
+};
+
+const resetSections = ({ sectionSelector }) => {
+ document.querySelectorAll(sectionSelector).forEach((section) => {
+ section.classList.remove(HIDE_CLASS);
+ });
};
const clearHighlights = () => {
@@ -85,6 +102,12 @@ export default {
type: String,
required: true,
},
+ isExpandedFn: {
+ type: Function,
+ required: false,
+ // default to a function that returns false
+ default: () => () => false,
+ },
},
data() {
return {
@@ -97,6 +120,7 @@ export default {
sectionSelector: this.sectionSelector,
expandSection: this.expandSection,
collapseSection: this.collapseSection,
+ isExpanded: this.isExpandedFn,
};
this.searchTerm = value;
@@ -104,7 +128,11 @@ export default {
clearResults(displayOptions);
if (value.length) {
+ saveExpansionState(document.querySelectorAll(this.sectionSelector), displayOptions);
+
displayResults(displayOptions, search(this.searchRoot, value));
+ } else {
+ restoreExpansionState(displayOptions);
}
},
expandSection(section) {
@@ -118,12 +146,10 @@ export default {
};
</script>
<template>
- <div class="gl-mt-5">
- <gl-search-box-by-type
- :value="searchTerm"
- :debounce="$options.TYPING_DELAY"
- :placeholder="__('Search settings')"
- @input="search"
- />
- </div>
+ <gl-search-box-by-type
+ :value="searchTerm"
+ :debounce="$options.TYPING_DELAY"
+ :placeholder="__('Search settings')"
+ @input="search"
+ />
</template>