Commit 91be4a2a authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '212596-pre-populate-prometheus-alert-modal' into 'master'

Pre-populate prometheus alert modal

See merge request gitlab-org/gitlab!28291
parents 509213f9 d944db54
...@@ -104,6 +104,9 @@ export default { ...@@ -104,6 +104,9 @@ export default {
formattedFiringAlerts() { formattedFiringAlerts() {
return this.firingAlerts.map(alert => this.formatAlertSummary(alert.alert_path)); return this.firingAlerts.map(alert => this.formatAlertSummary(alert.alert_path));
}, },
configuredAlert() {
return this.hasAlerts ? values(this.alertsToManage)[0].metricId : '';
},
}, },
created() { created() {
this.service = new AlertsService({ alertsEndpoint: this.alertsEndpoint }); this.service = new AlertsService({ alertsEndpoint: this.alertsEndpoint });
...@@ -271,6 +274,7 @@ export default { ...@@ -271,6 +274,7 @@ export default {
:alerts-to-manage="alertsToManage" :alerts-to-manage="alertsToManage"
:relevant-queries="relevantQueries" :relevant-queries="relevantQueries"
:error-message="errorMessage" :error-message="errorMessage"
:configured-alert="configuredAlert"
:modal-id="modalId" :modal-id="modalId"
@create="handleCreate" @create="handleCreate"
@update="handleUpdate" @update="handleUpdate"
......
...@@ -61,6 +61,11 @@ export default { ...@@ -61,6 +61,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
configuredAlert: {
type: String,
required: false,
default: '',
},
alertsToManage: { alertsToManage: {
type: Object, type: Object,
required: false, required: false,
...@@ -207,6 +212,7 @@ export default { ...@@ -207,6 +212,7 @@ export default {
:ok-disabled="formDisabled" :ok-disabled="formDisabled"
@ok="handleSubmit" @ok="handleSubmit"
@hidden="handleHidden" @hidden="handleHidden"
@shown="selectQuery(configuredAlert)"
> >
<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: Pre-populate prometheus alert modal
merge_request: 28291
author: Gilang Gumilar
type: added
...@@ -26,6 +26,7 @@ describe('AlertWidgetForm', () => { ...@@ -26,6 +26,7 @@ describe('AlertWidgetForm', () => {
alertsToManage: { alertsToManage: {
alert: { alert_path: alertPath, operator: '<', threshold: 5, metricId }, alert: { alert_path: alertPath, operator: '<', threshold: 5, metricId },
}, },
configuredAlert: metricId,
}; };
function createComponent(props = {}) { function createComponent(props = {}) {
...@@ -118,6 +119,14 @@ describe('AlertWidgetForm', () => { ...@@ -118,6 +119,14 @@ describe('AlertWidgetForm', () => {
expect(wrapper.vm.prometheusMetricId).toBe(null); expect(wrapper.vm.prometheusMetricId).toBe(null);
}); });
it('sets selectedAlert to the provided configuredAlert on modal show', () => {
createComponent(propsWithAlertData);
modal().vm.$emit('shown');
expect(wrapper.vm.selectedAlert).toEqual(propsWithAlertData.alertsToManage[alertPath]);
});
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