Browse Source

HUE-8330 [assist] Include namespace for show in assist

Johan Ahlen 7 years ago
parent
commit
03af8a8adf

+ 39 - 13
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -120,7 +120,7 @@ var AssistDbSource = (function () {
     var self = this;
     self.loading(true);
 
-    ContextCatalog.getNamespaces({ sourceType: self.sourceType }).done(function (context) {
+    return ContextCatalog.getNamespaces({ sourceType: self.sourceType }).done(function (context) {
       var assistNamespaces = [];
       var activeNamespace;
       var activeCompute;
@@ -160,11 +160,42 @@ var AssistDbSource = (function () {
       self.loadedDeferred.resolve();
       self.loading(false);
     })
-
   };
 
-  AssistDbSource.prototype.highlightInside = function (path) {
-    // TODO: Highlight from namespace
+  AssistDbSource.prototype.highlightInside = function (catalogEntry) {
+    var self = this;
+    if (self.navigationSettings.rightAssist) {
+      return;
+    }
+
+    var whenLoaded = function () {
+      self.namespaces().some(function (namespace) {
+        if (namespace.namespace.id === catalogEntry.namespace.id) {
+          if (self.selectedNamespace() !== namespace) {
+            self.selectedNamespace(namespace);
+          }
+          if (self.selectedNamespace().hasEntries()) {
+            self.selectedNamespace().highlightInside(catalogEntry);
+          } else {
+            self.selectedNamespace().initDatabases(function () {
+              self.selectedNamespace().highlightInside(catalogEntry);
+            })
+          }
+          return true;
+        }
+      })
+    };
+
+    if (self.namespaces().length) {
+      whenLoaded();
+    } else if (self.loading()) {
+      var loadingSub = self.loading.subscribe(function () {
+        loadingSub.dispose();
+        whenLoaded();
+      })
+    } else {
+      self.loadNamespaces().done(whenLoaded);
+    }
   };
 
   AssistDbSource.prototype.triggerRefresh = function (data, event) {
@@ -396,20 +427,15 @@ var AssistDbNamespace = (function () {
     self.loadedDeferred.done(callback);
   };
 
-  AssistDbNamespace.prototype.highlightInside = function (path) {
+  AssistDbNamespace.prototype.highlightInside = function (catalogEntry) {
     var self = this;
-
-    if (self.navigationSettings.rightAssist) {
-      return;
-    }
-
     var foundDb;
     var index;
 
     var findDatabase = function () {
       $.each(self.databases(), function (idx, db) {
         db.highlight(false);
-        if (db.databaseName === path[0]) {
+        if (db.databaseName === catalogEntry.path[0]) {
           foundDb = db;
           index = idx;
         }
@@ -431,8 +457,8 @@ var AssistDbNamespace = (function () {
                 foundDb.highlight(false);
               }, 1800);
             });
-            if (path.length > 1) {
-              foundDb.highlightInside(path.slice(1), []);
+            if (catalogEntry.path.length > 1) {
+              foundDb.highlightInside(catalogEntry.path.slice(1));
             } else {
               huePubSub.publish('assist.db.scrollTo', foundDb);
             }

+ 7 - 15
desktop/core/src/desktop/templates/assist.mako

@@ -1229,35 +1229,27 @@ from desktop.views import _ko
           });
         });
 
-        huePubSub.subscribe('assist.db.highlight', function (location) {
+        huePubSub.subscribe('assist.db.highlight', function (catalogEntry) {
           huePubSub.publish('left.assist.show');
-          if (location.sourceType === 'solr') {
+          if (catalogEntry.getSourceType() === 'solr') {
             huePubSub.publish('assist.show.solr');
-          }
-          else {
+          } else {
             huePubSub.publish('assist.show.sql');
           }
           huePubSub.publish('context.popover.hide');
           window.setTimeout(function () {
             var foundSource;
             $.each(self.sources(), function (idx, source) {
-              if (source.sourceType === location.sourceType) {
+              if (source.sourceType === catalogEntry.getSourceType()) {
                 foundSource = source;
                 return false;
               }
             });
             if (foundSource) {
-              var whenLoaded = function () {
-                if (self.selectedSource() !== foundSource) {
-                  self.selectedSource(foundSource);
-                }
-                foundSource.highlightInside(location.path);
-              };
-              if (foundSource.hasEntries()) {
-                whenLoaded();
-              } else {
-                foundSource.initDatabases(whenLoaded);
+              if (self.selectedSource() !== foundSource) {
+                self.selectedSource(foundSource);
               }
+              foundSource.highlightInside(catalogEntry);
             }
           }, 0);
         });

+ 2 - 8
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -617,10 +617,7 @@ from metadata.conf import has_navigator
 
       DataCatalogContext.prototype.showInAssist = function () {
         var self = this;
-        huePubSub.publish('assist.db.highlight', {
-          sourceType: self.catalogEntry().getSourceType(),
-          path: self.catalogEntry().path
-        });
+        huePubSub.publish('assist.db.highlight', self.catalogEntry());
         huePubSub.publish('global.search.close');
       };
 
@@ -946,10 +943,7 @@ from metadata.conf import has_navigator
         self.activeTab = ko.observable('terms');
 
         var showInAssistPubSub = huePubSub.subscribe('context.popover.show.in.assist', function () {
-          huePubSub.publish('assist.db.highlight', {
-            sourceType: 'solr',
-            path: self.catalogEntry.path
-          });
+          huePubSub.publish('assist.db.highlight', self.catalogEntry);
         });
         self.disposals.push(function () {
           showInAssistPubSub.remove();