summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issues_list/components/jira_issues_import_status_app.vue
blob: ba0ca57523aaf7e6b2009ece8658b5fd44faf131 (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
<script>
import { GlAlert, GlLabel } from '@gitlab/ui';
import { last } from 'lodash';
import {
  calculateJiraImportLabel,
  isInProgress,
  setFinishedAlertHideMap,
  shouldShowFinishedAlert,
} from '~/jira_import/utils/jira_import_utils';
import { n__ } from '~/locale';
import getIssuesListDetailsQuery from '../queries/get_issues_list_details.query.graphql';

export default {
  name: 'JiraIssuesImportStatus',
  components: {
    GlAlert,
    GlLabel,
  },
  props: {
    canEdit: {
      type: Boolean,
      required: true,
    },
    isJiraConfigured: {
      type: Boolean,
      required: true,
    },
    issuesPath: {
      type: String,
      required: true,
    },
    projectPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      jiraImport: {},
    };
  },
  apollo: {
    jiraImport: {
      query: getIssuesListDetailsQuery,
      variables() {
        return {
          fullPath: this.projectPath,
        };
      },
      update: ({ project }) => {
        const label = calculateJiraImportLabel(
          project.jiraImports.nodes,
          project.issues.nodes.flatMap(({ labels }) => labels.nodes),
        );
        return {
          importedIssuesCount: last(project.jiraImports.nodes)?.importedIssuesCount,
          label,
          shouldShowFinishedAlert: shouldShowFinishedAlert(label.title, project.jiraImportStatus),
          shouldShowInProgressAlert: isInProgress(project.jiraImportStatus),
        };
      },
      skip() {
        return !this.isJiraConfigured || !this.canEdit;
      },
    },
  },
  computed: {
    finishedMessage() {
      return n__(
        '%d issue successfully imported with the label',
        '%d issues successfully imported with the label',
        this.jiraImport.importedIssuesCount,
      );
    },
    labelTarget() {
      return `${this.issuesPath}?label_name[]=${encodeURIComponent(this.jiraImport.label.title)}`;
    },
  },
  methods: {
    hideFinishedAlert() {
      setFinishedAlertHideMap(this.jiraImport.label.title);
      this.jiraImport.shouldShowFinishedAlert = false;
    },
    hideInProgressAlert() {
      this.jiraImport.shouldShowInProgressAlert = false;
    },
  },
};
</script>

<template>
  <div class="gl-my-5">
    <gl-alert v-if="jiraImport.shouldShowInProgressAlert" @dismiss="hideInProgressAlert">
      {{ __('Import in progress. Refresh page to see newly added issues.') }}
    </gl-alert>

    <gl-alert
      v-else-if="jiraImport.shouldShowFinishedAlert"
      variant="success"
      @dismiss="hideFinishedAlert"
    >
      {{ finishedMessage }}
      <gl-label
        :background-color="jiraImport.label.color"
        scoped
        size="sm"
        :target="labelTarget"
        :title="jiraImport.label.title"
      />
    </gl-alert>
  </div>
</template>