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

77 lines
1.6 KiB
Vue
Raw Normal View History

2020-04-22 19:07:51 +05:30
<script>
/**
* Renders the delete button that allows deleting a stopped environment.
2021-01-29 00:20:46 +05:30
* Used in the environments table.
2020-04-22 19:07:51 +05:30
*/
2021-11-18 22:05:49 +05:30
import { GlDropdownItem, GlModalDirective } from '@gitlab/ui';
2020-04-22 19:07:51 +05:30
import { s__ } from '~/locale';
import eventHub from '../event_hub';
2022-01-26 12:08:38 +05:30
import setEnvironmentToDelete from '../graphql/mutations/set_environment_to_delete.mutation.graphql';
2020-04-22 19:07:51 +05:30
export default {
components: {
2021-11-18 22:05:49 +05:30
GlDropdownItem,
2020-04-22 19:07:51 +05:30
},
directives: {
2021-01-29 00:20:46 +05:30
GlModalDirective,
2020-04-22 19:07:51 +05:30
},
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
},
data() {
return {
isLoading: false,
};
},
2021-11-18 22:05:49 +05:30
i18n: {
title: s__('Environments|Delete environment'),
2020-04-22 19:07:51 +05:30
},
mounted() {
2022-01-26 12:08:38 +05:30
if (!this.graphql) {
eventHub.$on('deleteEnvironment', this.onDeleteEnvironment);
}
2020-04-22 19:07:51 +05:30
},
beforeDestroy() {
2022-01-26 12:08:38 +05:30
if (!this.graphql) {
eventHub.$off('deleteEnvironment', this.onDeleteEnvironment);
}
2020-04-22 19:07:51 +05:30
},
methods: {
onClick() {
2022-01-26 12:08:38 +05:30
if (this.graphql) {
this.$apollo.mutate({
mutation: setEnvironmentToDelete,
variables: { environment: this.environment },
});
} else {
eventHub.$emit('requestDeleteEnvironment', this.environment);
}
2020-04-22 19:07:51 +05:30
},
onDeleteEnvironment(environment) {
if (this.environment.id === environment.id) {
this.isLoading = true;
}
},
},
};
</script>
<template>
2021-11-18 22:05:49 +05:30
<gl-dropdown-item
v-gl-modal-directive.delete-environment-modal
2020-04-22 19:07:51 +05:30
:loading="isLoading"
2021-01-29 00:20:46 +05:30
variant="danger"
2020-04-22 19:07:51 +05:30
@click="onClick"
2021-11-18 22:05:49 +05:30
>
{{ $options.i18n.title }}
</gl-dropdown-item>
2020-04-22 19:07:51 +05:30
</template>