2020-07-28 23:09:34 +05:30
|
|
|
<script>
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { s__ } from '~/locale';
|
|
|
|
import Tracking from '~/tracking';
|
|
|
|
import { trackAlertStatusUpdateOptions } from '../constants';
|
2021-01-03 14:25:43 +05:30
|
|
|
import updateAlertStatusMutation from '../graphql/mutations/update_alert_status.mutation.graphql';
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
i18n: {
|
|
|
|
UPDATE_ALERT_STATUS_ERROR: s__(
|
|
|
|
'AlertManagement|There was an error while updating the status of the alert.',
|
|
|
|
),
|
|
|
|
UPDATE_ALERT_STATUS_INSTRUCTION: s__('AlertManagement|Please try again.'),
|
|
|
|
},
|
|
|
|
statuses: {
|
|
|
|
TRIGGERED: s__('AlertManagement|Triggered'),
|
|
|
|
ACKNOWLEDGED: s__('AlertManagement|Acknowledged'),
|
|
|
|
RESOLVED: s__('AlertManagement|Resolved'),
|
|
|
|
},
|
|
|
|
components: {
|
2021-01-03 14:25:43 +05:30
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
2020-07-28 23:09:34 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
alert: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isDropdownShowing: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
isSidebar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
dropdownClass() {
|
|
|
|
// eslint-disable-next-line no-nested-ternary
|
|
|
|
return this.isSidebar ? (this.isDropdownShowing ? 'show' : 'gl-display-none') : '';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateAlertStatus(status) {
|
|
|
|
this.$emit('handle-updating', true);
|
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
2021-01-03 14:25:43 +05:30
|
|
|
mutation: updateAlertStatusMutation,
|
2020-07-28 23:09:34 +05:30
|
|
|
variables: {
|
|
|
|
iid: this.alert.iid,
|
|
|
|
status: status.toUpperCase(),
|
|
|
|
projectPath: this.projectPath,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(resp => {
|
|
|
|
this.trackStatusUpdate(status);
|
|
|
|
const errors = resp.data?.updateAlertStatus?.errors || [];
|
|
|
|
|
|
|
|
if (errors[0]) {
|
|
|
|
this.$emit(
|
|
|
|
'alert-error',
|
|
|
|
`${this.$options.i18n.UPDATE_ALERT_STATUS_ERROR} ${errors[0]}`,
|
|
|
|
);
|
|
|
|
}
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
this.$emit('hide-dropdown');
|
2020-07-28 23:09:34 +05:30
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$emit(
|
|
|
|
'alert-error',
|
|
|
|
`${this.$options.i18n.UPDATE_ALERT_STATUS_ERROR} ${this.$options.i18n.UPDATE_ALERT_STATUS_INSTRUCTION}`,
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.$emit('handle-updating', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
trackStatusUpdate(status) {
|
|
|
|
const { category, action, label } = trackAlertStatusUpdateOptions;
|
|
|
|
Tracking.event(category, action, { label, property: status });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="dropdown dropdown-menu-selectable" :class="dropdownClass">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-dropdown
|
2020-07-28 23:09:34 +05:30
|
|
|
ref="dropdown"
|
|
|
|
right
|
|
|
|
:text="$options.statuses[alert.status]"
|
|
|
|
class="w-100"
|
|
|
|
toggle-class="dropdown-menu-toggle"
|
|
|
|
@keydown.esc.native="$emit('hide-dropdown')"
|
|
|
|
@hide="$emit('hide-dropdown')"
|
|
|
|
>
|
2021-01-03 14:25:43 +05:30
|
|
|
<p v-if="isSidebar" class="gl-new-dropdown-header-top" data-testid="dropdown-header">
|
|
|
|
{{ s__('AlertManagement|Assign status') }}
|
|
|
|
</p>
|
2020-07-28 23:09:34 +05:30
|
|
|
<div class="dropdown-content dropdown-body">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-dropdown-item
|
2020-07-28 23:09:34 +05:30
|
|
|
v-for="(label, field) in $options.statuses"
|
|
|
|
:key="field"
|
|
|
|
data-testid="statusDropdownItem"
|
|
|
|
:active="label.toUpperCase() === alert.status"
|
|
|
|
:active-class="'is-active'"
|
|
|
|
@click="updateAlertStatus(label)"
|
|
|
|
>
|
|
|
|
{{ label }}
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown-item>
|
2020-07-28 23:09:34 +05:30
|
|
|
</div>
|
2021-01-03 14:25:43 +05:30
|
|
|
</gl-dropdown>
|
2020-07-28 23:09:34 +05:30
|
|
|
</div>
|
|
|
|
</template>
|