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' ) ,
2023-05-27 22:25:52 +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 >