debian-mirror-gitlab/app/assets/javascripts/environments/components/canary_update_modal.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

134 lines
3.8 KiB
Vue
Raw Normal View History

2021-03-08 18:12:59 +05:30
<script>
import { GlAlert, GlModal, GlSprintf } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { CANARY_UPDATE_MODAL } from '../constants';
2021-03-11 19:13:27 +05:30
import updateCanaryIngress from '../graphql/mutations/update_canary_ingress.mutation.graphql';
2021-03-08 18:12:59 +05:30
export default {
components: {
GlAlert,
GlModal,
GlSprintf,
},
props: {
environment: {
type: Object,
required: false,
default: () => ({}),
},
weight: {
type: Number,
required: false,
default: 0,
},
visible: {
type: Boolean,
required: false,
default: false,
},
},
translations: {
title: s__('CanaryIngress|Change the ratio of canary deployments?'),
ratioChange: s__(
'CanaryIngress|You are changing the ratio of the canary rollout for %{environment} compared to the stable deployment to:',
),
stableWeight: s__('CanaryIngress|%{boldStart}Stable:%{boldEnd} %{stable}'),
canaryWeight: s__('CanaryIngress|%{boldStart}Canary:%{boldEnd} %{canary}'),
deploymentWarning: s__(
'CanaryIngress|Doing so will set a deployment change in progress. This temporarily blocks any further configuration until the deployment is finished.',
),
},
modal: {
modalId: CANARY_UPDATE_MODAL,
actionPrimary: {
text: s__('CanaryIngress|Change ratio'),
2022-08-13 15:12:31 +05:30
attributes: [{ variant: 'confirm' }],
2021-03-08 18:12:59 +05:30
},
actionCancel: { text: __('Cancel') },
static: true,
},
data() {
return { error: '', dismissed: true };
},
computed: {
stableWeight() {
return (100 - this.weight).toString();
},
canaryWeight() {
return this.weight.toString();
},
hasError() {
return Boolean(this.error);
},
environmentName() {
return this.environment?.name ?? '';
},
},
methods: {
submitCanaryChange() {
return this.$apollo
.mutate({
mutation: updateCanaryIngress,
variables: {
input: {
2022-04-04 11:22:00 +05:30
id: this.environment.global_id || this.environment.globalId,
2021-03-08 18:12:59 +05:30
weight: this.weight,
},
},
})
.then(
({
data: {
environmentsCanaryIngressUpdate: {
errors: [error],
},
},
}) => {
this.error = error;
},
)
.catch(() => {
this.error = __('Something went wrong. Please try again later');
});
},
dismiss() {
this.error = '';
},
},
};
</script>
<template>
<div>
<gl-alert v-if="hasError" variant="danger" @dismiss="dismiss">{{ error }}</gl-alert>
<gl-modal v-bind="$options.modal" :visible="visible" @primary="submitCanaryChange">
<template #modal-title>{{ $options.translations.title }}</template>
<template #default>
<p>
<gl-sprintf :message="$options.translations.ratioChange">
<template #environment>{{ environmentName }}</template>
</gl-sprintf>
</p>
<ul class="gl-list-style-none gl-p-0">
<li>
<gl-sprintf :message="$options.translations.stableWeight">
<template #bold="{ content }">
<span class="gl-font-weight-bold">{{ content }}</span>
</template>
<template #stable>{{ stableWeight }}</template>
</gl-sprintf>
</li>
<li>
<gl-sprintf :message="$options.translations.canaryWeight">
<template #bold="{ content }">
<span class="gl-font-weight-bold">{{ content }}</span>
</template>
<template #canary>{{ canaryWeight }}</template>
</gl-sprintf>
</li>
</ul>
<p>{{ $options.translations.deploymentWarning }}</p>
</template>
</gl-modal>
</div>
</template>