debian-mirror-gitlab/app/assets/javascripts/environments/components/confirm_rollback_modal.vue

151 lines
3.7 KiB
Vue
Raw Normal View History

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';
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,
},
2019-07-07 11:18:12 +05:30
},
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() {
2021-10-27 15:23:28 +05:30
if (this.hasMultipleCommits) {
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) {
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() {
return this.environment.isLastDeployment
? s__('Environments|Re-deploy')
: s__('Environments|Rollback');
},
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,
};
},
},
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() {
eventHub.$emit('rollbackEnvironment', this.environment);
},
commitData(lastDeployment, key) {
if (lastDeployment && lastDeployment.commit) {
return lastDeployment.commit[key];
}
return '';
},
},
2021-10-27 15:23:28 +05:30
csrf,
cancelProps: {
text: __('Cancel'),
attributes: [{ variant: 'danger' }],
},
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
>
2021-10-27 15:23:28 +05:30
<gl-sprintf
v-if="environment.isLastDeployment"
:message="
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?',
)
"
>
<template #link>
<gl-link :href="commitUrl" target="_blank" class="commit-sha mr-0">{{
commitShortSha
}}</gl-link>
</template>
</gl-sprintf>
<gl-sprintf
v-else
:message="
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?',
)
"
>
<template #name>{{ environment.name }}</template>
<template #link>
<gl-link :href="commitUrl" target="_blank" class="commit-sha mr-0">{{
commitShortSha
}}</gl-link>
</template>
</gl-sprintf>
2019-07-07 11:18:12 +05:30
</gl-modal>
</template>