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
|
<script>
import { GlCollapsibleListbox } from '@gitlab/ui';
import uniqueId from 'lodash/uniqueId';
import { s__ } from '~/locale';
import { CANARY_UPDATE_MODAL } from '../constants';
export default {
components: {
GlCollapsibleListbox,
},
props: {
canaryIngress: {
required: true,
type: Object,
},
graphql: {
required: false,
type: Boolean,
default: false,
},
},
ingressOptions: Array(100 / 5 + 1)
.fill(0)
.map((_, i) => {
const value = i * 5;
return { value, text: value.toString() };
}),
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;
},
canaryWeight() {
return this.weight;
},
},
methods: {
changeCanary(weight) {
this.$root.$emit('bv::show::modal', CANARY_UPDATE_MODAL);
this.$emit('change', weight);
},
changeStable(weight) {
this.$root.$emit('bv::show::modal', CANARY_UPDATE_MODAL);
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-collapsible-listbox
:id="stableWeightId"
:selected="stableWeight"
:items="$options.ingressOptions"
class="gl-min-w-full gl-text-black-normal"
toggle-class="gl-min-w-full gl-rounded-top-left-none! gl-rounded-top-right-none! gl-rounded-bottom-right-none!"
@select="changeStable"
/>
</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-collapsible-listbox
:id="canaryWeightId"
:selected="canaryWeight"
:items="$options.ingressOptions"
class="gl-min-w-full"
toggle-class="gl-min-w-full gl-rounded-top-left-none! gl-rounded-top-right-none! gl-rounded-bottom-right-none!"
@select="changeCanary"
/>
</div>
</section>
</template>
|