Bläddra i källkod

HUE-8018 [assist] Refresh the right assistant when a catalog entry is refreshed

Johan Ahlen 7 år sedan
förälder
incheckning
cacd698

+ 37 - 42
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -140,7 +140,7 @@ var AssistDbSource = (function () {
               subscription.dispose();
               applyPopularity();
             });
-          } else if (db.entries().length == 0) {
+          } else if (db.entries().length === 0) {
             var subscription = db.entries.subscribe(function (newEntries) {
               if (newEntries.length > 0) {
                 subscription.dispose();
@@ -154,14 +154,16 @@ var AssistDbSource = (function () {
       }
     });
 
-    huePubSub.subscribe('assist.database.get', function (callback) {
-      callback(self.selectedDatabase());
-    });
+    if (!self.navigationSettings.rightAssist) {
+      huePubSub.subscribe('assist.database.get', function (callback) {
+        callback(self.selectedDatabase());
+      });
+    }
 
     self.reloading = ko.observable(false);
 
     self.loadingTables = ko.pureComputed(function() {
-      return typeof self.selectedDatabase() != "undefined" && self.selectedDatabase() !== null && self.selectedDatabase().loading();
+      return typeof self.selectedDatabase() !== 'undefined' && self.selectedDatabase() !== null && self.selectedDatabase().loading();
     });
 
     self.loadingSamples = ko.observable(true);
@@ -172,11 +174,13 @@ var AssistDbSource = (function () {
         if (!self.selectedDatabase().hasEntries() && !self.selectedDatabase().loading()) {
           self.selectedDatabase().loadEntries()
         }
-        self.apiHelper.setInTotalStorage('assist_' + self.sourceType, 'lastSelectedDb', self.selectedDatabase().catalogEntry.name)
-        huePubSub.publish("assist.database.set", {
-          source: self.sourceType,
-          name: self.selectedDatabase().catalogEntry.name
-        })
+        if (!self.navigationSettings.rightAssist) {
+          self.apiHelper.setInTotalStorage('assist_' + self.sourceType, 'lastSelectedDb', self.selectedDatabase().catalogEntry.name);
+          huePubSub.publish("assist.database.set", {
+            source: self.sourceType,
+            name: self.selectedDatabase().catalogEntry.name
+          })
+        }
       }
     };
 
@@ -187,24 +191,9 @@ var AssistDbSource = (function () {
     var nestedFilter = {
       querySpec: ko.observable({}),
       showTables: ko.observable(true),
-      showViews: ko.observable(true),
-      activeEditorTables: ko.observableArray([])
+      showViews: ko.observable(true)
     };
 
-    huePubSub.subscribe('editor.active.locations', function (activeLocations) {
-      var activeTables = [];
-      // TODO: Test multiple snippets
-      if (self.sourceType !== activeLocations.type) {
-        return;
-      }
-      activeLocations.locations.forEach(function (location) {
-        if (location.type === 'table') {
-          activeTables.push(location.identifierChain.length == 2 ? { table: location.identifierChain[1].name, db: location.identifierChain[0].name} : { table: location.identifierChain[0].name });
-        }
-      });
-      nestedFilter.activeEditorTables(activeTables);
-    });
-
     self.setDatabase = function (databaseName) {
       if (databaseName && self.selectedDatabase() && databaseName === self.selectedDatabase().catalogEntry.name) {
         return;
@@ -281,27 +270,33 @@ var AssistDbSource = (function () {
       $container.find(".assist-actions, .assist-db-header-actions").css('right', -$container.scrollLeft() + 'px');
     };
 
-    huePubSub.subscribe('data.catalog.entry.refreshed', function (details) {
-      if (self.catalogEntry === details.entry) {
-        self.initDatabases();
-      } else if (details.entry.getSourceType() === self.sourceType) {
-        var findAndReloadInside = function (entries) {
-          return entries.some(function (entry) {
-            if (entry.catalogEntry === details.entry) {
-              entry.loadEntries();
-              return true;
-            }
-            return findAndReloadInside(entry.entries());
-          })
-        };
-        findAndReloadInside(self.databases());
-      }
-    })
+    if (!self.navigationSettings.rightAssist) {
+      huePubSub.subscribe('data.catalog.entry.refreshed', function (details) {
+        if (self.catalogEntry === details.entry) {
+          self.initDatabases();
+        } else if (details.entry.getSourceType() === self.sourceType) {
+          var findAndReloadInside = function (entries) {
+            return entries.some(function (entry) {
+              if (entry.catalogEntry === details.entry) {
+                entry.loadEntries();
+                return true;
+              }
+              return findAndReloadInside(entry.entries());
+            })
+          };
+          findAndReloadInside(self.databases());
+        }
+      });
+    }
   }
 
   AssistDbSource.prototype.highlightInside = function (path) {
     var self = this;
 
+    if (self.navigationSettings.rightAssist) {
+      return;
+    }
+
     var foundDb;
     var index;
 

+ 51 - 11
desktop/core/src/desktop/templates/assist.mako

@@ -2477,10 +2477,6 @@ from desktop.views import _ko
           }).join('.').toLowerCase();
         };
 
-        var databaseIndex = {};
-
-        var activeTableIndex = {};
-
         self.filter = {
           querySpec: ko.observable({
             query: '',
@@ -2499,12 +2495,7 @@ from desktop.views import _ko
         };
         var i18n = {};
 
-        var assistDbSource = new AssistDbSource({
-          i18n : i18n,
-          type: 'hive',
-          name: 'hive',
-          navigationSettings: navigationSettings
-        });
+        var sources = {};
 
         var loadEntriesTimeout = -1;
         // This fetches the columns for each table synchronously with 2 second in between.
@@ -2569,7 +2560,24 @@ from desktop.views import _ko
             }
           }
           updateOnVisible = false;
-          assistDbSource.sourceType = activeLocations.type;
+
+          if (!sources[activeLocations.type]) {
+            sources[activeLocations.type] = {
+              assistDbSource: new AssistDbSource({
+                i18n: i18n,
+                type: activeLocations.type,
+                name: activeLocations.type,
+                navigationSettings: navigationSettings
+              }),
+              databaseIndex: {},
+              activeTableIndex: {}
+            }
+          }
+
+          var assistDbSource = sources[activeLocations.type].assistDbSource;
+          var databaseIndex = sources[activeLocations.type].databaseIndex;
+          var activeTableIndex = sources[activeLocations.type].activeTableIndex;
+
           if (!activeLocations) {
             self.activeLocations(undefined);
             return;
@@ -2694,6 +2702,38 @@ from desktop.views import _ko
           }
         };
 
+
+        huePubSub.subscribe('data.catalog.entry.refreshed', function (details) {
+          var sourceType = details.entry.getSourceType();
+          if (sources[sourceType]) {
+            var completeRefresh = false;
+            if (details.entry.isSource()) {
+              sources[sourceType].databaseIndex = {};
+              sources[sourceType].activeTableIndex = {};
+              completeRefresh = true;
+            } else if (details.entry.isDatabase() && sources[sourceType].databaseIndex[details.entry.name]) {
+              var dbEntry = sources[sourceType].databaseIndex[details.entry.name];
+              var activeTableIndex = sources[sourceType].activeTableIndex;
+              Object.keys(activeTableIndex).forEach(function (tableKey) {
+                var tableEntry = activeTableIndex[tableKey];
+                if (tableEntry.parent === dbEntry) {
+                  delete activeTableIndex[tableKey];
+                  completeRefresh = true;
+                }
+              });
+            } else if (details.entry.isTableOrView()) {
+              var activeTableIndex = sources[sourceType].activeTableIndex;
+              if (activeTableIndex[details.entry.getQualifiedPath()]) {
+                delete activeTableIndex[details.entry.getQualifiedPath()];
+                completeRefresh = true;
+              }
+            }
+            if (completeRefresh) {
+              handleLocationUpdate(self.activeLocations());
+            }
+          }
+        });
+
         if (self.activeTab() === 'editorAssistant') {
           huePubSub.publish('get.active.editor.locations', handleLocationUpdate);
         } else {