Преглед изворни кода

support both uid and id for showing/removing notifiers

bergquist пре 7 година
родитељ
комит
48aa173f67

+ 16 - 5
public/app/features/alerting/AlertTabCtrl.ts

@@ -142,7 +142,9 @@ export class AlertTabCtrl {
       isDefault: false,
       isDefault: false,
       uid: model.uid
       uid: model.uid
     });
     });
-    if (!_.find(this.alert.notifications, { id: model.id})) {
+
+    // avoid duplicates using both id and uid to be backwards compatible.
+    if (!_.find(this.alert.notifications, n => n.id === model.id || n.uid === model.uid)) {
       this.alert.notifications.push({ uid: model.uid });
       this.alert.notifications.push({ uid: model.uid });
     }
     }
 
 
@@ -152,9 +154,11 @@ export class AlertTabCtrl {
     this.addNotificationSegment.fake = true;
     this.addNotificationSegment.fake = true;
   }
   }
 
 
-  removeNotification(deleteUid) {
-    _.remove(this.alert.notifications, { uid: deleteUid});
-    _.remove(this.alertNotifications, { uid: deleteUid});
+  removeNotification(an) {
+    // remove notifiers refeered to by id and uid to support notifiers added
+    // before and after we added support for uid
+    _.remove(this.alert.notifications, n =>  n.uid === an.uid || n.id === an.id);
+    _.remove(this.alertNotifications, n =>  n.uid === an.uid || n.id === an.id);
   }
   }
 
 
   initModel() {
   initModel() {
@@ -190,7 +194,14 @@ export class AlertTabCtrl {
     ThresholdMapper.alertToGraphThresholds(this.panel);
     ThresholdMapper.alertToGraphThresholds(this.panel);
 
 
     for (const addedNotification of alert.notifications) {
     for (const addedNotification of alert.notifications) {
-      const model = _.find(this.notifications, { id: addedNotification.id });
+      // lookup notifier type by uid
+      let model = _.find(this.notifications, { uid: addedNotification.uid });
+
+      // fallback to using id if uid is missing
+      if (!model) {
+        model = _.find(this.notifications, { id: addedNotification.id });
+      }
+
       if (model && model.isDefault === false) {
       if (model && model.isDefault === false) {
         model.iconClass = this.getNotificationIcon(model.type);
         model.iconClass = this.getNotificationIcon(model.type);
         this.alertNotifications.push(model);
         this.alertNotifications.push(model);

+ 1 - 1
public/app/features/alerting/partials/alert_tab.html

@@ -135,7 +135,7 @@
         <div class="gf-form" ng-repeat="nc in ctrl.alertNotifications">
         <div class="gf-form" ng-repeat="nc in ctrl.alertNotifications">
           <span class="gf-form-label" ng-style="{'background-color': nc.bgColor }">
           <span class="gf-form-label" ng-style="{'background-color': nc.bgColor }">
             <i class="{{nc.iconClass}}"></i>&nbsp;{{nc.name}}&nbsp;
             <i class="{{nc.iconClass}}"></i>&nbsp;{{nc.name}}&nbsp;
-            <i class="fa fa-remove pointer muted" ng-click="ctrl.removeNotification(nc.uid)" ng-if="nc.isDefault === false"></i>
+            <i class="fa fa-remove pointer muted" ng-click="ctrl.removeNotification(nc)" ng-if="nc.isDefault === false"></i>
           </span>
           </span>
         </div>
         </div>
         <div class="gf-form">
         <div class="gf-form">