Browse Source

HUE-6134 [assist] Use the MetastoreTable for tables in the assistant

Johan Ahlen 8 years ago
parent
commit
2e0a82e38d

+ 2 - 2
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -594,7 +594,7 @@ var MetastoreTable = (function () {
     self.fetchDetails();
   };
 
-  MetastoreTable.prototype.showContextPopover = function (entry, event) {
+  MetastoreTable.prototype.showContextPopover = function (entry, event, orientation) {
     var $source = $(event.target);
     var offset = $source.offset();
     huePubSub.publish('sql.context.popover.show', {
@@ -602,7 +602,7 @@ var MetastoreTable = (function () {
         type: 'table',
         identifierChain: [{ name: entry.name }]
       },
-      orientation: 'right',
+      orientation: orientation || 'right',
       sourceType: 'hive',
       defaultDatabase: entry.database.name,
       source: {

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3383,7 +3383,7 @@
             });
           }
 
-          var lastKnownLocations = { id: $el.attr("id"), type: snippet.type(), locations: e.data.locations };
+          var lastKnownLocations = { id: $el.attr("id"), type: snippet.type(), defaultDatabase: snippet.database(), locations: e.data.locations };
           huePubSub.publish('editor.active.locations', lastKnownLocations);
 
           huePubSub.subscribe('get.active.editor.locations', function () {

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

@@ -1661,7 +1661,7 @@ from notebook.conf import get_ordered_interpreters
     <!-- /ko -->
     <br/>
     <ul data-bind="foreach: activeTables">
-      <li>
+      <li data-bind="click: function (data, event) { showContextPopover(data, event, 'left') }">
         <span data-bind="text: name"></span> <i class="fa fa-info"></i> <i class="fa fa-fw fa-clock-o muted" title="02/01/2017 10:15 PM"></i>
       </li>
     </ul>
@@ -1752,14 +1752,21 @@ from notebook.conf import get_ordered_interpreters
                 if (isPointInside(location.location, cursorPos.row+1, cursorPos.column+1)) {
                   statementFound = true;
                 }
-              } else if (statementFound && location.type === 'table') {
+              } else if (statementFound && location.type === 'table' && location.identifierChain.length <= 2) {
+                // tableIndex is used to make sure we only add each table once
                 tableIndex[createQualifiedIdentifier(location.identifierChain)] = { name: location.identifierChain[location.identifierChain.length - 1].name, identifierChain: location.identifierChain }
               } else if (statementFound && locations[i].type === 'column') {
                 columnIndex[createQualifiedIdentifier(location.identifierChain)] = { name: location.identifierChain[location.identifierChain.length - 1].name, identifierChain: location.identifierChain }
               }
             }
             self.activeTables($.map(tableIndex, function (value) {
-              return value;
+              return new MetastoreTable({
+                database: {
+                  name: value.identifierChain.length === 2 ? value.identifierChain[0].name : self.locationIndex()[self.activeCursorLocation().id].defaultDatabase
+                },
+                type: 'table',
+                name: value.name
+              });
             }));
             self.activeColumns($.map(columnIndex, function (value) {
               return value;
@@ -1769,6 +1776,7 @@ from notebook.conf import get_ordered_interpreters
 
         huePubSub.subscribeOnce('set.active.snippet.type', self.activeSourceType);
         huePubSub.publish('get.active.snippet.type');
+
         self.disposals.push(huePubSub.subscribe('active.snippet.type.changed', self.activeSourceType).remove);
 
         self.disposals.push(huePubSub.subscribe('editor.active.cursor.location', function (location) {