summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/stages_dropdown.vue
blob: 1c15af55a8b9fa91ca712082457955f56c8466c7 (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
<script>
  import _ from 'underscore';
  import CiIcon from '~/vue_shared/components/ci_icon.vue';
  import Icon from '~/vue_shared/components/icon.vue';
  import { __ } from '~/locale';

  export default {
    components: {
      CiIcon,
      Icon,
    },
    props: {
      pipeline: {
        type: Object,
        required: true,
      },
      stages: {
        type: Array,
        required: true,
      },
    },
    data() {
      return {
        selectedStage: this.stages.length > 0 ? this.stages[0].name : __('More'),
      };
    },
    computed: {
      hasRef() {
        return !_.isEmpty(this.pipeline.ref);
      },
    },
    watch: {
      // When the component is initially mounted it may start with an empty stages array.
      // Once the prop is updated, we set the first stage as the selected one
      stages(newVal) {
        if (newVal.length) {
          this.selectedStage = newVal[0].name;
        }
      },
    },
    methods: {
      onStageClick(stage) {
        this.$emit('requestSidebarStageDropdown', stage);
        this.selectedStage = stage.name;
      },
    },
  };
</script>
<template>
  <div class="block-last dropdown">
    <ci-icon
      :status="pipeline.details.status"
      class="vertical-align-middle"
    />

    {{ __('Pipeline') }}
    <a
      :href="pipeline.path"
      class="js-pipeline-path link-commit"
    >
      #{{ pipeline.id }}
    </a>
    <template v-if="hasRef">
      {{ __('from') }}
      <a
        :href="pipeline.ref.path"
        class="link-commit ref-name"
      >
        {{ pipeline.ref.name }}
      </a>
    </template>

    <button
      type="button"
      data-toggle="dropdown"
      class="js-selected-stage dropdown-menu-toggle prepend-top-8"
    >
      {{ selectedStage }}
      <i class="fa fa-chevron-down" ></i>
    </button>

    <ul class="dropdown-menu">
      <li
        v-for="stage in stages"
        :key="stage.name"
      >
        <button
          type="button"
          class="js-stage-item stage-item"
          @click="onStageClick(stage)"
        >
          {{ stage.name }}
        </button>
      </li>
    </ul>
  </div>
</template>