Pārlūkot izejas kodu

HUE-6815 [frontend] Enable open on enter and show in assist for the global search result entries

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

+ 22 - 7
desktop/core/src/desktop/templates/ko_components.mako

@@ -616,7 +616,7 @@ from desktop.views import _ko
     <div data-bind="with: data" style="width: 100%;">
       <div style="width:100%; text-align: center; margin-top: 40px; font-size: 140px; color: #787878;" data-bind="template: { name: 'document-icon-template', data: { document: { isDirectory: doc_type === 'directory', definition: function() { return { type: doc_type } } } } }"></div>
       <div style="width: 100%; margin-top: 20px; text-align:center">
-        <a style="font-size: 20px;" href="javscript:void(0)" data-bind="text: hue_name, hueLink: link, click: function () { $parents[1].searchResultVisible(false); }"></a>
+        <a style="font-size: 20px;" href="javscript:void(0)" data-bind="text: hue_name, hueLink: link, click: function () { $parents[1].close(); }"></a>
         <br/>
         <span data-bind="text: DocumentTypeGlobals[doc_type] || doc_type"></span>
         <!-- ko if: hue_description -->
@@ -656,7 +656,7 @@ from desktop.views import _ko
         <!-- ko with: selectedResult -->
           <!-- ko switch: type -->
             <!-- ko case: ['database', 'table', 'view', 'field']  -->
-              <!-- ko component: { name: 'sql-context-contents-global-search', params: { data: data } } --><!-- /ko -->
+              <!-- ko component: { name: 'sql-context-contents-global-search', params: { data: data, globalSearch: $parent } } --><!-- /ko -->
             <!-- /ko -->
             <!-- ko case: 'document'  -->
               <!-- ko template: 'search-document-context-template' --><!-- /ko -->
@@ -710,11 +710,13 @@ from desktop.views import _ko
           }
           if (newValue !== '') {
             self.triggerAutocomplete(newValue);
+            window.clearTimeout(self.fetchThrottle);
+            self.fetchThrottle = window.setTimeout(function () {
+              self.fetchResults(newValue);
+            }, 500);
+          } else {
+            self.searchResultCategories([]);
           }
-          window.clearTimeout(self.fetchThrottle);
-          self.fetchThrottle = window.setTimeout(function () {
-            self.fetchResults(newValue);
-          }, 500);
         });
 
         self.searchHasFocus.subscribe(function (newVal) {
@@ -790,6 +792,12 @@ from desktop.views import _ko
         });
       };
 
+      GlobalSearch.prototype.close = function () {
+        var self = this;
+        self.searchResultVisible(false);
+        self.searchInput('');
+      };
+
       GlobalSearch.prototype.updateInlineAutocomplete = function (partial) {
         var self = this;
         var newAutocomplete = '';
@@ -901,7 +909,14 @@ from desktop.views import _ko
       };
 
       GlobalSearch.prototype.openResult = function () {
-        console.log('open... ');
+        var self = this;
+        var selectedResult = self.selectedResult();
+        if (['database', 'table', 'field', 'view'].indexOf(selectedResult.type) !== -1) {
+          huePubSub.publish('context.popover.show.in.assist');
+        } else if (selectedResult.type === 'document') {
+          huePubSub.publish('open.link', '/hue' + selectedResult.data.link);
+        }
+        self.close();
       };
 
       GlobalSearch.prototype.resultSelected = function (categoryIndex, resultIndex) {

+ 20 - 2
desktop/core/src/desktop/templates/sql_context_popover.mako

@@ -1356,8 +1356,9 @@ from metadata.conf import has_navigator
         var self = this;
         self.contents = undefined;
 
+        self.disposals = [];
 
-        self.showInAssistEnabled = false; // TODO: enable show in assist and fix the pubsubs for metastore etc.
+        self.showInAssistEnabled = true;
 
         self.isDatabase = params.data.type.toLowerCase() === 'database';
         self.isTable = params.data.type.toLowerCase() === 'table';
@@ -1372,10 +1373,20 @@ from metadata.conf import has_navigator
 
         var adaptedData = { identifierChain: [] };
 
-        params.data.originalName.split('.').forEach(function (part) {
+        var path = params.data.originalName.split('.');
+        path.forEach(function (part) {
           adaptedData.identifierChain.push({ name: part });
         });
 
+        var metastorePubSub = huePubSub.subscribe('context.popover.open.in.metastore', function () {
+          huePubSub.publish('open.link', '/metastore/table' + (self.isTable ? '/' : 's/') + path.join('/'));
+          params.globalSearch.close();
+        });
+
+        self.disposals.push(function () {
+          metastorePubSub.remove();
+        });
+
 
         if (self.isDatabase) {
           self.contents = new DatabaseContextTabs(adaptedData, params.data.sourceType.toLowerCase(), 'default');
@@ -1389,6 +1400,13 @@ from metadata.conf import has_navigator
 
       };
 
+      SqlContextContentsGlobalSearch.prototype.dispose = function () {
+        var self = this;
+        self.disposals.forEach(function (dispose) {
+          dispose();
+        })
+      };
+
       ko.components.register('sql-context-contents-global-search', {
         viewModel: SqlContextContentsGlobalSearch,
         template: { element: 'sql-context-contents' }