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

board_sidebar_milestone_select.vue « sidebar « components « boards « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 78c3f8acc62b8e6e890184df3855ba5dff52ca8e (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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<script>
import { mapGetters, mapActions } from 'vuex';
import {
  GlDropdown,
  GlDropdownItem,
  GlDropdownText,
  GlSearchBoxByType,
  GlDropdownDivider,
  GlLoadingIcon,
} from '@gitlab/ui';
import { fetchPolicies } from '~/lib/graphql';
import BoardEditableItem from '~/boards/components/sidebar/board_editable_item.vue';
import groupMilestones from '../../graphql/group_milestones.query.graphql';
import createFlash from '~/flash';
import { __, s__ } from '~/locale';

export default {
  components: {
    BoardEditableItem,
    GlDropdown,
    GlLoadingIcon,
    GlDropdownItem,
    GlDropdownText,
    GlSearchBoxByType,
    GlDropdownDivider,
  },
  data() {
    return {
      milestones: [],
      searchTitle: '',
      loading: false,
      edit: false,
    };
  },
  apollo: {
    milestones: {
      fetchPolicy: fetchPolicies.CACHE_AND_NETWORK,
      query: groupMilestones,
      debounce: 250,
      skip() {
        return !this.edit;
      },
      variables() {
        return {
          fullPath: this.groupFullPath,
          searchTitle: this.searchTitle,
          state: 'active',
          includeDescendants: true,
        };
      },
      update(data) {
        const edges = data?.group?.milestones?.edges ?? [];
        return edges.map(item => item.node);
      },
      error() {
        createFlash({ message: this.$options.i18n.fetchMilestonesError });
      },
    },
  },
  computed: {
    ...mapGetters({ issue: 'activeIssue' }),
    hasMilestone() {
      return this.issue.milestone !== null;
    },
    groupFullPath() {
      const { referencePath = '' } = this.issue;
      return referencePath.slice(0, referencePath.indexOf('/'));
    },
    projectPath() {
      const { referencePath = '' } = this.issue;
      return referencePath.slice(0, referencePath.indexOf('#'));
    },
    dropdownText() {
      return this.issue.milestone?.title ?? this.$options.i18n.noMilestone;
    },
  },
  mounted() {
    this.$root.$on('bv::dropdown::hide', () => {
      this.$refs.sidebarItem.collapse();
    });
  },
  methods: {
    ...mapActions(['setActiveIssueMilestone']),
    handleOpen() {
      this.edit = true;
      this.$refs.dropdown.show();
    },
    async setMilestone(milestoneId) {
      this.loading = true;
      this.searchTitle = '';
      this.$refs.sidebarItem.collapse();

      try {
        const input = { milestoneId, projectPath: this.projectPath };
        await this.setActiveIssueMilestone(input);
      } catch (e) {
        createFlash({ message: this.$options.i18n.updateMilestoneError });
      } finally {
        this.loading = false;
      }
    },
  },
  i18n: {
    milestone: __('Milestone'),
    noMilestone: __('No milestone'),
    assignMilestone: __('Assign milestone'),
    noMilestonesFound: s__('Milestones|No milestones found'),
    fetchMilestonesError: __('There was a problem fetching milestones.'),
    updateMilestoneError: __('An error occurred while updating the milestone.'),
  },
};
</script>

<template>
  <board-editable-item
    ref="sidebarItem"
    :title="$options.i18n.milestone"
    :loading="loading"
    @open="handleOpen()"
    @close="edit = false"
  >
    <template v-if="hasMilestone" #collapsed>
      <strong class="gl-text-gray-900">{{ issue.milestone.title }}</strong>
    </template>
    <template>
      <gl-dropdown
        ref="dropdown"
        :text="dropdownText"
        :header-text="$options.i18n.assignMilestone"
        block
      >
        <gl-search-box-by-type ref="search" v-model.trim="searchTitle" class="gl-m-3" />
        <gl-dropdown-item
          data-testid="no-milestone-item"
          :is-check-item="true"
          :is-checked="!issue.milestone"
          @click="setMilestone(null)"
        >
          {{ $options.i18n.noMilestone }}
        </gl-dropdown-item>
        <gl-dropdown-divider />
        <gl-loading-icon v-if="$apollo.loading" class="gl-py-4" />
        <template v-else-if="milestones.length > 0">
          <gl-dropdown-item
            v-for="milestone in milestones"
            :key="milestone.id"
            :is-check-item="true"
            :is-checked="issue.milestone && milestone.id === issue.milestone.id"
            data-testid="milestone-item"
            @click="setMilestone(milestone.id)"
          >
            {{ milestone.title }}
          </gl-dropdown-item>
        </template>
        <gl-dropdown-text v-else data-testid="no-milestones-found">
          {{ $options.i18n.noMilestonesFound }}
        </gl-dropdown-text>
      </gl-dropdown>
    </template>
  </board-editable-item>
</template>