Commit 91b93d06 authored by Alexander Turinske's avatar Alexander Turinske

Fix sorting issue with alert statuses

- I tried to over-engineer the status change UI and broke
  status sorting
- fixed it by simplifying it
parent a7395c71
<script> <script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { s__ } from '~/locale';
// TODO once backend is settled, update by either abstracting this out to app/assets/javascripts/graphql_shared or create new, modified query in #287757 // TODO once backend is settled, update by either abstracting this out to app/assets/javascripts/graphql_shared or create new, modified query in #287757
import updateAlertStatusMutation from '~/alert_management/graphql/mutations/update_alert_status.mutation.graphql'; import updateAlertStatusMutation from '~/alert_management/graphql/mutations/update_alert_status.mutation.graphql';
import { MESSAGES, STATUSES } from './constants';
export default { export default {
i18n: { i18n: {
updateError: s__( STATUSES,
'ThreatMonitoring|There was an error while updating the status of the alert. Please try again.',
),
},
statuses: {
TRIGGERED: s__('ThreatMonitoring|Unreviewed'),
ACKNOWLEDGED: s__('ThreatMonitoring|In review'),
RESOLVED: s__('ThreatMonitoring|Resolved'),
IGNORED: s__('ThreatMonitoring|Dismissed'),
}, },
components: { components: {
GlDropdown, GlDropdown,
...@@ -33,16 +25,14 @@ export default { ...@@ -33,16 +25,14 @@ export default {
data() { data() {
return { return {
isUpdating: false, isUpdating: false,
status: this.alert.status,
}; };
}, },
methods: { methods: {
handleError() { handleError() {
this.$emit('alert-error', this.$options.i18n.updateError); this.$emit('alert-error', MESSAGES.UPDATE_STATUS_ERROR);
}, },
async updateAlertStatus(status) { async updateAlertStatus(status) {
this.isUpdating = true; this.isUpdating = true;
this.status = status;
try { try {
const { data } = await this.$apollo.mutate({ const { data } = await this.$apollo.mutate({
mutation: updateAlertStatusMutation, mutation: updateAlertStatusMutation,
...@@ -60,7 +50,6 @@ export default { ...@@ -60,7 +50,6 @@ export default {
this.$emit('alert-update'); this.$emit('alert-update');
} catch { } catch {
this.status = this.alert.status;
this.handleError(); this.handleError();
} finally { } finally {
this.isUpdating = false; this.isUpdating = false;
...@@ -75,16 +64,16 @@ export default { ...@@ -75,16 +64,16 @@ export default {
<gl-dropdown <gl-dropdown
:loading="isUpdating" :loading="isUpdating"
right right
:text="$options.statuses[status]" :text="$options.i18n.STATUSES[alert.status]"
class="gl-w-full" class="gl-w-full"
toggle-class="dropdown-menu-toggle" toggle-class="dropdown-menu-toggle"
> >
<div class="dropdown-content dropdown-body"> <div class="dropdown-content dropdown-body">
<gl-dropdown-item <gl-dropdown-item
v-for="(label, field) in $options.statuses" v-for="(label, field) in $options.i18n.STATUSES"
:key="field" :key="field"
:active="field === status" :active="field === alert.status"
active-class="'is-active'" active-class="is-active"
@click="updateAlertStatus(field)" @click="updateAlertStatus(field)"
> >
{{ label }} {{ label }}
......
...@@ -8,6 +8,9 @@ export const MESSAGES = { ...@@ -8,6 +8,9 @@ export const MESSAGES = {
"ThreatMonitoring|There was an error displaying the alerts. Confirm your endpoint's configuration details to ensure alerts appear.", "ThreatMonitoring|There was an error displaying the alerts. Confirm your endpoint's configuration details to ensure alerts appear.",
), ),
NO_ALERTS: s__('ThreatMonitoring|No alerts to display.'), NO_ALERTS: s__('ThreatMonitoring|No alerts to display.'),
UPDATE_STATUS_ERROR: s__(
'ThreatMonitoring|There was an error while updating the status of the alert. Please try again.',
),
}; };
export const STATUSES = { export const STATUSES = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment