2019-07-07 11:18:12 +05:30
< script >
/ * *
* Render modal to confirm rollback / redeploy .
* /
2020-05-24 23:13:21 +05:30
import { escape } from 'lodash' ;
2019-07-07 11:18:12 +05:30
import { GlModal } from '@gitlab/ui' ;
import { s _ _ , sprintf } from '~/locale' ;
import eventHub from '../event_hub' ;
export default {
name : 'ConfirmRollbackModal' ,
components : {
GlModal ,
} ,
props : {
environment : {
type : Object ,
required : true ,
} ,
} ,
computed : {
modalTitle ( ) {
const title = this . environment . isLastDeployment
? 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 ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'short_id' ) ;
} ,
commitUrl ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'commit_path' ) ;
} ,
commitTitle ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'title' ) ;
} ,
modalText ( ) {
2020-05-24 23:13:21 +05:30
const linkStart = ` <a class="commit-sha mr-0" href=" ${ escape ( this . commitUrl ) } "> ` ;
const commitId = escape ( this . commitShortSha ) ;
2019-07-07 11:18:12 +05:30
const linkEnd = '</a>' ;
2020-05-24 23:13:21 +05:30
const name = escape ( this . name ) ;
2019-07-07 11:18:12 +05:30
const body = this . environment . isLastDeployment
? s _ _ (
'Environments|This action will relaunch the job for commit %{linkStart}%{commitId}%{linkEnd}, putting the environment in a previous version. Are you sure you want to continue?' ,
)
: s _ _ (
'Environments|This action will run the job defined by %{name} for commit %{linkStart}%{commitId}%{linkEnd} putting the environment in a previous version. You can revert it by re-deploying the latest version of your application. Are you sure you want to continue?' ,
) ;
return sprintf (
body ,
{
commitId ,
linkStart ,
linkEnd ,
name ,
} ,
false ,
) ;
} ,
modalActionText ( ) {
return this . environment . isLastDeployment
? s _ _ ( 'Environments|Re-deploy' )
: s _ _ ( 'Environments|Rollback' ) ;
} ,
} ,
methods : {
onOk ( ) {
eventHub . $emit ( 'rollbackEnvironment' , this . environment ) ;
} ,
commitData ( lastDeployment , key ) {
if ( lastDeployment && lastDeployment . commit ) {
return lastDeployment . commit [ key ] ;
}
return '' ;
} ,
} ,
} ;
< / script >
< template >
< gl-modal
: title = "modalTitle"
modal - id = "confirm-rollback-modal"
: ok - title = "modalActionText"
ok - variant = "danger"
@ ok = "onOk"
>
< p v-html = "modalText" > < / p >
< / gl-modal >
< / template >