From a5ab3467a705b62911feacc3cf627fdbb00aa198 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 13 Jan 2020 15:07:53 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../registry/settings/components/settings_form.vue | 84 +++++++++++++--------- .../javascripts/registry/settings/store/getters.js | 8 +++ .../javascripts/registry/settings/store/index.js | 2 + .../registry/settings/store/mutations.js | 5 ++ .../javascripts/registry/settings/store/state.js | 4 ++ app/assets/javascripts/registry/settings/utils.js | 6 ++ 6 files changed, 77 insertions(+), 32 deletions(-) create mode 100644 app/assets/javascripts/registry/settings/store/getters.js create mode 100644 app/assets/javascripts/registry/settings/utils.js (limited to 'app/assets/javascripts/registry') diff --git a/app/assets/javascripts/registry/settings/components/settings_form.vue b/app/assets/javascripts/registry/settings/components/settings_form.vue index 402763e2e21..55a6a1ace55 100644 --- a/app/assets/javascripts/registry/settings/components/settings_form.vue +++ b/app/assets/javascripts/registry/settings/components/settings_form.vue @@ -1,6 +1,6 @@ diff --git a/app/assets/javascripts/registry/settings/store/getters.js b/app/assets/javascripts/registry/settings/store/getters.js new file mode 100644 index 00000000000..fc32a9f08e4 --- /dev/null +++ b/app/assets/javascripts/registry/settings/store/getters.js @@ -0,0 +1,8 @@ +import { findDefaultOption } from '../utils'; + +export const getCadence = state => + state.settings.cadence || findDefaultOption(state.formOptions.cadence); +export const getKeepN = state => + state.settings.keep_n || findDefaultOption(state.formOptions.keepN); +export const getOlderThan = state => + state.settings.older_than || findDefaultOption(state.formOptions.olderThan); diff --git a/app/assets/javascripts/registry/settings/store/index.js b/app/assets/javascripts/registry/settings/store/index.js index 91a35aac149..c2500454d8e 100644 --- a/app/assets/javascripts/registry/settings/store/index.js +++ b/app/assets/javascripts/registry/settings/store/index.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import Vuex from 'vuex'; import * as actions from './actions'; import mutations from './mutations'; +import * as getters from './getters'; import state from './state'; Vue.use(Vuex); @@ -11,6 +12,7 @@ export const createStore = () => state, actions, mutations, + getters, }); export default createStore(); diff --git a/app/assets/javascripts/registry/settings/store/mutations.js b/app/assets/javascripts/registry/settings/store/mutations.js index b8384fd4a45..25a67cc6973 100644 --- a/app/assets/javascripts/registry/settings/store/mutations.js +++ b/app/assets/javascripts/registry/settings/store/mutations.js @@ -3,6 +3,11 @@ import * as types from './mutation_types'; export default { [types.SET_INITIAL_STATE](state, initialState) { state.projectId = initialState.projectId; + state.formOptions = { + cadence: JSON.parse(initialState.cadenceOptions), + keepN: JSON.parse(initialState.keepNOptions), + olderThan: JSON.parse(initialState.olderThanOptions), + }; }, [types.UPDATE_SETTINGS](state, settings) { state.settings = { ...state.settings, ...settings }; diff --git a/app/assets/javascripts/registry/settings/store/state.js b/app/assets/javascripts/registry/settings/store/state.js index c3a26083c9f..50c882e1839 100644 --- a/app/assets/javascripts/registry/settings/store/state.js +++ b/app/assets/javascripts/registry/settings/store/state.js @@ -23,4 +23,8 @@ export default () => ({ * Same structure as settings, above but Frozen object and used only in case the user clicks 'cancel' */ original: {}, + /* + * Contains the options used to populate the form selects + */ + formOptions: {}, }); diff --git a/app/assets/javascripts/registry/settings/utils.js b/app/assets/javascripts/registry/settings/utils.js new file mode 100644 index 00000000000..75af401e96d --- /dev/null +++ b/app/assets/javascripts/registry/settings/utils.js @@ -0,0 +1,6 @@ +export const findDefaultOption = options => { + const item = options.find(o => o.default); + return item ? item.key : null; +}; + +export default () => {}; -- cgit v1.2.1