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

move_issues_button.vue « move « components « sidebar « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab4ac9500ad592648a44342d9ee7ab1aaf446b2d (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
162
163
164
165
166
167
168
169
170
171
<script>
import { GlAlert } from '@gitlab/ui';
import { createAlert } from '~/flash';
import { logError } from '~/lib/logger';
import { s__ } from '~/locale';
import {
  WORK_ITEM_TYPE_ENUM_ISSUE,
  WORK_ITEM_TYPE_ENUM_INCIDENT,
  WORK_ITEM_TYPE_ENUM_TASK,
  WORK_ITEM_TYPE_ENUM_TEST_CASE,
} from '~/work_items/constants';
import issuableEventHub from '~/issues/list/eventhub';
import getIssuesQuery from 'ee_else_ce/issues/list/queries/get_issues.query.graphql';
import getIssuesCountQuery from 'ee_else_ce/issues/list/queries/get_issues_counts.query.graphql';
import moveIssueMutation from '../../queries/move_issue.mutation.graphql';
import IssuableMoveDropdown from './issuable_move_dropdown.vue';

export default {
  name: 'MoveIssuesButton',
  components: {
    IssuableMoveDropdown,
    GlAlert,
  },
  props: {
    projectFullPath: {
      type: String,
      required: true,
    },
    projectsFetchPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      selectedIssuables: [],
      moveInProgress: false,
    };
  },
  computed: {
    cannotMoveTasksWarningTitle() {
      if (this.tasksSelected && this.testCasesSelected) {
        return s__('Issues|Tasks and test cases can not be moved.');
      }

      if (this.testCasesSelected) {
        return s__('Issues|Test cases can not be moved.');
      }

      return s__('Issues|Tasks can not be moved.');
    },
    issuesSelected() {
      return this.selectedIssuables.some((item) => item.type === WORK_ITEM_TYPE_ENUM_ISSUE);
    },
    incidentsSelected() {
      return this.selectedIssuables.some((item) => item.type === WORK_ITEM_TYPE_ENUM_INCIDENT);
    },
    tasksSelected() {
      return this.selectedIssuables.some((item) => item.type === WORK_ITEM_TYPE_ENUM_TASK);
    },
    testCasesSelected() {
      return this.selectedIssuables.some((item) => item.type === WORK_ITEM_TYPE_ENUM_TEST_CASE);
    },
  },
  mounted() {
    issuableEventHub.$on('issuables:issuableChecked', this.handleIssuableChecked);
  },
  beforeDestroy() {
    issuableEventHub.$off('issuables:issuableChecked', this.handleIssuableChecked);
  },
  methods: {
    handleIssuableChecked(issuable, value) {
      if (value) {
        this.selectedIssuables.push(issuable);
      } else {
        const index = this.selectedIssuables.indexOf(issuable);
        if (index > -1) {
          this.selectedIssuables.splice(index, 1);
        }
      }
    },
    moveIssues(targetProject) {
      const iids = this.selectedIssuables.reduce((result, issueData) => {
        if (
          issueData.type === WORK_ITEM_TYPE_ENUM_ISSUE ||
          issueData.type === WORK_ITEM_TYPE_ENUM_INCIDENT
        ) {
          result.push(issueData.iid);
        }
        return result;
      }, []);

      if (iids.length === 0) {
        return;
      }

      this.moveInProgress = true;
      issuableEventHub.$emit('issuables:bulkMoveStarted');

      const promises = iids.map((id) => {
        return this.moveIssue(id, targetProject);
      });

      Promise.all(promises)
        .then((promisesResult) => {
          let foundError = false;

          for (const promiseResult of promisesResult) {
            if (promiseResult.data.issueMove?.errors?.length) {
              foundError = true;
              logError(
                `Error moving issue. Error message: ${promiseResult.data.issueMove.errors[0].message}`,
              );
            }
          }

          if (!foundError) {
            const client = this.$apollo.provider.defaultClient;
            client.refetchQueries({
              include: [getIssuesQuery, getIssuesCountQuery],
            });
            this.moveInProgress = false;
            this.selectedIssuables = [];
            issuableEventHub.$emit('issuables:bulkMoveEnded');
          } else {
            throw new Error();
          }
        })
        .catch(() => {
          this.moveInProgress = false;
          issuableEventHub.$emit('issuables:bulkMoveEnded');

          createAlert({
            message: s__(`Issues|There was an error while moving the issues.`),
          });
        });
    },
    moveIssue(issueIid, targetProject) {
      return this.$apollo.mutate({
        mutation: moveIssueMutation,
        variables: {
          moveIssueInput: {
            projectPath: this.projectFullPath,
            iid: issueIid,
            targetProjectPath: targetProject.full_path,
          },
        },
      });
    },
  },
  i18n: {
    dropdownButtonTitle: s__('Issues|Move selected'),
  },
};
</script>
<template>
  <div>
    <issuable-move-dropdown
      :project-full-path="projectFullPath"
      :projects-fetch-path="projectsFetchPath"
      :move-in-progress="moveInProgress"
      :disabled="!issuesSelected && !incidentsSelected"
      :dropdown-header-title="$options.i18n.dropdownButtonTitle"
      :dropdown-button-title="$options.i18n.dropdownButtonTitle"
      @move-issuable="moveIssues"
    />
    <gl-alert v-if="tasksSelected || testCasesSelected" :dismissible="false" variant="warning">
      {{ cannotMoveTasksWarningTitle }}
    </gl-alert>
  </div>
</template>