All files / app/assets/javascripts/environments/components environment_delete.vue

54.54% Statements 6/11
80% Branches 4/5
80% Functions 4/5
54.54% Lines 6/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79  11x                                                         7x                       7x         7x           2x 1x                                                
<script>
/**
 * Renders the delete button that allows deleting a stopped environment.
 * Used in the environments table.
 */
 
import { GlDisclosureDropdownItem, GlModalDirective } from '@gitlab/ui';
import { s__ } from '~/locale';
import eventHub from '../event_hub';
import setEnvironmentToDelete from '../graphql/mutations/set_environment_to_delete.mutation.graphql';
 
export default {
  components: {
    GlDisclosureDropdownItem,
  },
  directives: {
    GlModalDirective,
  },
  props: {
    environment: {
      type: Object,
      required: true,
    },
    graphql: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      isLoading: false,
      item: {
        text: s__('Environments|Delete environment'),
        extraAttrs: {
          variant: 'danger',
          class: 'gl-text-red-500!',
        },
      },
    };
  },
  mounted() {
    if (!this.graphql) {
      eventHub.$on('deleteEnvironment', this.onDeleteEnvironment);
    }
  },
  beforeDestroy() {
    if (!this.graphql) {
      eventHub.$off('deleteEnvironment', this.onDeleteEnvironment);
    }
  },
  methods: {
    onClick() {
      if (this.graphql) {
        this.$apollo.mutate({
          mutation: setEnvironmentToDelete,
          variables: { environment: this.environment },
        });
      } else {
        eventHub.$emit('requestDeleteEnvironment', this.environment);
      }
    },
    onDeleteEnvironment(environment) {
      Iif (this.environment.id === environment.id) {
        this.isLoading = true;
      }
    },
  },
};
</script>
<template>
  <gl-disclosure-dropdown-item
    v-gl-modal-directive.delete-environment-modal
    :item="item"
    :loading="isLoading"
    @action="onClick"
  />
</template>