environment_rollback.vue 1.38 KB
Newer Older
Filipa Lacerda's avatar
Filipa Lacerda committed
1
<script>
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
/**
 * Renders Rollback or Re deploy button in environments table depending
 * of the provided property `isLastDeployment`.
 *
 * Makes a post request when the button is clicked.
 */
import { s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';
import eventHub from '../event_hub';
import LoadingIcon from '../../vue_shared/components/loading_icon.vue';

export default {
  components: {
    Icon,
    LoadingIcon,
  },

  directives: {
    tooltip,
  },

  props: {
    retryUrl: {
      type: String,
      default: '',
Filipa Lacerda's avatar
Filipa Lacerda committed
28
    },
29 30 31 32

    isLastDeployment: {
      type: Boolean,
      default: true,
33
    },
34 35 36 37 38 39 40 41 42 43
  },
  data() {
    return {
      isLoading: false,
    };
  },

  computed: {
    title() {
      return this.isLastDeployment ? s__('Environments|Re-deploy to environment') : s__('Environments|Rollback environment');
44
    },
45 46 47 48 49
  },

  methods: {
    onClick() {
      this.isLoading = true;
50

51
      eventHub.$emit('postAction', { endpoint: this.retryUrl });
52
    },
53 54
  },
};
Filipa Lacerda's avatar
Filipa Lacerda committed
55 56 57
</script>
<template>
  <button
58
    v-tooltip
59
    :disabled="isLoading"
60
    :title="title"
Filipa Lacerda's avatar
Filipa Lacerda committed
61
    type="button"
Clement Ho's avatar
Clement Ho committed
62
    class="btn d-none d-sm-none d-md-block"
Filipa Lacerda's avatar
Filipa Lacerda committed
63
    @click="onClick"
64
  >
65

66 67 68 69 70 71
    <icon
      v-if="isLastDeployment"
      name="repeat" />
    <icon
      v-else
      name="redo"/>
72

73
    <loading-icon v-if="isLoading" />
Filipa Lacerda's avatar
Filipa Lacerda committed
74 75
  </button>
</template>