Commit 9d117cd5 authored by Gilang Gumilar's avatar Gilang Gumilar

Auto-select single metric alert

parent f05e3d46
...@@ -177,6 +177,13 @@ export default { ...@@ -177,6 +177,13 @@ export default {
prometheus_metric_id: this.prometheusMetricId, prometheus_metric_id: this.prometheusMetricId,
}); });
}, },
handleShown() {
if (this.configuredAlert) {
this.selectQuery(this.configuredAlert);
} else if (this.relevantQueries.length === 1) {
this.selectQuery(this.relevantQueries[0].metricId);
}
},
resetAlertData() { resetAlertData() {
this.operator = null; this.operator = null;
this.threshold = null; this.threshold = null;
...@@ -212,7 +219,7 @@ export default { ...@@ -212,7 +219,7 @@ export default {
:ok-disabled="formDisabled" :ok-disabled="formDisabled"
@ok="handleSubmit" @ok="handleSubmit"
@hidden="handleHidden" @hidden="handleHidden"
@shown="selectQuery(configuredAlert)" @shown="handleShown"
> >
<div v-if="errorMessage" class="alert-modal-message danger_message">{{ errorMessage }}</div> <div v-if="errorMessage" class="alert-modal-message danger_message">{{ errorMessage }}</div>
<div class="alert-form"> <div class="alert-form">
......
---
title: Select the first option if there is only one metric option on alerts dropdown.
merge_request: 29857
author: Gilang Gumilar
type: added
...@@ -127,6 +127,38 @@ describe('AlertWidgetForm', () => { ...@@ -127,6 +127,38 @@ describe('AlertWidgetForm', () => {
expect(wrapper.vm.selectedAlert).toEqual(propsWithAlertData.alertsToManage[alertPath]); expect(wrapper.vm.selectedAlert).toEqual(propsWithAlertData.alertsToManage[alertPath]);
}); });
it('sets selectedAlert to the first relevantQueries if there is only one option on modal show', () => {
createComponent({
...propsWithAlertData,
configuredAlert: '',
});
modal().vm.$emit('shown');
expect(wrapper.vm.selectedAlert).toEqual(propsWithAlertData.alertsToManage[alertPath]);
});
it('does not set selectedAlert to the first relevantQueries if there is more than one option on modal show', () => {
createComponent({
relevantQueries: [
{
metricId: '8',
alertPath: 'alert',
label: 'alert-label',
},
{
metricId: '9',
alertPath: 'alert',
label: 'alert-label',
},
],
});
modal().vm.$emit('shown');
expect(wrapper.vm.selectedAlert).toEqual({});
});
describe('with existing alert', () => { describe('with existing alert', () => {
beforeEach(() => { beforeEach(() => {
createComponent(propsWithAlertData); createComponent(propsWithAlertData);
......
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