diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-11 00:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-11 00:09:24 +0300 |
commit | 02c3b2af448be6a5004e8d833cbcbf8e5f185210 (patch) | |
tree | 27359dc5c21a8901c9eb95a0101cb97087b1f4ac /app/assets/javascripts/search_settings | |
parent | 577bb49691b11bc8ebae3a4966153ed39af60d87 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/search_settings')
-rw-r--r-- | app/assets/javascripts/search_settings/components/search_settings.vue | 38 | ||||
-rw-r--r-- | app/assets/javascripts/search_settings/mount.js | 8 |
2 files changed, 37 insertions, 9 deletions
diff --git a/app/assets/javascripts/search_settings/components/search_settings.vue b/app/assets/javascripts/search_settings/components/search_settings.vue index de8ec57e255..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) { diff --git a/app/assets/javascripts/search_settings/mount.js b/app/assets/javascripts/search_settings/mount.js index 9c0bc403fe9..260c793a769 100644 --- a/app/assets/javascripts/search_settings/mount.js +++ b/app/assets/javascripts/search_settings/mount.js @@ -1,6 +1,5 @@ import Vue from 'vue'; -import $ from 'jquery'; -import { expandSection, closeSection } from '~/settings_panels'; +import { expandSection, closeSection, isExpanded } from '~/settings_panels'; import SearchSettings from '~/search_settings/components/search_settings.vue'; const mountSearch = ({ el }) => @@ -12,10 +11,11 @@ const mountSearch = ({ el }) => props: { searchRoot: document.querySelector('#content-body'), sectionSelector: '.js-search-settings-section, section.settings', + isExpandedFn: isExpanded, }, on: { - collapse: (section) => closeSection($(section)), - expand: (section) => expandSection($(section)), + collapse: closeSection, + expand: expandSection, }, }), }); |