environment_rollback.vue 1.8 KB
Newer Older
F
Filipa Lacerda 已提交
1
<script>
2 3 4 5 6 7
/**
 * Renders Rollback or Re deploy button in environments table depending
 * of the provided property `isLastDeployment`.
 *
 * Makes a post request when the button is clicked.
 */
8
import { GlTooltipDirective, GlLoadingIcon, GlModalDirective, GlButton } from '@gitlab/ui';
9 10
import { s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
11
import ConfirmRollbackModal from './confirm_rollback_modal.vue';
12 13 14 15 16
import eventHub from '../event_hub';

export default {
  components: {
    Icon,
17
    GlLoadingIcon,
18 19
    GlButton,
    ConfirmRollbackModal,
20 21
  },
  directives: {
22
    GlTooltip: GlTooltipDirective,
23
    GlModal: GlModalDirective,
24 25 26 27 28
  },
  props: {
    isLastDeployment: {
      type: Boolean,
      default: true,
29
    },
30 31 32 33 34 35 36 37 38 39

    environment: {
      type: Object,
      required: true,
    },

    retryUrl: {
      type: String,
      required: true,
    },
40 41 42 43 44 45 46 47 48
  },
  data() {
    return {
      isLoading: false,
    };
  },

  computed: {
    title() {
49 50 51
      return this.isLastDeployment
        ? s__('Environments|Re-deploy to environment')
        : s__('Environments|Rollback environment');
F
Filipa Lacerda 已提交
52
    },
53 54 55 56
  },

  methods: {
    onClick() {
57 58 59 60 61 62 63 64 65 66
      eventHub.$emit('requestRollbackEnvironment', {
        ...this.environment,
        retryUrl: this.retryUrl,
        isLastDeployment: this.isLastDeployment,
      });
      eventHub.$on('rollbackEnvironment', environment => {
        if (environment.id === this.environment.id) {
          this.isLoading = true;
        }
      });
67
    },
68 69
  },
};
F
Filipa Lacerda 已提交
70 71
</script>
<template>
72
  <gl-button
73
    v-gl-tooltip
74
    v-gl-modal.confirm-rollback-modal
75
    :disabled="isLoading"
76
    :title="title"
77
    class="d-none d-md-block text-secondary"
F
Filipa Lacerda 已提交
78
    @click="onClick"
F
Filipa Lacerda 已提交
79
  >
M
Mike Greiling 已提交
80
    <icon v-if="isLastDeployment" name="repeat" /> <icon v-else name="redo" />
C
Clement Ho 已提交
81
    <gl-loading-icon v-if="isLoading" />
82
  </gl-button>
F
Filipa Lacerda 已提交
83
</template>