summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/ci_badge_link.vue
blob: 271cfd210a67901420670101ef991e18fad550d4 (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
<script>
import { GlTooltipDirective, GlLink } from '@gitlab/ui';
import CiIcon from './ci_icon.vue';
/**
 * Renders CI Badge link with CI icon and status text based on
 * API response shared between all places where it is used.
 *
 * Receives status object containing:
 * status: {
 *   details_path or detailsPath: "/gitlab-org/gitlab-foss/pipelines/8150156" // url
 *   group:"running" // used for CSS class
 *   icon: "icon_status_running" // used to render the icon
 *   label:"running" // used for potential tooltip
 *   text:"running" // text rendered
 * }
 *
 * Used in:
 * - Pipelines table - first column
 * - Jobs table - first column
 * - Pipeline show view - header
 * - Job show view - header
 * - MR widget
 * - Terraform table
 * - On-demand scans list
 */

export default {
  components: {
    GlLink,
    CiIcon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    status: {
      type: Object,
      required: true,
    },
    showText: {
      type: Boolean,
      required: false,
      default: true,
    },
    iconClasses: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    title() {
      return !this.showText ? this.status?.text : '';
    },
    detailsPath() {
      // For now, this can either come from graphQL with camelCase or REST API in snake_case
      return this.status.detailsPath || this.status.details_path;
    },
    cssClass() {
      const className = this.status.group;
      return className ? `ci-status ci-${className}` : 'ci-status';
    },
  },
};
</script>
<template>
  <gl-link
    v-gl-tooltip
    class="gl-display-inline-flex gl-align-items-center gl-line-height-0 gl-px-3 gl-py-2 gl-rounded-base"
    :class="cssClass"
    :title="title"
    data-qa-selector="status_badge_link"
    :href="detailsPath"
    @click="$emit('ciStatusBadgeClick')"
  >
    <ci-icon :status="status" :css-classes="iconClasses" />

    <template v-if="showText">
      <span class="gl-ml-2">{{ status.text }}</span>
    </template>
  </gl-link>
</template>