summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/header_component.vue
blob: c7b72be36ad07ae19bccec2f0d7cfc1ad0a17f45 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<script>
import { GlLoadingIcon, GlModal, GlModalDirective, GlButton } from '@gitlab/ui';
import ciHeader from '~/vue_shared/components/header_ci_component.vue';
import eventHub from '../event_hub';
import { __ } from '~/locale';

const DELETE_MODAL_ID = 'pipeline-delete-modal';

export default {
  name: 'PipelineHeaderSection',
  components: {
    ciHeader,
    GlLoadingIcon,
    GlModal,
    GlButton,
  },
  directives: {
    GlModal: GlModalDirective,
  },
  props: {
    pipeline: {
      type: Object,
      required: true,
    },
    isLoading: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      isCanceling: false,
      isRetrying: false,
      isDeleting: false,
    };
  },

  computed: {
    status() {
      return this.pipeline.details && this.pipeline.details.status;
    },
    shouldRenderContent() {
      return !this.isLoading && Object.keys(this.pipeline).length;
    },
    deleteModalConfirmationText() {
      return __(
        'Are you sure you want to delete this pipeline? Doing so will expire all pipeline caches and delete all related objects, such as builds, logs, artifacts, and triggers. This action cannot be undone.',
      );
    },
  },

  methods: {
    cancelPipeline() {
      this.isCanceling = true;
      eventHub.$emit('headerPostAction', this.pipeline.cancel_path);
    },
    retryPipeline() {
      this.isRetrying = true;
      eventHub.$emit('headerPostAction', this.pipeline.retry_path);
    },
    deletePipeline() {
      this.isDeleting = true;
      eventHub.$emit('headerDeleteAction', this.pipeline.delete_path);
    },
  },
  DELETE_MODAL_ID,
};
</script>
<template>
  <div class="pipeline-header-container">
    <ci-header
      v-if="shouldRenderContent"
      :status="status"
      :item-id="pipeline.id"
      :time="pipeline.created_at"
      :user="pipeline.user"
      item-name="Pipeline"
    >
      <gl-button
        v-if="pipeline.retry_path"
        :loading="isRetrying"
        :disabled="isRetrying"
        data-testid="retryButton"
        category="secondary"
        variant="info"
        @click="retryPipeline()"
      >
        {{ __('Retry') }}
      </gl-button>

      <gl-button
        v-if="pipeline.cancel_path"
        :loading="isCanceling"
        :disabled="isCanceling"
        data-testid="cancelPipeline"
        class="gl-ml-3"
        category="primary"
        variant="danger"
        @click="cancelPipeline()"
      >
        {{ __('Cancel running') }}
      </gl-button>

      <gl-button
        v-if="pipeline.delete_path"
        v-gl-modal="$options.DELETE_MODAL_ID"
        :loading="isDeleting"
        :disabled="isDeleting"
        data-testid="deletePipeline"
        class="gl-ml-3"
        category="secondary"
        variant="danger"
      >
        {{ __('Delete') }}
      </gl-button>
    </ci-header>

    <gl-loading-icon v-if="isLoading" size="lg" class="gl-mt-3 gl-mb-3" />

    <gl-modal
      :modal-id="$options.DELETE_MODAL_ID"
      :title="__('Delete pipeline')"
      :ok-title="__('Delete pipeline')"
      ok-variant="danger"
      @ok="deletePipeline()"
    >
      <p>
        {{ deleteModalConfirmationText }}
      </p>
    </gl-modal>
  </div>
</template>