Pārlūkot izejas kodu

HUE-7693 [assist] Make sure the right database is opened when a query is opened

Johan Ahlen 8 gadi atpakaļ
vecāks
revīzija
7ba57d0

+ 4 - 4
desktop/core/src/desktop/templates/assist.mako

@@ -1222,7 +1222,7 @@ from desktop.views import _ko
             }, 0);
           });
 
-          huePubSub.subscribe("assist.set.database", function (databaseDef) {
+          huePubSub.subscribe('assist.set.database', function (databaseDef) {
             if (!databaseDef.source || !self.sourceIndex[databaseDef.source]) {
               return;
             }
@@ -1230,14 +1230,14 @@ from desktop.views import _ko
             self.setDatabaseWhenLoaded(databaseDef.name);
           });
 
-          huePubSub.subscribe("assist.get.database", function (source) {
+          huePubSub.subscribe('assist.get.database', function (source) {
             if (self.sourceIndex[source] && self.sourceIndex[source].selectedDatabase()) {
-              huePubSub.publish("assist.database.set", {
+              huePubSub.publish('assist.database.set', {
                 source: source,
                 name: self.sourceIndex[source].selectedDatabase().databaseName
               });
             } else {
-              huePubSub.publish("assist.database.set", {
+              huePubSub.publish('assist.database.set', {
                 source: source,
                 name: 'default'
               });

+ 23 - 11
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2684,17 +2684,6 @@ var EditorViewModel = (function() {
     self.loadingScheduler = ko.observable(false);
 
 
-    huePubSub.subscribeOnce('assist.db.panel.ready', function () {
-      if (self.type().indexOf('query') === 0 && self.snippets().length == 1) {
-        huePubSub.publish('assist.set.database', {
-          source: self.snippets()[0].type(),
-          name: self.snippets()[0].database()
-        });
-      }
-    }, vm.huePubSubId);
-
-    huePubSub.publish('assist.is.db.panel.ready');
-
     // Init
     if (notebook.snippets) {
       $.each(notebook.snippets, function (index, snippet) {
@@ -2715,6 +2704,29 @@ var EditorViewModel = (function() {
         });
       }
     }
+
+    huePubSub.subscribeOnce('assist.db.panel.ready', function () {
+      if (self.type().indexOf('query') === 0) {
+        if (self.snippets().length === 1) {
+          huePubSub.publish('assist.set.database', {
+            source: self.snippets()[0].type(),
+            name: self.snippets()[0].database()
+          });
+        } else {
+          var snippetsSub = self.snippets.subscribe(function (snippets) {
+            if (snippets.length === 1) {
+              huePubSub.publish('assist.set.database', {
+                source: self.snippets()[0].type(),
+                name: self.snippets()[0].database()
+              });
+            }
+            snippetsSub.dispose();
+          })
+        }
+      }
+    }, vm.huePubSubId);
+
+    huePubSub.publish('assist.is.db.panel.ready');
   };
 
   function EditorViewModel(editor_id, notebooks, options, CoordinatorEditorViewModel, RunningCoordinatorModel) {