Browse Source

Clear query models when changing data source type, fixes #14394

Torkel Ödegaard 7 years ago
parent
commit
acf24bd679
1 changed files with 11 additions and 4 deletions
  1. 11 4
      public/app/features/panel/metrics_tab.ts

+ 11 - 4
public/app/features/panel/metrics_tab.ts

@@ -89,10 +89,17 @@ export class MetricsTabCtrl {
           target.datasource = config.defaultDatasource;
           target.datasource = config.defaultDatasource;
         }
         }
       });
       });
-    } else if (this.datasourceInstance && this.datasourceInstance.meta.mixed) {
-      _.each(this.panel.targets, target => {
-        delete target.datasource;
-      });
+    } else if (this.datasourceInstance) {
+      // if switching from mixed
+      if (this.datasourceInstance.meta.mixed) {
+        _.each(this.panel.targets, target => {
+          delete target.datasource;
+        });
+      } else if (this.datasourceInstance.meta.id !== datasource.meta.id) {
+        // we are changing data source type, clear queries
+        this.panel.targets = [{ refId: 'A' }];
+        this.panelCtrl.nextRefId = this.dashboard.getNextQueryLetter(this.panel);
+      }
     }
     }
 
 
     this.datasourceInstance = datasource;
     this.datasourceInstance = datasource;