浏览代码

HUE-8819 [assist] Show the right assistant for all SQL type editors

Johan Ahlen 6 年之前
父节点
当前提交
84a7f3fa63

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook/app.js

@@ -911,7 +911,7 @@ huePubSub.subscribe('app.dom.loaded', app => {
         if (app === 'editor') {
           huePubSub.publish('redraw.fixed.headers');
           huePubSub.publish('hue.scrollleft.show');
-          huePubSub.publish('active.snippet.type.changed', viewModel.editorType());
+          huePubSub.publish('active.snippet.type.changed', { type: viewModel.editorType(), isSqlDialect: viewModel.getSnippetViewSettings(viewModel.editorType()).sqlDialect });
         }
       },
       HUE_PUB_SUB_EDITOR_ID

+ 3 - 3
desktop/core/src/desktop/js/apps/notebook/editorViewModel.js

@@ -560,7 +560,7 @@ class EditorViewModel {
             if (typeof skipUrlChange === 'undefined' && !self.isNotificationManager()) {
               if (self.editorMode()) {
                 self.editorType(data.document.type.substring('query-'.length));
-                huePubSub.publish('active.snippet.type.changed', self.editorType());
+                huePubSub.publish('active.snippet.type.changed', { type: self.editorType(), isSqlDialect: self.getSnippetViewSettings(self.editorType()).sqlDialect });
                 self.changeURL(
                   self.URLS.editor + '?editor=' + data.document.id + '&type=' + self.editorType()
                 );
@@ -583,7 +583,7 @@ class EditorViewModel {
     };
 
     self.newNotebook = function(editorType, callback, queryTab) {
-      huePubSub.publish('active.snippet.type.changed', editorType);
+      huePubSub.publish('active.snippet.type.changed', { type: editorType, isSqlDialect: editorType ? self.getSnippetViewSettings(editorType).sqlDialect : undefined  });
       $.post(
         '/notebook/api/create_notebook',
         {
@@ -604,7 +604,7 @@ class EditorViewModel {
             if (window.location.getParameter('type') === '') {
               hueUtils.changeURLParameter('type', self.editorType());
             }
-            huePubSub.publish('active.snippet.type.changed', editorType);
+            huePubSub.publish('active.snippet.type.changed', { type: editorType, isSqlDialect: editorType ? self.getSnippetViewSettings(editorType).sqlDialect : undefined  });
           }
 
           if (typeof callback !== 'undefined' && callback !== null) {

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -222,7 +222,7 @@ class Snippet {
 
     self.inFocus.subscribe(newValue => {
       if (newValue) {
-        huePubSub.publish('active.snippet.type.changed', self.type());
+        huePubSub.publish('active.snippet.type.changed', { type: self.type(), isSqlDialect: self.isSqlDialect() });
       }
     });
 

+ 3 - 3
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -436,7 +436,7 @@ class EditorViewModel {
 
   newNotebook(editorType, callback, queryTab) {
     const self = this;
-    huePubSub.publish('active.snippet.type.changed', editorType);
+    huePubSub.publish('active.snippet.type.changed', { type: editorType, isSqlDialect: editorType ? self.getSnippetViewSettings(editorType).sqlDialect : undefined });
     $.post(
       '/notebook/api/create_notebook',
       {
@@ -457,7 +457,7 @@ class EditorViewModel {
           if (window.location.getParameter('type') === '') {
             hueUtils.changeURLParameter('type', self.editorType());
           }
-          huePubSub.publish('active.snippet.type.changed', editorType);
+          huePubSub.publish('active.snippet.type.changed', { type: editorType, isSqlDialect: editorType ? self.getSnippetViewSettings(editorType).sqlDialect : undefined });
         }
 
         if (typeof callback !== 'undefined' && callback !== null) {
@@ -486,7 +486,7 @@ class EditorViewModel {
           if (typeof skipUrlChange === 'undefined' && !self.isNotificationManager()) {
             if (self.editorMode()) {
               self.editorType(data.document.type.substring('query-'.length));
-              huePubSub.publish('active.snippet.type.changed', self.editorType());
+              huePubSub.publish('active.snippet.type.changed', { type: self.editorType(), isSqlDialect: self.getSnippetViewSettings(self.editorType()).sqlDialect });
               self.changeURL(
                 self.URLS.editor + '?editor=' + data.document.id + '&type=' + self.editorType()
               );

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -212,7 +212,7 @@ class Snippet {
 
     self.inFocus.subscribe(newValue => {
       if (newValue) {
-        huePubSub.publish('active.snippet.type.changed', self.type());
+        huePubSub.publish('active.snippet.type.changed', { type: self.type(), isSqlDialect: self.isSqlDialect() });
       }
     });
 

+ 2 - 2
desktop/core/src/desktop/js/sidePanelViewModel.js

@@ -69,9 +69,9 @@ class SidePanelViewModel {
       }
     });
 
-    huePubSub.subscribe('active.snippet.type.changed', snippetType => {
+    huePubSub.subscribe('active.snippet.type.changed', details => {
       self.rightAssistAvailable(
-        snippetType === 'impala' || snippetType === 'hive' || snippetType === 'pig'
+        details.isSqlDialect || details.type === 'pig'
       );
     });
 

+ 1 - 1
desktop/core/src/desktop/js/sql/aceLocationHandler.js

@@ -1320,7 +1320,7 @@ class AceLocationHandler {
         if (statementDetails.id !== self.editorId) {
           return;
         }
-        if (self.snippet.type() === 'hive' || self.snippet.type() === 'impala') {
+        if (self.snippet.isSqlDialect()) {
           if (lastContextRequest) {
             lastContextRequest.dispose();
           }

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

@@ -2648,7 +2648,7 @@ from desktop.views import _ko
           });
         };
 
-        var activeSnippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', updateType);
+        var activeSnippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', function (details) { updateType(details.type) });
 
         self.disposals.push(function () {
           activeSnippetTypeSub.remove();
@@ -2765,7 +2765,7 @@ from desktop.views import _ko
           <!-- ko hueSpinner: { spin: filter.querySpec() && filter.querySpec().query !== '' && someLoading(), inline: true,  center: true} --><!-- /ko -->
         </div>
 
-        <!-- ko if: HAS_OPTIMIZER && !isSolr() -->
+        <!-- ko if: showRisks -->
         <div class="assist-flex-header assist-divider"><div class="assist-inner-header">${ _('Query Analysis') }</div></div>
         <div class="assist-flex-third">
           <!-- ko if: ! activeRisks().hints -->
@@ -2856,6 +2856,20 @@ from desktop.views import _ko
         self.isSolr = ko.observable(false);
         self.activeTab = params.activeTab;
 
+        self.sourceType = ko.observable(params.sourceType());
+
+        self.showRisks = ko.pureComputed(function () {
+          return window.HAS_OPTIMIZER && !self.isSolr() && (self.sourceType() === 'impala' || self.sourceType() === 'hive')
+        });
+
+        var typeSub = huePubSub.subscribe('active.snippet.type.changed', function (details) {
+          self.sourceType(details.type);
+        });
+
+        self.disposals.push(function () {
+          typeSub.remove();
+        });
+
         self.uploadingTableStats = ko.observable(false);
         self.activeStatement = ko.observable();
         self.activeTables = ko.observableArray();
@@ -3432,6 +3446,8 @@ from desktop.views import _ko
           }).extend({ rateLimit: 300 })
         };
 
+        self.sourceType = ko.observable('solr');
+
         self.activeTables = ko.observableArray();
 
         self.filteredTables = AssistantUtils.getFilteredTablesPureComputed(self);
@@ -3455,6 +3471,8 @@ from desktop.views import _ko
             return;
           }
 
+          self.sourceType = ko.observable(collection.engine());
+
           var assistDbSource = new AssistDbSource({
             i18n : i18n,
             initialNamespace: collection.activeNamespace,
@@ -3550,7 +3568,7 @@ from desktop.views import _ko
     <!-- ko if: visible -->
     <div class="right-assist-contents">
       <!-- ko if: editorAssistantTabAvailable-->
-      <div data-bind="component: { name: 'editor-assistant-panel', params: { activeTab: activeTab } }, visible: activeTab() === 'editorAssistant'"></div>
+      <div data-bind="component: { name: 'editor-assistant-panel', params: { activeTab: activeTab, sourceType: sourceType } }, visible: activeTab() === 'editorAssistant'"></div>
       <!-- /ko -->
 
       <!-- ko if: functionsTabAvailable -->
@@ -3587,6 +3605,7 @@ from desktop.views import _ko
 
         self.activeTab = ko.observable();
         self.visible = params.visible;
+        self.sourceType = ko.observable();
 
         self.editorAssistantTabAvailable = ko.observable(false);
         self.dashboardAssistantTabAvailable = ko.observable(false);
@@ -3636,10 +3655,11 @@ from desktop.views import _ko
           }
         };
 
-        var updateContentsForType = function (type) {
+        var updateContentsForType = function (type, isSqlDialect) {
+          self.sourceType(type);
           self.functionsTabAvailable(type === 'hive' || type === 'impala' || type === 'pig');
           self.langRefTabAvailable(type === 'impala');
-          self.editorAssistantTabAvailable((!window.IS_EMBEDDED || window.EMBEDDED_ASSISTANT_ENABLED) && (type === 'hive' || type === 'impala'));
+          self.editorAssistantTabAvailable((!window.IS_EMBEDDED || window.EMBEDDED_ASSISTANT_ENABLED) && isSqlDialect);
           self.dashboardAssistantTabAvailable(type === 'dashboard');
           self.schedulesTabAvailable(false);
           if (type !== 'dashboard') {
@@ -3657,12 +3677,12 @@ from desktop.views import _ko
           updateTabs();
         };
 
-        var snippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', updateContentsForType);
+        var snippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', function (details) { updateContentsForType(details.type, details.isSqlDialect) });
         self.disposals.push(snippetTypeSub.remove.bind(snippetTypeSub));
 
         huePubSub.subscribe('set.current.app.name', function (appName) {
           if (appName === 'dashboard') {
-            updateContentsForType(appName);
+            updateContentsForType(appName, false);
           }
         });
         huePubSub.publish('get.current.app.name');