From 48aff82709769b098321c738f3444b9bdaa694c6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 21 Oct 2020 07:08:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-5-stable-ee --- .../components/alerts_integrations_list.vue | 109 +++++++++++++ .../components/alerts_settings_form.vue | 179 ++++++++++----------- .../javascripts/alerts_settings/constants.js | 24 ++- 3 files changed, 210 insertions(+), 102 deletions(-) create mode 100644 app/assets/javascripts/alerts_settings/components/alerts_integrations_list.vue (limited to 'app/assets/javascripts/alerts_settings') diff --git a/app/assets/javascripts/alerts_settings/components/alerts_integrations_list.vue b/app/assets/javascripts/alerts_settings/components/alerts_integrations_list.vue new file mode 100644 index 00000000000..217442e6131 --- /dev/null +++ b/app/assets/javascripts/alerts_settings/components/alerts_integrations_list.vue @@ -0,0 +1,109 @@ + + + diff --git a/app/assets/javascripts/alerts_settings/components/alerts_settings_form.vue b/app/assets/javascripts/alerts_settings/components/alerts_settings_form.vue index f0bb8b0a90f..f885afae378 100644 --- a/app/assets/javascripts/alerts_settings/components/alerts_settings_form.vue +++ b/app/assets/javascripts/alerts_settings/components/alerts_settings_form.vue @@ -14,9 +14,11 @@ import { GlFormSelect, } from '@gitlab/ui'; import { debounce } from 'lodash'; -import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; +import { s__ } from '~/locale'; +import { doesHashExistInUrl } from '~/lib/utils/url_utility'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ToggleButton from '~/vue_shared/components/toggle_button.vue'; +import IntegrationsList from './alerts_integrations_list.vue'; import csrf from '~/lib/utils/csrf'; import service from '../services'; import { @@ -25,7 +27,9 @@ import { JSON_VALIDATE_DELAY, targetPrometheusUrlPlaceholder, targetOpsgenieUrlPlaceholder, + sectionHash, } from '../constants'; +import createFlash, { FLASH_TYPES } from '~/flash'; export default { i18n, @@ -46,11 +50,11 @@ export default { GlSprintf, ClipboardButton, ToggleButton, + IntegrationsList, }, directives: { 'gl-modal': GlModalDirective, }, - mixins: [glFeatureFlagsMixin()], inject: ['prometheus', 'generic', 'opsgenie'], data() { return { @@ -148,6 +152,20 @@ export default { ? this.$options.targetOpsgenieUrlPlaceholder : this.$options.targetPrometheusUrlPlaceholder; }, + integrations() { + return [ + { + name: s__('AlertSettings|HTTP endpoint'), + type: s__('AlertsIntegrations|HTTP endpoint'), + activated: this.generic.activated, + }, + { + name: s__('AlertSettings|External Prometheus'), + type: s__('AlertsIntegrations|Prometheus'), + activated: this.prometheus.activated, + }, + ]; + }, }, watch: { 'testAlert.json': debounce(function debouncedJsonValidate() { @@ -173,9 +191,12 @@ export default { this.authKey = this.selectedService.authKey ?? ''; }, methods: { - createUserErrorMessage(errors = { error: [''] }) { - // eslint-disable-next-line prefer-destructuring - this.serverError = errors.error[0]; + createUserErrorMessage(errors = {}) { + const error = Object.entries(errors)?.[0]; + if (error) { + const [field, [msg]] = error; + this.serverError = `${field} ${msg}`; + } }, setOpsgenieAsDefault() { this.options = this.options.map(el => { @@ -245,29 +266,11 @@ export default { ? { service: { opsgenie_mvc_target_url: this.targetUrl, opsgenie_mvc_enabled: value } } : { service: { active: value } }, }) - .then(() => { - this.active = value; - this.toggleSuccess(value); - - if (!this.isOpsgenie && value) { - if (!this.selectedService.authKey) { - return window.location.reload(); - } - - return this.removeOpsGenieOption(); - } - - if (this.isOpsgenie && value) { - return this.setOpsgenieAsDefault(); - } - - // eslint-disable-next-line no-return-assign - return (this.options = serviceOptions); - }) + .then(() => this.notifySuccessAndReload()) .catch(({ response: { data: { errors } = {} } = {} }) => { this.createUserErrorMessage(errors); this.setFeedback({ - feedbackMessage: `${this.$options.i18n.errorMsg}.`, + feedbackMessage: this.$options.i18n.errorMsg, variant: 'danger', }); }) @@ -276,6 +279,12 @@ export default { this.canSaveForm = false; }); }, + reload() { + if (!doesHashExistInUrl(sectionHash)) { + window.location.hash = sectionHash; + } + window.location.reload(); + }, togglePrometheusActive(value) { this.loading = true; return service @@ -288,15 +297,11 @@ export default { redirect: window.location, }, }) - .then(() => { - this.active = value; - this.toggleSuccess(value); - this.removeOpsGenieOption(); - }) + .then(() => this.notifySuccessAndReload()) .catch(({ response: { data: { errors } = {} } = {} }) => { this.createUserErrorMessage(errors); this.setFeedback({ - feedbackMessage: `${this.$options.i18n.errorMsg}.`, + feedbackMessage: this.$options.i18n.errorMsg, variant: 'danger', }); }) @@ -305,18 +310,9 @@ export default { this.canSaveForm = false; }); }, - toggleSuccess(value) { - if (value) { - this.setFeedback({ - feedbackMessage: this.$options.i18n.endPointActivated, - variant: 'info', - }); - } else { - this.setFeedback({ - feedbackMessage: this.$options.i18n.changesSaved, - variant: 'info', - }); - } + notifySuccessAndReload() { + createFlash({ message: this.$options.i18n.changesSaved, type: FLASH_TYPES.NOTICE }); + setTimeout(() => this.reload(), 1000); }, setFeedback({ feedbackMessage, variant }) { this.feedback = { feedbackMessage, variant }; @@ -375,47 +371,50 @@ export default {