Переглянути джерело

HUE-9255 [assist] Switch from connector type to dialect in the right assist functions panel

Johan Ahlen 5 роки тому
батько
коміт
672ac98b27

+ 3 - 2
desktop/core/src/desktop/js/apps/notebook/app.js

@@ -27,6 +27,7 @@ import hueUtils from 'utils/hueUtils';
 import I18n from 'utils/i18n';
 import sqlWorkerHandler from 'sql/sqlWorkerHandler';
 import { initNotebook2 } from 'apps/notebook2/app';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 if (window.ENABLE_NOTEBOOK_2) {
   initNotebook2();
@@ -925,8 +926,8 @@ if (window.ENABLE_NOTEBOOK_2) {
           if (app === 'editor') {
             huePubSub.publish('redraw.fixed.headers');
             huePubSub.publish('hue.scrollleft.show');
-            huePubSub.publish('active.snippet.type.changed', {
-              type: viewModel.editorType(),
+            huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+              dialect: viewModel.editorType(),
               isSqlDialect: viewModel.getSnippetViewSettings(viewModel.editorType()).sqlDialect
             });
           }

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

@@ -25,6 +25,10 @@ import hueUtils from 'utils/hueUtils';
 
 import Notebook from 'apps/notebook/notebook';
 import Snippet from 'apps/notebook/snippet';
+import {
+  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+  GET_ACTIVE_SNIPPET_DIALECT_EVENT
+} from 'apps/notebook2/events';
 
 class EditorViewModel {
   constructor(editor_id, notebooks, options, CoordinatorEditorViewModel, RunningCoordinatorModel) {
@@ -299,14 +303,10 @@ class EditorViewModel {
     });
 
     huePubSub.subscribe(
-      'get.active.snippet.type',
+      GET_ACTIVE_SNIPPET_DIALECT_EVENT,
       callback => {
         withActiveSnippet(activeSnippet => {
-          if (callback) {
-            callback(activeSnippet.type());
-          } else {
-            huePubSub.publish('set.active.snippet.type', activeSnippet.type());
-          }
+          callback(activeSnippet.type()); // Dialect = type in editor v1
         });
       },
       self.huePubSubId
@@ -566,8 +566,8 @@ class EditorViewModel {
               if (self.editorMode()) {
                 self.editorType(data.document.type.substring('query-'.length));
                 if (!self.isNotificationManager()) {
-                  huePubSub.publish('active.snippet.type.changed', {
-                    type: self.editorType(),
+                  huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+                    dialect: self.editorType(),
                     isSqlDialect: self.getSnippetViewSettings(self.editorType()).sqlDialect
                   });
                 }
@@ -594,8 +594,8 @@ class EditorViewModel {
 
     self.newNotebook = function(editorType, callback, queryTab) {
       if (!self.isNotificationManager()) {
-        huePubSub.publish('active.snippet.type.changed', {
-          type: editorType,
+        huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+          dialect: editorType,
           isSqlDialect: editorType ? self.getSnippetViewSettings(editorType).sqlDialect : undefined
         });
       }
@@ -624,8 +624,8 @@ class EditorViewModel {
               hueUtils.changeURLParameter('type', self.editorType());
             }
             if (!self.isNotificationManager()) {
-              huePubSub.publish('active.snippet.type.changed', {
-                type: editorType,
+              huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+                dialect: editorType,
                 isSqlDialect: editorType
                   ? self.getSnippetViewSettings(editorType).sqlDialect
                   : undefined

+ 3 - 2
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -30,6 +30,7 @@ import Session from 'apps/notebook/session';
 import sqlStatementsParser from 'parse/sqlStatementsParser';
 import { SHOW_EVENT as SHOW_GIST_MODAL_EVENT } from 'ko/components/ko.shareGistModal';
 import { cancelActiveRequest } from 'api/apiUtils';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 const NOTEBOOK_MAPPING = {
   ignore: [
@@ -235,8 +236,8 @@ class Snippet {
 
     self.inFocus.subscribe(newValue => {
       if (newValue) {
-        huePubSub.publish('active.snippet.type.changed', {
-          type: self.type(),
+        huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+          dialect: self.type(),
           isSqlDialect: self.isSqlDialect()
         });
       }

+ 1 - 2
desktop/core/src/desktop/js/apps/notebook2/app.js

@@ -32,8 +32,7 @@ import {
   REDRAW_FIXED_HEADERS_EVENT,
   SHOW_GRID_SEARCH_EVENT,
   SHOW_NORMAL_RESULT_EVENT,
-  REDRAW_CHART_EVENT,
-  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT
+  REDRAW_CHART_EVENT
 } from 'apps/notebook2/events';
 import { DIALECT } from 'apps/notebook2/snippet';
 

+ 7 - 8
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -24,7 +24,10 @@ import huePubSub from 'utils/huePubSub';
 import hueUtils from 'utils/hueUtils';
 
 import Notebook from 'apps/notebook2/notebook';
-import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
+import {
+  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+  GET_ACTIVE_SNIPPET_DIALECT_EVENT
+} from 'apps/notebook2/events';
 import { CONFIG_REFRESHED_EVENT, GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
 
 class EditorViewModel {
@@ -155,14 +158,10 @@ class EditorViewModel {
     });
 
     huePubSub.subscribe(
-      'get.active.snippet.type',
+      GET_ACTIVE_SNIPPET_DIALECT_EVENT,
       callback => {
         this.withActiveSnippet(activeSnippet => {
-          if (callback) {
-            callback(activeSnippet.dialect());
-          } else {
-            huePubSub.publish('set.active.snippet.type', activeSnippet.dialect());
-          }
+          callback(activeSnippet.dialect());
         });
       },
       this.huePubSubId
@@ -377,7 +376,7 @@ class EditorViewModel {
   notifyDialectChange(dialect, isSqlDialect) {
     if (dialect && this.lastNotifiedDialect !== dialect) {
       huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-        type: dialect,
+        dialect: dialect,
         isSqlDialect: isSqlDialect
       });
       this.lastNotifiedDialect = dialect;

+ 2 - 1
desktop/core/src/desktop/js/apps/notebook2/events.js

@@ -1,4 +1,5 @@
-export const ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT = 'active.snippet.type.changed';
+export const ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT = 'active.snippet.dialect.changed';
+export const GET_ACTIVE_SNIPPET_DIALECT_EVENT = 'get.active.snippet.dialect';
 export const REDRAW_CHART_EVENT = 'result.chart.redraw';
 export const HIDE_FIXED_HEADERS_EVENT = 'result.grid.hide.fixed.headers';
 export const REDRAW_FIXED_HEADERS_EVENT = 'result.grid.redraw.fixed.headers';

+ 3 - 2
desktop/core/src/desktop/js/ko/components/assist/ko.assistEditorContextPanel.js

@@ -24,6 +24,7 @@ import componentUtils from 'ko/components/componentUtils';
 import dataCatalog from 'catalog/dataCatalog';
 import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 const TEMPLATE =
   ASSIST_TABLE_TEMPLATES +
@@ -209,8 +210,8 @@ class AssistEditorContextPanel {
         (this.sourceType() === 'impala' || this.sourceType() === 'hive')
     );
 
-    const typeSub = huePubSub.subscribe('active.snippet.type.changed', details => {
-      this.sourceType(details.type);
+    const typeSub = huePubSub.subscribe(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, details => {
+      this.sourceType(details.dialect);
     });
 
     this.disposals.push(() => {

+ 44 - 35
desktop/core/src/desktop/js/ko/components/assist/ko.assistFunctionsPanel.js

@@ -22,6 +22,10 @@ import huePubSub from 'utils/huePubSub';
 import { PigFunctions, SqlFunctions } from 'sql/sqlFunctions';
 import I18n from 'utils/i18n';
 import { GET_KNOWN_CONFIG_EVENT, CONFIG_REFRESHED_EVENT } from 'utils/hueConfig';
+import {
+  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+  GET_ACTIVE_SNIPPET_DIALECT_EVENT
+} from 'apps/notebook2/events';
 
 // prettier-ignore
 const TEMPLATE = `
@@ -29,7 +33,7 @@ const TEMPLATE = `
     <div class="assist-flex-panel">
       <div class="assist-flex-header">
         <div class="assist-inner-header">
-          <div class="function-dialect-dropdown" data-bind="component: { name: 'hue-drop-down', params: { fixedPosition: true, value: activeType, entries: availableTypes, linkTitle: '${I18n(
+          <div class="function-dialect-dropdown" data-bind="component: { name: 'hue-drop-down', params: { fixedPosition: true, value: activeDialect, entries: availableDialects, linkTitle: '${I18n(
             'Selected dialect'
           )}' } }" style="display: inline-block"></div>
         </div>
@@ -87,16 +91,16 @@ class AssistFunctionsPanel {
     this.categories = {};
     this.disposals = [];
 
-    this.activeType = ko.observable();
-    this.availableTypes = ko.observableArray();
+    this.activeDialect = ko.observable();
+    this.availableDialects = ko.observableArray();
 
     this.query = ko.observable().extend({ rateLimit: 400 });
     this.selectedFunction = ko.observable();
 
-    const selectedFunctionPerType = {};
+    const selectedFunctionPeDialect = {};
     this.selectedFunction.subscribe(newFunction => {
       if (newFunction) {
-        selectedFunctionPerType[this.activeType()] = newFunction;
+        selectedFunctionPeDialect[this.activeDialect()] = newFunction;
         if (!newFunction.category.open()) {
           newFunction.category.open(true);
         }
@@ -148,19 +152,19 @@ class AssistFunctionsPanel {
       return result;
     });
 
-    this.activeType.subscribe(newType => {
-      if (newType) {
-        this.selectedFunction(selectedFunctionPerType[newType]);
-        this.activeCategories(this.categories[newType]);
-        apiHelper.setInTotalStorage('assist', 'function.panel.active.type', newType);
+    this.activeDialect.subscribe(newDialect => {
+      if (newDialect) {
+        this.selectedFunction(selectedFunctionPeDialect[newDialect]);
+        this.activeCategories(this.categories[newDialect]);
+        apiHelper.setInTotalStorage('assist', 'function.panel.active.dialect', newDialect);
       }
     });
 
-    const updateType = type => {
-      this.availableTypes().every(availableType => {
-        if (availableType.toLowerCase() === type) {
-          if (this.activeType() !== availableType) {
-            this.activeType(availableType);
+    const updateDialect = dialect => {
+      this.availableDialects().every(availableDialect => {
+        if (availableDialect.toLowerCase() === dialect) {
+          if (this.activeDialect() !== availableDialect) {
+            this.activeDialect(availableDialect);
           }
           return false;
         }
@@ -168,49 +172,54 @@ class AssistFunctionsPanel {
       });
     };
 
-    const activeSnippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', details => {
-      updateType(details.type);
-    });
+    const activeSnippetDialectSub = huePubSub.subscribe(
+      ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+      details => {
+        updateDialect(details.dialect);
+      }
+    );
 
     const configUpdated = config => {
-      const lastActiveType =
-        this.activeType() || apiHelper.getFromTotalStorage('assist', 'function.panel.active.type');
+      const lastActiveDialect =
+        this.activeDialect() ||
+        apiHelper.getFromTotalStorage('assist', 'function.panel.active.dialect');
       if (config.app_config && config.app_config.editor && config.app_config.editor.interpreters) {
-        const typesIndex = {};
+        const dialectIndex = {};
         config.app_config.editor.interpreters.forEach(interpreter => {
           if (
-            interpreter.type === 'hive' ||
-            interpreter.type === 'impala' ||
-            interpreter.type === 'pig'
+            interpreter.dialect === 'hive' ||
+            interpreter.dialect === 'impala' ||
+            interpreter.dialect === 'pig'
           ) {
-            typesIndex[interpreter.type] = true;
+            dialectIndex[interpreter.dialect] = true;
           }
         });
-        this.availableTypes(Object.keys(typesIndex).sort());
+        this.availableDialects(Object.keys(dialectIndex).sort());
 
-        this.availableTypes().forEach(type => {
-          this.initFunctions(type);
+        this.availableDialects().forEach(dialect => {
+          this.initFunctions(dialect);
         });
 
-        if (lastActiveType && typesIndex[lastActiveType]) {
-          this.activeType(lastActiveType);
+        if (lastActiveDialect && dialectIndex[lastActiveDialect]) {
+          this.activeDialect(lastActiveDialect);
         } else {
-          this.activeType(this.availableTypes().length ? this.availableTypes()[0] : undefined);
+          this.activeDialect(
+            this.availableDialects().length ? this.availableDialects()[0] : undefined
+          );
         }
       } else {
-        this.availableTypes([]);
+        this.availableDialects([]);
       }
+      huePubSub.publish(GET_ACTIVE_SNIPPET_DIALECT_EVENT, updateDialect);
     };
 
     huePubSub.publish(GET_KNOWN_CONFIG_EVENT, configUpdated);
     const configSub = huePubSub.subscribe(CONFIG_REFRESHED_EVENT, configUpdated);
 
     this.disposals.push(() => {
-      activeSnippetTypeSub.remove();
+      activeSnippetDialectSub.remove();
       configSub.remove();
     });
-
-    huePubSub.publish('get.active.snippet.type', updateType);
   }
 
   dispose() {

+ 11 - 11
desktop/core/src/desktop/js/ko/components/assist/ko.assistFunctionsPanel.test.js

@@ -26,10 +26,10 @@ describe('ko.assistFunctionsPanel.js', () => {
           app_config: {
             editor: {
               interpreters: [
-                { type: 'pig' },
-                { type: 'pig' },
-                { type: 'impala' },
-                { type: 'banana' }
+                { dialect: 'pig' },
+                { dialect: 'pig' },
+                { dialect: 'impala' },
+                { dialect: 'banana' }
               ]
             }
           }
@@ -39,31 +39,31 @@ describe('ko.assistFunctionsPanel.js', () => {
     const subject = new AssistFunctionsPanel();
 
     expect(spy).toHaveBeenCalled();
-    expect(subject.availableTypes()).toEqual(['impala', 'pig']);
+    expect(subject.availableDialects()).toEqual(['impala', 'pig']);
 
     spy.mockRestore();
 
     huePubSub.publish(CONFIG_REFRESHED_EVENT, {
       app_config: {
         editor: {
-          interpreters: [{ type: 'pig' }]
+          interpreters: [{ dialect: 'pig' }]
         }
       }
     });
 
-    expect(subject.availableTypes()).toEqual(['pig']);
-    expect(subject.activeType()).toEqual('pig');
+    expect(subject.availableDialects()).toEqual(['pig']);
+    expect(subject.activeDialect()).toEqual('pig');
 
     huePubSub.publish(CONFIG_REFRESHED_EVENT, {
       app_config: {
         editor: {
-          interpreters: [{ type: 'banana' }]
+          interpreters: [{ dialect: 'banana' }]
         }
       }
     });
 
-    expect(subject.availableTypes()).toEqual([]);
-    expect(subject.activeType()).toBeFalsy();
+    expect(subject.availableDialects()).toEqual([]);
+    expect(subject.activeDialect()).toBeFalsy();
 
     subject.dispose();
   });

+ 11 - 4
desktop/core/src/desktop/js/ko/components/assist/ko.assistLangRefPanel.js

@@ -22,6 +22,10 @@ import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
 import { GET_KNOWN_CONFIG_EVENT, CONFIG_REFRESHED_EVENT } from 'utils/hueConfig';
 import { simpleGet } from 'api/apiUtils';
+import {
+  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+  GET_ACTIVE_SNIPPET_DIALECT_EVENT
+} from 'apps/notebook2/events';
 
 // prettier-ignore
 const TEMPLATE = `
@@ -145,9 +149,12 @@ class AssistLangRefPanel {
       }
     };
 
-    const activeSnippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', details => {
-      updateType(details.type);
-    });
+    const activeSnippetTypeSub = huePubSub.subscribe(
+      ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
+      details => {
+        updateType(details.dialect);
+      }
+    );
 
     const configUpdated = config => {
       const lastActiveType = this.sourceType();
@@ -178,7 +185,7 @@ class AssistLangRefPanel {
       activeSnippetTypeSub.remove();
     });
 
-    huePubSub.publish('get.active.snippet.type', updateType);
+    huePubSub.publish(GET_ACTIVE_SNIPPET_DIALECT_EVENT, updateType);
 
     this.topics = ko.pureComputed(() => {
       return this.sourceType() ? this.allTopics[this.sourceType()] : [];

+ 3 - 2
desktop/core/src/desktop/js/ko/components/assist/ko.rightAssistPanel.js

@@ -20,6 +20,7 @@ import apiHelper from 'api/apiHelper';
 import componentUtils from 'ko/components/componentUtils';
 import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 const EDITOR_ASSISTANT_TAB = 'editorAssistant';
 const DASHBOARD_ASSISTANT_TAB = 'dashboardAssistant';
@@ -164,8 +165,8 @@ class RightAssistPanel {
       updateTabs();
     };
 
-    const snippetTypeSub = huePubSub.subscribe('active.snippet.type.changed', details => {
-      updateContentsForType(details.type, details.isSqlDialect);
+    const snippetTypeSub = huePubSub.subscribe(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, details => {
+      updateContentsForType(details.dialect, details.isSqlDialect);
     });
     this.disposals.push(snippetTypeSub.remove.bind(snippetTypeSub));
 

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

@@ -20,6 +20,7 @@ import * as ko from 'knockout';
 import apiHelper from 'api/apiHelper';
 import hueAnalytics from 'utils/hueAnalytics';
 import huePubSub from 'utils/huePubSub';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 class SidePanelViewModel {
   constructor() {
@@ -70,8 +71,8 @@ class SidePanelViewModel {
     huePubSub.subscribe('set.current.app.name', onAppChange);
     huePubSub.publish('get.current.app.name', onAppChange);
 
-    huePubSub.subscribe('active.snippet.type.changed', details => {
-      self.rightAssistAvailable(details.isSqlDialect || details.type === 'pig');
+    huePubSub.subscribe(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, details => {
+      self.rightAssistAvailable(details.isSqlDialect || details.dialect === 'pig');
     });
 
     self.activeAppViewModel = ko.observable();