summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-03 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-03 09:08:42 +0000
commitf14507e586a7f75f0fb71a1d8468b7361be860d4 (patch)
treea8aa547b517a7ae5626c902bfb558c1fc5386c4e /app/assets/javascripts/registry/settings
parentf4d27d532e3abeecd1caffeb3a56e698ae982e5b (diff)
downloadgitlab-ce-f14507e586a7f75f0fb71a1d8468b7361be860d4.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/registry/settings')
-rw-r--r--app/assets/javascripts/registry/settings/components/registry_settings_app.vue2
-rw-r--r--app/assets/javascripts/registry/settings/components/settings_form.vue207
-rw-r--r--app/assets/javascripts/registry/settings/constants.js15
-rw-r--r--app/assets/javascripts/registry/settings/store/getters.js13
-rw-r--r--app/assets/javascripts/registry/settings/store/mutations.js4
-rw-r--r--app/assets/javascripts/registry/settings/utils.js6
6 files changed, 27 insertions, 220 deletions
diff --git a/app/assets/javascripts/registry/settings/components/registry_settings_app.vue b/app/assets/javascripts/registry/settings/components/registry_settings_app.vue
index 28f4ef62242..2156c4469da 100644
--- a/app/assets/javascripts/registry/settings/components/registry_settings_app.vue
+++ b/app/assets/javascripts/registry/settings/components/registry_settings_app.vue
@@ -3,7 +3,7 @@ import { mapActions, mapState } from 'vuex';
import { GlAlert } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale';
-import { FETCH_SETTINGS_ERROR_MESSAGE } from '../constants';
+import { FETCH_SETTINGS_ERROR_MESSAGE } from '../../shared/constants';
import SettingsForm from './settings_form.vue';
diff --git a/app/assets/javascripts/registry/settings/components/settings_form.vue b/app/assets/javascripts/registry/settings/components/settings_form.vue
index 6a617f97271..ad2fdb4fd40 100644
--- a/app/assets/javascripts/registry/settings/components/settings_form.vue
+++ b/app/assets/javascripts/registry/settings/components/settings_form.vue
@@ -1,32 +1,16 @@
<script>
import { mapActions, mapState, mapGetters } from 'vuex';
-import {
- GlFormGroup,
- GlToggle,
- GlFormSelect,
- GlFormTextarea,
- GlButton,
- GlCard,
- GlLoadingIcon,
-} from '@gitlab/ui';
-import { s__, __, sprintf } from '~/locale';
import Tracking from '~/tracking';
import {
- NAME_REGEX_LENGTH,
UPDATE_SETTINGS_ERROR_MESSAGE,
UPDATE_SETTINGS_SUCCESS_MESSAGE,
-} from '../constants';
+} from '../../shared/constants';
import { mapComputed } from '~/vuex_shared/bindings';
+import ExpirationPolicyForm from '../../shared/components/expiration_policy_form.vue';
export default {
components: {
- GlFormGroup,
- GlToggle,
- GlFormSelect,
- GlFormTextarea,
- GlButton,
- GlCard,
- GlLoadingIcon,
+ ExpirationPolicyForm,
},
mixins: [Tracking.mixin()],
labelsConfig: {
@@ -43,59 +27,7 @@ export default {
computed: {
...mapState(['formOptions', 'isLoading']),
...mapGetters({ isEdited: 'getIsEdited' }),
- ...mapComputed(
- [
- 'enabled',
- { key: 'cadence', getter: 'getCadence' },
- { key: 'older_than', getter: 'getOlderThan' },
- { key: 'keep_n', getter: 'getKeepN' },
- 'name_regex',
- ],
- 'updateSettings',
- 'settings',
- ),
- policyEnabledText() {
- return this.enabled ? __('enabled') : __('disabled');
- },
- toggleDescriptionText() {
- return sprintf(
- s__('ContainerRegistry|Docker tag expiration policy is %{toggleStatus}'),
- {
- toggleStatus: `<strong>${this.policyEnabledText}</strong>`,
- },
- false,
- );
- },
- regexHelpText() {
- return sprintf(
- s__(
- 'ContainerRegistry|Wildcards such as %{codeStart}*-stable%{codeEnd} or %{codeStart}production/*%{codeEnd} are supported. To select all tags, use %{codeStart}.*%{codeEnd}',
- ),
- {
- codeStart: '<code>',
- codeEnd: '</code>',
- },
- false,
- );
- },
- nameRegexPlaceholder() {
- return '.*';
- },
- nameRegexState() {
- return this.name_regex ? this.name_regex.length <= NAME_REGEX_LENGTH : null;
- },
- formIsInvalid() {
- return this.nameRegexState === false;
- },
- isFormElementDisabled() {
- return !this.enabled || this.isLoading;
- },
- isSubmitButtonDisabled() {
- return this.formIsInvalid || this.isLoading;
- },
- isCancelButtonDisabled() {
- return !this.isEdited || this.isLoading;
- },
+ ...mapComputed([{ key: 'settings', getter: 'getSettings' }], 'updateSettings'),
},
methods: {
...mapActions(['resetSettings', 'saveSettings']),
@@ -114,127 +46,12 @@ export default {
</script>
<template>
- <form ref="form-element" @submit.prevent="submit" @reset.prevent="reset">
- <gl-card>
- <template #header>
- {{ s__('ContainerRegistry|Tag expiration policy') }}
- </template>
- <template>
- <gl-form-group
- id="expiration-policy-toggle-group"
- :label-cols="$options.labelsConfig.cols"
- :label-align="$options.labelsConfig.align"
- label-for="expiration-policy-toggle"
- :label="s__('ContainerRegistry|Expiration policy:')"
- >
- <div class="d-flex align-items-start">
- <gl-toggle id="expiration-policy-toggle" v-model="enabled" :disabled="isLoading" />
- <span class="mb-2 ml-1 lh-2" v-html="toggleDescriptionText"></span>
- </div>
- </gl-form-group>
-
- <gl-form-group
- id="expiration-policy-interval-group"
- :label-cols="$options.labelsConfig.cols"
- :label-align="$options.labelsConfig.align"
- label-for="expiration-policy-interval"
- :label="s__('ContainerRegistry|Expiration interval:')"
- >
- <gl-form-select
- id="expiration-policy-interval"
- v-model="older_than"
- :disabled="isFormElementDisabled"
- >
- <option v-for="option in formOptions.olderThan" :key="option.key" :value="option.key">
- {{ option.label }}
- </option>
- </gl-form-select>
- </gl-form-group>
-
- <gl-form-group
- id="expiration-policy-schedule-group"
- :label-cols="$options.labelsConfig.cols"
- :label-align="$options.labelsConfig.align"
- label-for="expiration-policy-schedule"
- :label="s__('ContainerRegistry|Expiration schedule:')"
- >
- <gl-form-select
- id="expiration-policy-schedule"
- v-model="cadence"
- :disabled="isFormElementDisabled"
- >
- <option v-for="option in formOptions.cadence" :key="option.key" :value="option.key">
- {{ option.label }}
- </option>
- </gl-form-select>
- </gl-form-group>
-
- <gl-form-group
- id="expiration-policy-latest-group"
- :label-cols="$options.labelsConfig.cols"
- :label-align="$options.labelsConfig.align"
- label-for="expiration-policy-latest"
- :label="s__('ContainerRegistry|Number of tags to retain:')"
- >
- <gl-form-select
- id="expiration-policy-latest"
- v-model="keep_n"
- :disabled="isFormElementDisabled"
- >
- <option v-for="option in formOptions.keepN" :key="option.key" :value="option.key">
- {{ option.label }}
- </option>
- </gl-form-select>
- </gl-form-group>
-
- <gl-form-group
- id="expiration-policy-name-matching-group"
- :label-cols="$options.labelsConfig.cols"
- :label-align="$options.labelsConfig.align"
- label-for="expiration-policy-name-matching"
- :label="
- s__('ContainerRegistry|Docker tags with names matching this regex pattern will expire:')
- "
- :state="nameRegexState"
- :invalid-feedback="
- s__('ContainerRegistry|The value of this input should be less than 255 characters')
- "
- >
- <gl-form-textarea
- id="expiration-policy-name-matching"
- v-model="name_regex"
- :placeholder="nameRegexPlaceholder"
- :state="nameRegexState"
- :disabled="isFormElementDisabled"
- trim
- />
- <template #description>
- <span ref="regex-description" v-html="regexHelpText"></span>
- </template>
- </gl-form-group>
- </template>
- <template #footer>
- <div class="d-flex justify-content-end">
- <gl-button
- ref="cancel-button"
- type="reset"
- :disabled="isCancelButtonDisabled"
- class="mr-2 d-block"
- >
- {{ __('Cancel') }}
- </gl-button>
- <gl-button
- ref="save-button"
- type="submit"
- :disabled="isSubmitButtonDisabled"
- variant="success"
- class="d-flex justify-content-center align-items-center js-no-auto-disable"
- >
- {{ __('Save expiration policy') }}
- <gl-loading-icon v-if="isLoading" class="ml-2" />
- </gl-button>
- </div>
- </template>
- </gl-card>
- </form>
+ <expiration-policy-form
+ v-model="settings"
+ :form-options="formOptions"
+ :is-loading="isLoading"
+ :disable-cancel-button="!isEdited"
+ @submit="submit"
+ @reset="reset"
+ />
</template>
diff --git a/app/assets/javascripts/registry/settings/constants.js b/app/assets/javascripts/registry/settings/constants.js
deleted file mode 100644
index c0dac466b29..00000000000
--- a/app/assets/javascripts/registry/settings/constants.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import { s__ } from '~/locale';
-
-export const FETCH_SETTINGS_ERROR_MESSAGE = s__(
- 'ContainerRegistry|Something went wrong while fetching the expiration policy.',
-);
-
-export const UPDATE_SETTINGS_ERROR_MESSAGE = s__(
- 'ContainerRegistry|Something went wrong while updating the expiration policy.',
-);
-
-export const UPDATE_SETTINGS_SUCCESS_MESSAGE = s__(
- 'ContainerRegistry|Expiration policy successfully saved.',
-);
-
-export const NAME_REGEX_LENGTH = 255;
diff --git a/app/assets/javascripts/registry/settings/store/getters.js b/app/assets/javascripts/registry/settings/store/getters.js
index cd6392bd0cc..639becebeec 100644
--- a/app/assets/javascripts/registry/settings/store/getters.js
+++ b/app/assets/javascripts/registry/settings/store/getters.js
@@ -1,10 +1,21 @@
import { isEqual } from 'lodash';
-import { findDefaultOption } from '../utils';
+import { findDefaultOption } from '../../shared/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);
+
+export const getSettings = (state, getters) => ({
+ enabled: state.settings.enabled,
+ cadence: getters.getCadence,
+ older_than: getters.getOlderThan,
+ keep_n: getters.getKeepN,
+ name_regex: state.settings.name_regex,
+});
+
export const getIsEdited = state => !isEqual(state.original, state.settings);
diff --git a/app/assets/javascripts/registry/settings/store/mutations.js b/app/assets/javascripts/registry/settings/store/mutations.js
index b773f2dd44c..f562137db1a 100644
--- a/app/assets/javascripts/registry/settings/store/mutations.js
+++ b/app/assets/javascripts/registry/settings/store/mutations.js
@@ -9,8 +9,8 @@ export default {
olderThan: JSON.parse(initialState.olderThanOptions),
};
},
- [types.UPDATE_SETTINGS](state, settings) {
- state.settings = { ...state.settings, ...settings };
+ [types.UPDATE_SETTINGS](state, data) {
+ state.settings = { ...state.settings, ...data.settings };
},
[types.SET_SETTINGS](state, settings) {
state.settings = settings;
diff --git a/app/assets/javascripts/registry/settings/utils.js b/app/assets/javascripts/registry/settings/utils.js
deleted file mode 100644
index 75af401e96d..00000000000
--- a/app/assets/javascripts/registry/settings/utils.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export const findDefaultOption = options => {
- const item = options.find(o => o.default);
- return item ? item.key : null;
-};
-
-export default () => {};