summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/incidents/sidebar_escalation_status.vue
blob: f7daad63f454659a80322b0a00daa837b0e906f2 (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
<script>
import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { createAlert } from '~/flash';
import { logError } from '~/lib/logger';
import EscalationStatus from 'ee_else_ce/sidebar/components/incidents/escalation_status.vue';
import {
  escalationStatusQuery,
  escalationStatusMutation,
  INCIDENTS_I18N as i18n,
} from '../../constants';
import { getStatusLabel } from '../../utils';
import SidebarEditableItem from '../sidebar_editable_item.vue';

export default {
  i18n,
  components: {
    EscalationStatus,
    SidebarEditableItem,
    GlIcon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    iid: {
      type: String,
      required: true,
    },
    projectPath: {
      type: String,
      required: true,
    },
    issuableType: {
      required: true,
      type: String,
    },
  },
  data() {
    return {
      status: null,
      isUpdating: false,
    };
  },
  apollo: {
    status: {
      query() {
        return escalationStatusQuery;
      },
      variables() {
        return {
          fullPath: this.projectPath,
          iid: this.iid,
        };
      },
      update(data) {
        return data.workspace?.issuable?.escalationStatus;
      },
      error(error) {
        const message = this.$options.i18n.fetchError;
        createAlert({ message });
        logError(message, error);
      },
    },
  },
  computed: {
    isLoading() {
      return this.$apollo.queries.status.loading;
    },
    currentStatusLabel() {
      return getStatusLabel(this.status);
    },
    tooltipText() {
      return `${this.$options.i18n.title}: ${this.currentStatusLabel}`;
    },
  },
  methods: {
    updateStatus(status) {
      this.isUpdating = true;
      this.closeSidebar();
      return this.$apollo
        .mutate({
          mutation: escalationStatusMutation,
          variables: {
            status,
            iid: this.iid,
            projectPath: this.projectPath,
          },
        })
        .then(({ data: { issueSetEscalationStatus } }) => {
          this.status = issueSetEscalationStatus.issue.escalationStatus;
        })
        .catch((error) => {
          const message = this.$options.i18n.updateError;
          createAlert({ message });
          logError(message, error);
        })
        .finally(() => {
          this.isUpdating = false;
        });
    },
    closeSidebar() {
      this.close();
      this.$refs.editable.collapse();
    },
    open() {
      this.$refs.escalationStatus.show();
    },
    close() {
      this.$refs.escalationStatus.hide();
    },
  },
};
</script>

<template>
  <sidebar-editable-item
    ref="editable"
    :title="$options.i18n.title"
    :initial-loading="isLoading"
    :loading="isUpdating"
    @open="open"
    @close="close"
  >
    <template #default>
      <escalation-status ref="escalationStatus" :value="status" @input="updateStatus" />
    </template>
    <template #collapsed>
      <div
        v-gl-tooltip.viewport.left="tooltipText"
        class="sidebar-collapsed-icon"
        data-testid="status-icon"
      >
        <gl-icon name="status" :size="16" />
      </div>
      <span class="hide-collapsed text-secondary">{{ currentStatusLabel }}</span>
    </template>
  </sidebar-editable-item>
</template>