summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/components/canary_update_modal.vue
blob: fd4885a9dbdaf2142ee223a6a694d702687f0c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<script>
import { GlAlert, GlModal, GlSprintf } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { CANARY_UPDATE_MODAL } from '../constants';
import updateCanaryIngress from '../graphql/mutations/update_canary_ingress.mutation.graphql';

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'),
      attributes: [{ variant: 'info' }],
    },
    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: {
              id: this.environment.global_id || this.environment.globalId,
              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>