summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/move/move_issue_button.vue
blob: e1259fad6a7f8ca2df526fc320525a88bf38876c (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
<script>
import ProjectSelect from '~/sidebar/components/move/issuable_move_dropdown.vue';
import { __ } from '~/locale';
import { createAlert } from '~/flash';
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: {
    moveIssue(targetProject) {
      this.moveInProgress = true;
      return this.$apollo
        .mutate({
          mutation: moveIssueMutation,
          variables: {
            moveIssueInput: {
              projectPath: this.projectFullPath,
              iid: this.issueIid,
              targetProjectPath: targetProject.full_path,
            },
          },
        })
        .then(({ data = {} }) => {
          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) => {
          this.moveInProgress = false;
          createAlert({
            message: this.$options.i18n.moveErrorMessage,
            captureError: true,
            error,
          });
        });
    },
  },
};
</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>