Browse Source

HUE-6146 [assist] Update the assist source when switching editor in Hue 4

This also takes care of setting the initial database when starting the Impala editor after Hive
Johan Ahlen 8 năm trước cách đây
mục cha
commit
c892c60

+ 16 - 2
desktop/core/src/desktop/templates/assist.mako

@@ -999,12 +999,26 @@ from notebook.conf import get_ordered_interpreters
           } else {
             huePubSub.publish("assist.database.set", {
               source: source,
-              name: null
+              name: 'default'
             });
           }
         });
 
-        huePubSub.publish("assist.db.panel.ready");
+        huePubSub.subscribe('assist.get.source', function () {
+          huePubSub.publish('assist.source.set', self.selectedSource().type);
+        });
+
+        huePubSub.subscribe('assist.set.source', function (source) {
+          if (self.sourceIndex[source]) {
+            self.selectedSource(self.sourceIndex[source]);
+          }
+        });
+
+        huePubSub.publish('assist.db.panel.ready');
+
+        huePubSub.subscribe('assist.is.db.panel.ready', function () {
+          huePubSub.publish('assist.db.panel.ready');
+        });
 
         self.selectedSource.subscribe(function (newSource) {
           if (newSource) {

+ 12 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -451,6 +451,14 @@ var EditorViewModel = (function() {
     self.isSqlDialect.subscribe(updateDatabases);
     updateDatabases();
 
+    huePubSub.subscribeOnce('assist.source.set', function (source) {
+      if (source !== self.type()) {
+        huePubSub.publish('assist.set.source', self.type());
+      }
+    });
+
+    huePubSub.publish('assist.get.source');
+
     var handleAssistSelection = function (databaseDef) {
       if (databaseDef.source === self.type() && self.database() !== databaseDef.name) {
         self.database(databaseDef.name);
@@ -2313,9 +2321,9 @@ var EditorViewModel = (function() {
       });
 
       download(JSON.stringify(jupyterNotebook), self.name() + ".ipynb", "text/plain");
-    }
+    };
 
-    huePubSub.subscribe("assist.db.panel.ready", function () {
+    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(),
@@ -2324,6 +2332,8 @@ var EditorViewModel = (function() {
       }
     });
 
+    huePubSub.publish('assist.is.db.panel.ready');
+
     // Init
     if (notebook.snippets) {
       $.each(notebook.snippets, function (index, snippet) {