2019-07-07 11:18:12 +05:30
< script >
/ * *
* Render modal to confirm rollback / redeploy .
* /
2021-10-27 15:23:28 +05:30
import { GlModal , GlSprintf , GlLink } from '@gitlab/ui' ;
2021-03-11 19:13:27 +05:30
import { escape } from 'lodash' ;
2021-10-27 15:23:28 +05:30
import csrf from '~/lib/utils/csrf' ;
import { _ _ , s _ _ , sprintf } from '~/locale' ;
2022-08-13 15:12:31 +05:30
import { helpPagePath } from '~/helpers/help_page_helper' ;
2019-07-07 11:18:12 +05:30
2022-01-26 12:08:38 +05:30
import rollbackEnvironment from '../graphql/mutations/rollback_environment.mutation.graphql' ;
2019-07-07 11:18:12 +05:30
import eventHub from '../event_hub' ;
export default {
name : 'ConfirmRollbackModal' ,
components : {
GlModal ,
2021-10-27 15:23:28 +05:30
GlSprintf ,
GlLink ,
} ,
model : {
prop : 'visible' ,
event : 'change' ,
2019-07-07 11:18:12 +05:30
} ,
props : {
environment : {
type : Object ,
required : true ,
} ,
2021-10-27 15:23:28 +05:30
visible : {
type : Boolean ,
required : false ,
default : false ,
} ,
hasMultipleCommits : {
type : Boolean ,
required : false ,
default : true ,
} ,
retryUrl : {
type : String ,
required : false ,
default : null ,
} ,
2022-01-26 12:08:38 +05:30
graphql : {
type : Boolean ,
required : false ,
default : false ,
} ,
2019-07-07 11:18:12 +05:30
} ,
computed : {
modalTitle ( ) {
2022-01-26 12:08:38 +05:30
const title = this . isLastDeployment
2019-07-07 11:18:12 +05:30
? s _ _ ( 'Environments|Re-deploy environment %{name}?' )
: s _ _ ( 'Environments|Rollback environment %{name}?' ) ;
return sprintf ( title , {
2020-05-24 23:13:21 +05:30
name : escape ( this . environment . name ) ,
2019-07-07 11:18:12 +05:30
} ) ;
} ,
commitShortSha ( ) {
2021-10-27 15:23:28 +05:30
if ( this . hasMultipleCommits ) {
2022-01-26 12:08:38 +05:30
if ( this . graphql ) {
const { lastDeployment } = this . environment ;
return this . commitData ( lastDeployment , 'shortId' ) ;
}
2021-10-27 15:23:28 +05:30
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'short_id' ) ;
}
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
return this . environment . commitShortSha ;
2019-07-07 11:18:12 +05:30
} ,
2021-10-27 15:23:28 +05:30
commitUrl ( ) {
if ( this . hasMultipleCommits ) {
2022-01-26 12:08:38 +05:30
if ( this . graphql ) {
const { lastDeployment } = this . environment ;
return this . commitData ( lastDeployment , 'commitPath' ) ;
}
2021-10-27 15:23:28 +05:30
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'commit_path' ) ;
}
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
return this . environment . commitUrl ;
2019-07-07 11:18:12 +05:30
} ,
modalActionText ( ) {
2022-08-13 15:12:31 +05:30
return this . isLastDeployment
? s _ _ ( 'Environments|Re-deploy environment' )
: s _ _ ( 'Environments|Rollback environment' ) ;
2019-07-07 11:18:12 +05:30
} ,
2021-10-27 15:23:28 +05:30
primaryProps ( ) {
let attributes = [ { variant : 'danger' } ] ;
if ( this . retryUrl ) {
attributes = [ ... attributes , { 'data-method' : 'post' } , { href : this . retryUrl } ] ;
}
2019-07-07 11:18:12 +05:30
2021-10-27 15:23:28 +05:30
return {
text : this . modalActionText ,
attributes ,
} ;
} ,
2022-01-26 12:08:38 +05:30
isLastDeployment ( ) {
2022-03-02 08:16:31 +05:30
return this . environment ? . isLastDeployment || this . environment ? . lastDeployment ? . isLast ;
2022-01-26 12:08:38 +05:30
} ,
2022-08-13 15:12:31 +05:30
modalBodyText ( ) {
return this . isLastDeployment
? s _ _ (
'Environments|This action will %{docsStart}retry the latest deployment%{docsEnd} with the commit %{commitId}, for this environment. Are you sure you want to continue?' ,
)
: s _ _ (
'Environments|This action will %{docsStart}roll back this environment%{docsEnd} to a previously successful deployment for commit %{commitId}. Are you sure you want to continue?' ,
) ;
} ,
2021-10-27 15:23:28 +05:30
} ,
2019-07-07 11:18:12 +05:30
methods : {
2021-10-27 15:23:28 +05:30
handleChange ( event ) {
this . $emit ( 'change' , event ) ;
} ,
2019-07-07 11:18:12 +05:30
onOk ( ) {
2022-01-26 12:08:38 +05:30
if ( this . graphql ) {
this . $apollo . mutate ( {
mutation : rollbackEnvironment ,
variables : { environment : this . environment } ,
} ) ;
} else {
eventHub . $emit ( 'rollbackEnvironment' , this . environment ) ;
}
2019-07-07 11:18:12 +05:30
} ,
commitData ( lastDeployment , key ) {
2022-01-26 12:08:38 +05:30
return lastDeployment ? . commit ? . [ key ] ? ? '' ;
2019-07-07 11:18:12 +05:30
} ,
} ,
2021-10-27 15:23:28 +05:30
csrf ,
cancelProps : {
text : _ _ ( 'Cancel' ) ,
2023-05-27 22:25:52 +05:30
attributes : { variant : 'danger' } ,
2021-10-27 15:23:28 +05:30
} ,
2022-08-13 15:12:31 +05:30
docsPath : helpPagePath ( 'ci/environments/index.md' , { anchor : 'retry-or-roll-back-a-deployment' } ) ,
2019-07-07 11:18:12 +05:30
} ;
< / script >
< template >
< gl-modal
: title = "modalTitle"
2021-10-27 15:23:28 +05:30
: visible = "visible"
: action - cancel = "$options.cancelProps"
: action - primary = "primaryProps"
2019-07-07 11:18:12 +05:30
modal - id = "confirm-rollback-modal"
@ ok = "onOk"
2021-10-27 15:23:28 +05:30
@ change = "handleChange"
2019-07-07 11:18:12 +05:30
>
2022-08-13 15:12:31 +05:30
< gl-sprintf :message = "modalBodyText" >
< template # commitId >
2021-10-27 15:23:28 +05:30
< gl-link :href = "commitUrl" target = "_blank" class = "commit-sha mr-0" > { {
commitShortSha
} } < / gl-link >
< / template >
2022-08-13 15:12:31 +05:30
< template # docs = "{ content }" >
< gl-link :href = "$options.docsLink" target = "_blank" > { { content } } < / gl-link >
2021-10-27 15:23:28 +05:30
< / template >
< / gl-sprintf >
2019-07-07 11:18:12 +05:30
< / gl-modal >
< / template >