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

93 lines
2.3 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-11-18 11:00:15 +05:30
/**
* Renders the stop "button" that allows stop an environment.
* Used in environments table.
*/
2018-05-09 12:01:36 +05:30
2021-01-29 00:20:46 +05:30
import { GlTooltipDirective, GlButton, GlModalDirective } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
2018-11-18 11:00:15 +05:30
import { s__ } from '~/locale';
import eventHub from '../event_hub';
2022-03-02 08:16:31 +05:30
import setEnvironmentToStopMutation from '../graphql/mutations/set_environment_to_stop.mutation.graphql';
import isEnvironmentStoppingQuery from '../graphql/queries/is_environment_stopping.query.graphql';
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
export default {
components: {
2020-10-24 23:57:45 +05:30
GlButton,
2018-11-18 11:00:15 +05:30
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2021-01-29 00:20:46 +05:30
GlModalDirective,
2018-11-18 11:00:15 +05:30
},
props: {
environment: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2022-03-02 08:16:31 +05:30
graphql: {
type: Boolean,
required: false,
default: false,
},
},
apollo: {
isEnvironmentStopping: {
query: isEnvironmentStoppingQuery,
variables() {
return { environment: this.environment };
},
},
2018-11-18 11:00:15 +05:30
},
2021-11-18 22:05:49 +05:30
i18n: {
title: s__('Environments|Stop environment'),
stop: s__('Environments|Stop'),
},
2018-11-18 11:00:15 +05:30
data() {
return {
isLoading: false,
2022-03-02 08:16:31 +05:30
isEnvironmentStopping: false,
2018-11-18 11:00:15 +05:30
};
},
mounted() {
eventHub.$on('stopEnvironment', this.onStopEnvironment);
},
beforeDestroy() {
eventHub.$off('stopEnvironment', this.onStopEnvironment);
},
methods: {
onClick() {
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP, this.$options.stopEnvironmentTooltipId);
2022-03-02 08:16:31 +05:30
if (this.graphql) {
this.$apollo.mutate({
mutation: setEnvironmentToStopMutation,
variables: { environment: this.environment },
});
} else {
eventHub.$emit('requestStopEnvironment', this.environment);
}
2018-11-18 11:00:15 +05:30
},
onStopEnvironment(environment) {
if (this.environment.id === environment.id) {
this.isLoading = true;
}
2017-08-17 22:00:37 +05:30
},
2018-11-18 11:00:15 +05:30
},
2021-01-03 14:25:43 +05:30
stopEnvironmentTooltipId: 'stop-environment-button-tooltip',
2018-11-18 11:00:15 +05:30
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2020-10-24 23:57:45 +05:30
<gl-button
2021-01-03 14:25:43 +05:30
v-gl-tooltip="{ id: $options.stopEnvironmentTooltipId }"
2021-01-29 00:20:46 +05:30
v-gl-modal-directive="'stop-environment-modal'"
2022-03-02 08:16:31 +05:30
:loading="isLoading || isEnvironmentStopping"
2021-11-18 22:05:49 +05:30
:title="$options.i18n.title"
:aria-label="$options.i18n.title"
2020-10-24 23:57:45 +05:30
icon="stop"
2021-11-18 22:05:49 +05:30
category="secondary"
2020-10-24 23:57:45 +05:30
variant="danger"
2018-11-08 19:23:39 +05:30
@click="onClick"
2021-11-18 22:05:49 +05:30
>
{{ $options.i18n.stop }}
</gl-button>
2017-08-17 22:00:37 +05:30
</template>