Welcome to mirror list, hosted at ThFree Co, Russian Federation.

type.vue « fields « components « show « issues « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ab49e5df38bc61df0182072c1e1de06526a93ab (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
<!-- eslint-disable vue/multi-word-component-names -->
<script>
import { GlFormGroup, GlIcon, GlCollapsibleListbox } from '@gitlab/ui';
import { TYPE_INCIDENT, TYPE_ISSUE } from '~/issues/constants';
import { __ } from '~/locale';
import { issuableTypes } 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,
    GlCollapsibleListbox,
  },
  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 === TYPE_INCIDENT || this.canCreateIncident;
    },
  },
  methods: {
    updateIssueType(issueType) {
      this.$apollo.mutate({
        mutation: updateIssueStateMutation,
        variables: {
          issueType,
          isDirty: true,
        },
      });
    },
    isShown(type) {
      return type.value !== TYPE_INCIDENT || this.shouldShowIncident;
    },
  },
};
</script>

<template>
  <gl-form-group
    :label="$options.i18n.label"
    label-class="sr-only"
    label-for="issuable-type"
    class="gl-mb-0"
  >
    <gl-collapsible-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-collapsible-listbox>
  </gl-form-group>
</template>