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
|
<script>
import { GlBadge, GlTooltipDirective, GlIcon } from '@gitlab/ui';
/**
* Renders CI icon based on API response shared between all places where it is used.
*
* Receives status object containing:
* status: {
* icon: "status_running" // used to render the icon and CSS class
* text: "Running",
* detailsPath: '/project1/jobs/1' // can also be details_path
* }
*
*/
export default {
components: {
GlBadge,
GlIcon,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
status: {
type: Object,
required: true,
validator(status) {
const { icon } = status;
return typeof icon === 'string' && icon.startsWith('status_');
},
},
showStatusText: {
type: Boolean,
required: false,
default: false,
},
showTooltip: {
type: Boolean,
required: false,
default: true,
},
useLink: {
type: Boolean,
default: true,
required: false,
},
},
computed: {
title() {
if (this.showTooltip) {
// show tooltip only when not showing text already
return !this.showStatusText ? this.status?.text : null;
}
return null;
},
ariaLabel() {
// show aria-label only when text is not rendered
if (!this.showStatusText) {
return this.status?.text;
}
return null;
},
href() {
// href can come from GraphQL (camelCase) or REST API (snake_case)
if (this.useLink) {
return this.status.detailsPath || this.status.details_path;
}
return null;
},
icon() {
if (this.status.icon) {
return `${this.status.icon}_borderless`;
}
return null;
},
variant() {
switch (this.status.icon) {
case 'status_success':
return 'success';
case 'status_warning':
case 'status_pending':
return 'warning';
case 'status_failed':
return 'danger';
case 'status_running':
return 'info';
// default covers the styles for the remainder of CI
// statuses that are not explicitly stated here
default:
return 'neutral';
}
},
},
};
</script>
<template>
<gl-badge
v-gl-tooltip
class="ci-icon gl-p-2"
:class="`ci-icon-variant-${variant}`"
:variant="variant"
:title="title"
:aria-label="ariaLabel"
:href="href"
size="md"
data-testid="ci-icon"
@click="$emit('ciStatusBadgeClick')"
>
<span class="ci-icon-gl-icon-wrapper"><gl-icon :name="icon" /></span
><span v-if="showStatusText" class="gl-mx-2 gl-white-space-nowrap" data-testid="ci-icon-text">{{
status.text
}}</span>
</gl-badge>
</template>
|