From 3410fb44e9b0de435c547d1b390d75cb8925ea26 Mon Sep 17 00:00:00 2001 From: lzd <24379844+lzdw@users.noreply.github.com> Date: Wed, 4 Sep 2019 20:00:37 +0800 Subject: [PATCH] Annotations: check if the name exists before creating a new annotation (#18880) --- public/app/features/annotations/editor_ctrl.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/app/features/annotations/editor_ctrl.ts b/public/app/features/annotations/editor_ctrl.ts index 971809055d4..56c87a31a38 100644 --- a/public/app/features/annotations/editor_ctrl.ts +++ b/public/app/features/annotations/editor_ctrl.ts @@ -4,6 +4,7 @@ import $ from 'jquery'; import coreModule from 'app/core/core_module'; import { DashboardModel } from 'app/features/dashboard/state'; import DatasourceSrv from '../plugins/datasource_srv'; +import appEvents from 'app/core/app_events'; export class AnnotationsEditorCtrl { mode: any; @@ -97,6 +98,11 @@ export class AnnotationsEditorCtrl { } add() { + const sameName: any = _.find(this.annotations, { name: this.currentAnnotation.name }); + if (sameName) { + appEvents.emit('alert-warning', ['Validation', 'Annotations with the same name already exists']); + return; + } this.annotations.push(this.currentAnnotation); this.reset(); this.mode = 'list';