2020-04-22 19:07:51 +05:30
|
|
|
<script>
|
2021-01-29 00:20:46 +05:30
|
|
|
import { GlTooltipDirective, GlModal } from '@gitlab/ui';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2020-04-22 19:07:51 +05:30
|
|
|
import eventHub from '../event_hub';
|
2022-01-26 12:08:38 +05:30
|
|
|
import deleteEnvironmentMutation from '../graphql/mutations/delete_environment.mutation.graphql';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
id: 'delete-environment-modal',
|
|
|
|
name: 'DeleteEnvironmentModal',
|
|
|
|
components: {
|
|
|
|
GlModal,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
environment: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
graphql: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
computed: {
|
2021-01-29 00:20:46 +05:30
|
|
|
primaryProps() {
|
|
|
|
return {
|
|
|
|
text: s__('Environments|Delete environment'),
|
|
|
|
attributes: [{ variant: 'danger' }],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
cancelProps() {
|
|
|
|
return {
|
2021-12-11 22:18:48 +05:30
|
|
|
text: __('Cancel'),
|
2021-01-29 00:20:46 +05:30
|
|
|
};
|
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
confirmDeleteMessage() {
|
|
|
|
return sprintf(
|
|
|
|
s__(
|
|
|
|
`Environments|Deleting the '%{environmentName}' environment cannot be undone. Do you want to delete it anyway?`,
|
|
|
|
),
|
|
|
|
{
|
|
|
|
environmentName: this.environment.name,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
modalTitle() {
|
|
|
|
return sprintf(s__(`Environments|Delete '%{environmentName}'?`), {
|
|
|
|
environmentName: this.environment.name,
|
|
|
|
});
|
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onSubmit() {
|
2022-01-26 12:08:38 +05:30
|
|
|
if (this.graphql) {
|
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
|
|
|
mutation: deleteEnvironmentMutation,
|
|
|
|
variables: { environment: this.environment },
|
|
|
|
})
|
2022-05-07 20:08:51 +05:30
|
|
|
.then(({ data }) => {
|
|
|
|
const [message] = data?.deleteEvironment?.errors ?? [];
|
2022-01-26 12:08:38 +05:30
|
|
|
if (message) {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({ message });
|
2022-01-26 12:08:38 +05:30
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) =>
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2022-01-26 12:08:38 +05:30
|
|
|
message: s__(
|
|
|
|
'Environments|An error occurred while deleting the environment. Check if the environment stopped; if not, stop it and try again.',
|
|
|
|
),
|
|
|
|
error,
|
|
|
|
captureError: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
eventHub.$emit('deleteEnvironment', this.environment);
|
|
|
|
}
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-modal
|
2021-01-29 00:20:46 +05:30
|
|
|
:modal-id="$options.id"
|
|
|
|
:action-primary="primaryProps"
|
|
|
|
:action-cancel="cancelProps"
|
|
|
|
:title="modalTitle"
|
|
|
|
@primary="onSubmit"
|
2020-04-22 19:07:51 +05:30
|
|
|
>
|
|
|
|
<p>{{ confirmDeleteMessage }}</p>
|
|
|
|
</gl-modal>
|
|
|
|
</template>
|