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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<script>
import { GlBadge, GlIcon } from '@gitlab/ui';
import Vue from 'vue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { fetchPolicies } from '~/lib/graphql';
import { __ } from '~/locale';
import {
STATUS_CLOSED,
STATUS_OPEN,
TYPE_ISSUE,
TYPE_MERGE_REQUEST,
TYPE_EPIC,
} from '~/issues/constants';
export const badgeState = Vue.observable({
state: '',
updateStatus: null,
});
const CLASSES = {
opened: 'issuable-status-badge-open',
locked: 'issuable-status-badge-open',
closed: 'issuable-status-badge-closed',
merged: 'issuable-status-badge-merged',
};
const ICONS = {
[TYPE_EPIC]: {
opened: 'epic',
closed: 'epic-closed',
},
[TYPE_ISSUE]: {
opened: 'issues',
locked: 'issues',
closed: 'issue-closed',
},
[TYPE_MERGE_REQUEST]: {
opened: 'merge-request-open',
locked: 'merge-request-open',
closed: 'merge-request-close',
merged: 'merge',
},
};
const STATUS = {
opened: __('Open'),
locked: __('Open'),
closed: __('Closed'),
merged: __('Merged'),
};
export default {
components: {
GlBadge,
GlIcon,
},
mixins: [glFeatureFlagMixin()],
inject: {
query: { default: null },
projectPath: { default: null },
iid: { default: null },
},
props: {
initialState: {
type: String,
required: false,
default: null,
},
issuableType: {
type: String,
required: false,
default: '',
},
},
data() {
if (!this.iid) return { state: this.initialState };
if (this.initialState && !badgeState.state) {
badgeState.state = this.initialState;
}
return badgeState;
},
computed: {
badgeClass() {
return [
CLASSES[this.state],
{
'gl-vertical-align-bottom': this.issuableType === TYPE_MERGE_REQUEST,
},
];
},
badgeVariant() {
if (this.state === STATUS_OPEN) {
return 'success';
} else if (this.state === STATUS_CLOSED) {
return this.issuableType === TYPE_MERGE_REQUEST ? 'danger' : 'info';
}
return 'info';
},
badgeText() {
return STATUS[this.state];
},
badgeIcon() {
const type = this.issuableType || TYPE_MERGE_REQUEST;
return ICONS[type][this.state];
},
},
created() {
if (!badgeState.updateStatus) {
badgeState.updateStatus = this.fetchState;
}
},
beforeDestroy() {
if (badgeState.updateStatus && this.query) {
badgeState.updateStatus = null;
}
},
methods: {
async fetchState() {
const { data } = await this.$apollo.query({
query: this.query,
variables: {
projectPath: this.projectPath,
iid: this.iid,
},
fetchPolicy: fetchPolicies.NO_CACHE,
});
badgeState.state = data?.workspace?.issuable?.state;
},
},
};
</script>
<template>
<gl-badge
class="issuable-status-badge gl-mr-3 gl-align-self-center"
:class="badgeClass"
:variant="badgeVariant"
:aria-label="badgeText"
>
<gl-icon :name="badgeIcon" class="gl-badge-icon" />
<span class="gl-display-none gl-sm-display-block gl-ml-2">{{ badgeText }}</span>
</gl-badge>
</template>
|