Welcome to mirror list, hosted at ThFree Co, Russian Federation.

canary_ingress.vue « components « environments « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30f3f9dfc7592a9adae6c152a0d2e729ffe40084 (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
<script>
import { GlDropdown, GlDropdownItem, GlModalDirective as GlModal } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import { s__ } from '~/locale';
import { CANARY_UPDATE_MODAL } from '../constants';

export default {
  components: {
    GlDropdown,
    GlDropdownItem,
  },
  directives: {
    GlModal,
  },
  props: {
    canaryIngress: {
      required: true,
      type: Object,
    },
    graphql: {
      required: false,
      type: Boolean,
      default: false,
    },
  },
  ingressOptions: Array(100 / 5 + 1)
    .fill(0)
    .map((_, i) => i * 5),

  translations: {
    stableLabel: s__('CanaryIngress|Stable'),
    canaryLabel: s__('CanaryIngress|Canary'),
  },

  CANARY_UPDATE_MODAL,

  css: {
    label: [
      'gl-font-base',
      'gl-font-weight-normal',
      'gl-line-height-normal',
      'gl-inset-border-1-gray-200',
      'gl-py-3',
      'gl-px-4',
      'gl-mb-0',
    ],
  },
  computed: {
    stableWeightId() {
      return uniqueId('stable-weight-');
    },
    canaryWeightId() {
      return uniqueId('canary-weight-');
    },
    weight() {
      if (this.graphql) {
        return this.canaryIngress.canaryWeight;
      }
      return this.canaryIngress.canary_weight;
    },
    stableWeight() {
      return (100 - this.weight).toString();
    },
    canaryWeight() {
      return this.weight.toString();
    },
  },
  methods: {
    changeCanary(weight) {
      this.$emit('change', weight);
    },
    changeStable(weight) {
      this.$emit('change', 100 - weight);
    },
  },
};
</script>
<template>
  <section class="gl-display-flex gl-bg-white gl-m-3">
    <div class="gl-display-flex gl-flex-direction-column">
      <label :for="stableWeightId" :class="$options.css.label" class="gl-rounded-top-left-base">
        {{ $options.translations.stableLabel }}
      </label>
      <gl-dropdown
        :id="stableWeightId"
        :text="stableWeight"
        data-testid="stable-weight"
        class="gl-w-full"
        toggle-class="gl-rounded-top-left-none! gl-rounded-top-right-none! gl-rounded-bottom-right-none!"
      >
        <gl-dropdown-item
          v-for="option in $options.ingressOptions"
          :key="option"
          v-gl-modal="$options.CANARY_UPDATE_MODAL"
          @click="changeStable(option)"
          >{{ option }}</gl-dropdown-item
        >
      </gl-dropdown>
    </div>
    <div class="gl-display-flex gl-display-flex gl-flex-direction-column">
      <label :for="canaryWeightId" :class="$options.css.label" class="gl-rounded-top-right-base">{{
        $options.translations.canaryLabel
      }}</label>
      <gl-dropdown
        :id="canaryWeightId"
        :text="canaryWeight"
        data-testid="canary-weight"
        toggle-class="gl-rounded-top-left-none! gl-rounded-top-right-none! gl-rounded-bottom-left-none! gl-border-l-none!"
      >
        <gl-dropdown-item
          v-for="option in $options.ingressOptions"
          :key="option"
          v-gl-modal="$options.CANARY_UPDATE_MODAL"
          @click="changeCanary(option)"
          >{{ option }}</gl-dropdown-item
        >
      </gl-dropdown>
    </div>
  </section>
</template>