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

move_issue_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: 581537264db8be81b8cf124142f067f52ca1a2b6 (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
<script>
import ProjectSelect from '~/sidebar/components/move/issuable_move_dropdown.vue';
import { __ } from '~/locale';
import { createAlert } from '~/alert';
import { visitUrl } from '~/lib/utils/url_utility';
import moveIssueMutation from '../../queries/move_issue.mutation.graphql';

export default {
  name: 'MoveIssueButton',
  components: { ProjectSelect },
  inject: ['projectsAutocompleteEndpoint', 'projectFullPath', 'issueIid'],

  i18n: {
    title: __('Move issue'),
    titleInProgress: __('Moving issue'),
    moveErrorMessage: __('An error occurred while moving the issue.'),
  },
  data() {
    return {
      moveInProgress: false,
    };
  },
  computed: {
    dropdownButtonTitle() {
      return this.moveInProgress ? this.$options.i18n.titleInProgress : this.$options.i18n.title;
    },
  },
  methods: {
    async moveIssue(targetProject) {
      this.moveInProgress = true;

      try {
        const { data } = await this.$apollo.mutate({
          mutation: moveIssueMutation,
          variables: {
            moveIssueInput: {
              projectPath: this.projectFullPath,
              iid: this.issueIid,
              targetProjectPath: targetProject.full_path,
            },
          },
        });

        if (!data.issueMove) return;

        const { errors } = data.issueMove;
        if (errors?.length > 0) {
          throw new Error(`Error moving the issue. Error message: ${errors[0].message}`);
        }

        visitUrl(data.issueMove?.issue.webUrl);
      } catch (error) {
        createAlert({
          message: this.$options.i18n.moveErrorMessage,
          captureError: true,
          error,
        });
      } finally {
        this.moveInProgress = false;
      }
    },
  },
};
</script>
<template>
  <project-select
    :projects-fetch-path="projectsAutocompleteEndpoint"
    :dropdown-button-title="dropdownButtonTitle"
    :dropdown-header-title="$options.i18n.title"
    :move-in-progress="moveInProgress"
    @move-issuable="moveIssue"
  />
</template>