diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-21 09:12:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-21 09:12:30 +0300 |
commit | b86ad5f488abdef5b568d000dd44cf174abbf4fc (patch) | |
tree | 54af0029bb29e81f30a050674a1b123ac2664e73 /app | |
parent | b82d69110784e196facfbe3f8dfc8111393a5dac (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
8 files changed, 33 insertions, 7 deletions
diff --git a/app/assets/javascripts/search/sidebar/components/app.vue b/app/assets/javascripts/search/sidebar/components/app.vue index 99cf16c8350..40b6e11577a 100644 --- a/app/assets/javascripts/search/sidebar/components/app.vue +++ b/app/assets/javascripts/search/sidebar/components/app.vue @@ -13,7 +13,7 @@ export default { ConfidentialityFilter, }, computed: { - ...mapState(['query']), + ...mapState(['query', 'sidebarDirty']), showReset() { return this.query.state || this.query.confidential; }, @@ -32,7 +32,7 @@ export default { <status-filter /> <confidentiality-filter /> <div class="gl-display-flex gl-align-items-center gl-mt-3"> - <gl-button category="primary" variant="confirm" size="small" type="submit"> + <gl-button category="primary" variant="confirm" type="submit" :disabled="!sidebarDirty"> {{ __('Apply') }} </gl-button> <gl-link v-if="showReset" class="gl-ml-auto" @click="resetQuery">{{ diff --git a/app/assets/javascripts/search/sidebar/constants/state_filter_data.js b/app/assets/javascripts/search/sidebar/constants/state_filter_data.js index 7c9a029ffe4..2f9f8a7cb46 100644 --- a/app/assets/javascripts/search/sidebar/constants/state_filter_data.js +++ b/app/assets/javascripts/search/sidebar/constants/state_filter_data.js @@ -5,7 +5,7 @@ const header = __('Status'); const filters = { ANY: { label: __('Any'), - value: 'all', + value: null, }, OPEN: { label: __('Open'), diff --git a/app/assets/javascripts/search/store/actions.js b/app/assets/javascripts/search/store/actions.js index be64a9278e3..a6af5644681 100644 --- a/app/assets/javascripts/search/store/actions.js +++ b/app/assets/javascripts/search/store/actions.js @@ -2,9 +2,9 @@ import Api from '~/api'; import createFlash from '~/flash'; import { visitUrl, setUrlParams } from '~/lib/utils/url_utility'; import { __ } from '~/locale'; -import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from './constants'; +import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, SIDEBAR_PARAMS } from './constants'; import * as types from './mutation_types'; -import { loadDataFromLS, setFrequentItemToLS, mergeById } from './utils'; +import { loadDataFromLS, setFrequentItemToLS, mergeById, isSidebarDirty } from './utils'; export const fetchGroups = ({ commit }, search) => { commit(types.REQUEST_GROUPS); @@ -86,8 +86,12 @@ export const setFrequentProject = ({ state, commit }, item) => { commit(types.LOAD_FREQUENT_ITEMS, { key: PROJECTS_LOCAL_STORAGE_KEY, data: frequentItems }); }; -export const setQuery = ({ commit }, { key, value }) => { +export const setQuery = ({ state, commit }, { key, value }) => { commit(types.SET_QUERY, { key, value }); + + if (SIDEBAR_PARAMS.includes(key)) { + commit(types.SET_SIDEBAR_DIRTY, isSidebarDirty(state.query, state.urlQuery)); + } }; export const applyQuery = ({ state }) => { diff --git a/app/assets/javascripts/search/store/constants.js b/app/assets/javascripts/search/store/constants.js index 3abf7cac6ba..678bd82c7a6 100644 --- a/app/assets/javascripts/search/store/constants.js +++ b/app/assets/javascripts/search/store/constants.js @@ -1,3 +1,6 @@ +import { stateFilterData } from '~/search/sidebar/constants/state_filter_data'; +import { confidentialFilterData } from '~/search/sidebar/constants/confidential_filter_data'; + export const MAX_FREQUENT_ITEMS = 5; export const MAX_FREQUENCY = 5; @@ -5,3 +8,5 @@ export const MAX_FREQUENCY = 5; export const GROUPS_LOCAL_STORAGE_KEY = 'global-search-frequent-groups'; export const PROJECTS_LOCAL_STORAGE_KEY = 'global-search-frequent-projects'; + +export const SIDEBAR_PARAMS = [stateFilterData.filterParam, confidentialFilterData.filterParam]; diff --git a/app/assets/javascripts/search/store/mutation_types.js b/app/assets/javascripts/search/store/mutation_types.js index 5c1c29dc738..bf1e3e79cba 100644 --- a/app/assets/javascripts/search/store/mutation_types.js +++ b/app/assets/javascripts/search/store/mutation_types.js @@ -7,5 +7,6 @@ export const RECEIVE_PROJECTS_SUCCESS = 'RECEIVE_PROJECTS_SUCCESS'; export const RECEIVE_PROJECTS_ERROR = 'RECEIVE_PROJECTS_ERROR'; export const SET_QUERY = 'SET_QUERY'; +export const SET_SIDEBAR_DIRTY = 'SET_SIDEBAR_DIRTY'; export const LOAD_FREQUENT_ITEMS = 'LOAD_FREQUENT_ITEMS'; diff --git a/app/assets/javascripts/search/store/mutations.js b/app/assets/javascripts/search/store/mutations.js index 63156a89738..5d154fe3aa0 100644 --- a/app/assets/javascripts/search/store/mutations.js +++ b/app/assets/javascripts/search/store/mutations.js @@ -26,6 +26,9 @@ export default { [types.SET_QUERY](state, { key, value }) { state.query[key] = value; }, + [types.SET_SIDEBAR_DIRTY](state, value) { + state.sidebarDirty = value; + }, [types.LOAD_FREQUENT_ITEMS](state, { key, data }) { state.frequentItems[key] = data; }, diff --git a/app/assets/javascripts/search/store/state.js b/app/assets/javascripts/search/store/state.js index 5b1429ccc97..d4005697f35 100644 --- a/app/assets/javascripts/search/store/state.js +++ b/app/assets/javascripts/search/store/state.js @@ -1,6 +1,8 @@ +import { cloneDeep } from 'lodash'; import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from './constants'; const createState = ({ query }) => ({ + urlQuery: cloneDeep(query), query, groups: [], fetchingGroups: false, @@ -10,5 +12,6 @@ const createState = ({ query }) => ({ [GROUPS_LOCAL_STORAGE_KEY]: [], [PROJECTS_LOCAL_STORAGE_KEY]: [], }, + sidebarDirty: false, }); export default createState; diff --git a/app/assets/javascripts/search/store/utils.js b/app/assets/javascripts/search/store/utils.js index b00b9bb0f2e..6b56ff0b5e5 100644 --- a/app/assets/javascripts/search/store/utils.js +++ b/app/assets/javascripts/search/store/utils.js @@ -1,5 +1,5 @@ import AccessorUtilities from '../../lib/utils/accessor'; -import { MAX_FREQUENT_ITEMS, MAX_FREQUENCY } from './constants'; +import { MAX_FREQUENT_ITEMS, MAX_FREQUENCY, SIDEBAR_PARAMS } from './constants'; function extractKeys(object, keyList) { return Object.fromEntries(keyList.map((key) => [key, object[key]])); @@ -80,3 +80,13 @@ export const mergeById = (inflatedData, storedData) => { return { ...stored, ...data }; }); }; + +export const isSidebarDirty = (currentQuery, urlQuery) => { + return SIDEBAR_PARAMS.some((param) => { + // userAddParam ensures we don't get a false dirty from null !== undefined + const userAddedParam = !urlQuery[param] && currentQuery[param]; + const userChangedExistingParam = urlQuery[param] && urlQuery[param] !== currentQuery[param]; + + return userAddedParam || userChangedExistingParam; + }); +}; |