summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issuables_list/components/issuable_list_root_app.vue
blob: 49a89d15c35a0ced911c0a2db83dfe9409554e32 (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
<script>
import { GlAlert, GlLabel } from '@gitlab/ui';
import getIssuesListDetailsQuery from '../queries/get_issues_list_details.query.graphql';
import {
  calculateJiraImportLabel,
  isFinished,
  isInProgress,
} from '~/jira_import/utils/jira_import_utils';

export default {
  name: 'IssuableListRoot',
  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 {
      isFinishedAlertShowing: true,
      isInProgressAlertShowing: true,
      jiraImport: {},
    };
  },
  apollo: {
    jiraImport: {
      query: getIssuesListDetailsQuery,
      variables() {
        return {
          fullPath: this.projectPath,
        };
      },
      update: ({ project }) => ({
        isInProgress: isInProgress(project.jiraImportStatus),
        isFinished: isFinished(project.jiraImportStatus),
        label: calculateJiraImportLabel(
          project.jiraImports.nodes,
          project.issues.nodes.flatMap(({ labels }) => labels.nodes),
        ),
      }),
      skip() {
        return !this.isJiraConfigured || !this.canEdit;
      },
    },
  },
  computed: {
    labelTarget() {
      return `${this.issuesPath}?label_name[]=${encodeURIComponent(this.jiraImport.label.title)}`;
    },
    shouldShowFinishedAlert() {
      return this.isFinishedAlertShowing && this.jiraImport.isFinished;
    },
    shouldShowInProgressAlert() {
      return this.isInProgressAlertShowing && this.jiraImport.isInProgress;
    },
  },
  methods: {
    hideFinishedAlert() {
      this.isFinishedAlertShowing = false;
    },
    hideInProgressAlert() {
      this.isInProgressAlertShowing = false;
    },
  },
};
</script>

<template>
  <div class="issuable-list-root">
    <gl-alert v-if="shouldShowInProgressAlert" @dismiss="hideInProgressAlert">
      {{ __('Import in progress. Refresh page to see newly added issues.') }}
    </gl-alert>
    <gl-alert v-if="shouldShowFinishedAlert" variant="success" @dismiss="hideFinishedAlert">
      {{ __('Issues successfully imported with the label') }}
      <gl-label
        :background-color="jiraImport.label.color"
        scoped
        size="sm"
        :target="labelTarget"
        :title="jiraImport.label.title"
      />
    </gl-alert>
  </div>
</template>