diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/assets/javascripts/search_settings/components/search_settings.vue | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/assets/javascripts/search_settings/components/search_settings.vue')
-rw-r--r-- | app/assets/javascripts/search_settings/components/search_settings.vue | 52 |
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> |