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
|
<script>
import { GlFormGroup, GlIcon, GlListbox } from '@gitlab/ui';
import { TYPE_ISSUE } from '~/issues/constants';
import { __ } from '~/locale';
import { issuableTypes, INCIDENT_TYPE } from '../../constants';
import getIssueStateQuery from '../../queries/get_issue_state.query.graphql';
import updateIssueStateMutation from '../../queries/update_issue_state.mutation.graphql';
export const i18n = {
label: __('Issue Type'),
};
export default {
i18n,
issuableTypes,
components: {
GlFormGroup,
GlIcon,
GlListbox,
},
inject: {
canCreateIncident: {
default: false,
},
issueType: {
default: TYPE_ISSUE,
},
},
data() {
return {
issueState: {},
selectedIssueType: '',
};
},
apollo: {
issueState: {
query: getIssueStateQuery,
result({
data: {
issueState: { issueType },
},
}) {
this.selectedIssueType = issueType;
},
},
},
computed: {
shouldShowIncident() {
return this.issueType === INCIDENT_TYPE || this.canCreateIncident;
},
},
methods: {
updateIssueType(issueType) {
this.$apollo.mutate({
mutation: updateIssueStateMutation,
variables: {
issueType,
isDirty: true,
},
});
},
isShown(type) {
return type.value !== INCIDENT_TYPE || this.shouldShowIncident;
},
},
};
</script>
<template>
<gl-form-group
:label="$options.i18n.label"
label-class="sr-only"
label-for="issuable-type"
class="mb-2 mb-md-0"
>
<gl-listbox
v-model="selectedIssueType"
toggle-class="gl-mb-0"
:items="$options.issuableTypes"
:header-text="$options.i18n.label"
:list-aria-labelled-by="$options.i18n.label"
block
@select="updateIssueType"
>
<template #list-item="{ item }">
<span v-show="isShown(item)" data-testid="issue-type-list-item">
<gl-icon :name="item.icon" />
{{ item.text }}
</span>
</template>
</gl-listbox>
</gl-form-group>
</template>
|