Просмотр исходного кода

fix(panel/common): fix for query letters when importing old dashboards, fixes #2943

Torkel Ödegaard 10 лет назад
Родитель
Сommit
c95a991cb3
2 измененных файлов с 23 добавлено и 5 удалено
  1. 15 4
      public/app/features/dashboard/dashboardSrv.js
  2. 8 1
      public/test/specs/dashboardSrv-specs.js

+ 15 - 4
public/app/features/dashboard/dashboardSrv.js

@@ -328,9 +328,20 @@ function (angular, $, kbn, _, moment) {
         }
         }
       }
       }
 
 
-      if (oldVersion < 7 && old.nav && old.nav.length) {
-        this.timepicker = old.nav[0];
-        delete this.nav;
+      if (oldVersion < 7) {
+        if (old.nav && old.nav.length) {
+          this.timepicker = old.nav[0];
+          delete this.nav;
+        }
+
+        // ensure query refIds
+        panelUpgrades.push(function(panel) {
+          _.each(panel.targets, function(target) {
+            if (!target.refId) {
+              target.refId = this.getNextQueryLetter(panel);
+            }
+          }, this);
+        });
       }
       }
 
 
       if (panelUpgrades.length === 0) {
       if (panelUpgrades.length === 0) {
@@ -341,7 +352,7 @@ function (angular, $, kbn, _, moment) {
         var row = this.rows[i];
         var row = this.rows[i];
         for (j = 0; j < row.panels.length; j++) {
         for (j = 0; j < row.panels.length; j++) {
           for (k = 0; k < panelUpgrades.length; k++) {
           for (k = 0; k < panelUpgrades.length; k++) {
-            panelUpgrades[k](row.panels[j]);
+            panelUpgrades[k].call(this, row.panels[j]);
           }
           }
         }
         }
       }
       }

+ 8 - 1
public/test/specs/dashboardSrv-specs.js

@@ -152,7 +152,10 @@ define([
           rows: [
           rows: [
             {
             {
               panels: [
               panels: [
-                {type: 'graphite', legend: true, aliasYAxis: { test: 2 }, grid: { min: 1, max: 10 }}
+                {
+                  type: 'graphite', legend: true, aliasYAxis: { test: 2 }, grid: { min: 1, max: 10 },
+                  targets: [{refId: 'A'}, {}],
+                }
               ]
               ]
             }
             }
           ]
           ]
@@ -178,6 +181,10 @@ define([
         expect(graph.type).to.be('graph');
         expect(graph.type).to.be('graph');
       });
       });
 
 
+      it('queries without refId should get it', function() {
+        expect(graph.targets[1].refId).to.be('B');
+      });
+
       it('update legend setting', function() {
       it('update legend setting', function() {
         expect(graph.legend.show).to.be(true);
         expect(graph.legend.show).to.be(true);
       });
       });