summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/graph/dropdown_job_component.vue
blob: 43121dd38f329208e512aa9362817fa54dacd326 (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
<script>
import $ from 'jquery';
import JobNameComponent from './job_name_component.vue';
import JobComponent from './job_component.vue';
import tooltip from '../../../vue_shared/directives/tooltip';

/**
 * Renders the dropdown for the pipeline graph.
 *
 * The following object should be provided as `job`:
 *
 * {
 *   "id": 4256,
 *   "name": "test",
 *   "status": {
 *     "icon": "icon_status_success",
 *     "text": "passed",
 *     "label": "passed",
 *     "group": "success",
 *     "details_path": "/root/ci-mock/builds/4256",
 *     "action": {
 *       "icon": "retry",
 *       "title": "Retry",
 *       "path": "/root/ci-mock/builds/4256/retry",
 *       "method": "post"
 *     }
 *   }
 * }
 */
export default {
  directives: {
    tooltip,
  },

  components: {
    JobComponent,
    JobNameComponent,
  },

  props: {
    job: {
      type: Object,
      required: true,
    },
    requestFinishedFor: {
      type: String,
      required: false,
      default: '',
    },
  },

  computed: {
    tooltipText() {
      return `${this.job.name} - ${this.job.status.label}`;
    },
  },

  mounted() {
    this.stopDropdownClickPropagation();
  },

  methods: {
    /**
     * When the user right clicks or cmd/ctrl + click in the job name or the action icon
     * the dropdown should not be closed so we stop propagation
     * of the click event inside the dropdown.
     *
     * Since this component is rendered multiple times per page we need to guarantee we only
     * target the click event of this component.
     */
    stopDropdownClickPropagation() {
      $(
        '.js-grouped-pipeline-dropdown button, .js-grouped-pipeline-dropdown a.mini-pipeline-graph-dropdown-item',
        this.$el,
      ).on('click', e => {
        e.stopPropagation();
      });
    },
  },
};
</script>
<template>
  <div class="ci-job-dropdown-container">
    <button
      v-tooltip
      type="button"
      data-toggle="dropdown"
      data-container="body"
      class="dropdown-menu-toggle build-content"
      :title="tooltipText">

      <job-name-component
        :name="job.name"
        :status="job.status"
      />

      <span class="dropdown-counter-badge">
        {{ job.size }}
      </span>
    </button>

    <ul class="dropdown-menu big-pipeline-graph-dropdown-menu js-grouped-pipeline-dropdown">
      <li class="scrollable-menu">
        <ul>
          <li
            v-for="(item, i) in job.jobs"
            :key="i">
            <job-component
              :job="item"
              css-class-job-name="mini-pipeline-graph-dropdown-item"
              :request-finished-for="requestFinishedFor"
            />
          </li>
        </ul>
      </li>
    </ul>
  </div>
</template>