فهرست منبع

HUE-9187 [editor] Only notify dialect change on actual change

Johan Ahlen 5 سال پیش
والد
کامیت
27a6df6ece

+ 4 - 4
desktop/core/src/desktop/js/apps/notebook2/app.js

@@ -504,10 +504,10 @@ export const initNotebook2 = () => {
           if (app === 'editor') {
             huePubSub.publish(REDRAW_FIXED_HEADERS_EVENT);
             huePubSub.publish('hue.scrollleft.show');
-            huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-              type: viewModel.editorType(),
-              isSqlDialect: viewModel.getSnippetViewSettings(viewModel.editorType()).sqlDialect
-            });
+            viewModel.notifyDialectChange(
+              viewModel.editorType(),
+              viewModel.getSnippetViewSettings(viewModel.editorType()).sqlDialect
+            );
           }
         },
         HUE_PUB_SUB_EDITOR_ID

+ 24 - 14
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -69,6 +69,7 @@ class EditorViewModel {
 
     this.autocompleteTimeout = options.autocompleteTimeout;
     this.selectedNotebook = ko.observable();
+    this.lastNotifiedDialect = undefined;
 
     this.combinedContent = ko.observable();
     this.isPresentationModeEnabled = ko.pureComputed(
@@ -350,10 +351,9 @@ class EditorViewModel {
 
   async newNotebook(editorType, callback, queryTab) {
     return new Promise((resolve, reject) => {
-      huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-        type: editorType,
-        isSqlDialect: editorType ? this.getSnippetViewSettings(editorType).sqlDialect : undefined
-      });
+      if (editorType) {
+        this.notifyDialectChange(editorType, this.getSnippetViewSettings(editorType).sqlDialect);
+      }
       $.post('/notebook/api/create_notebook', {
         type: editorType || this.editorType(),
         directory_uuid: window.location.getParameter('directory_uuid'),
@@ -376,12 +376,12 @@ class EditorViewModel {
             if (window.location.getParameter('type') === '') {
               hueUtils.changeURLParameter('type', this.editorType());
             }
-            huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-              type: editorType,
-              isSqlDialect: editorType
-                ? this.getSnippetViewSettings(editorType).sqlDialect
-                : undefined
-            });
+            if (editorType) {
+              this.notifyDialectChange(
+                editorType,
+                this.getSnippetViewSettings(editorType).sqlDialect
+              );
+            }
           }
 
           if (callback) {
@@ -411,10 +411,10 @@ class EditorViewModel {
       if (typeof skipUrlChange === 'undefined' && !this.isNotificationManager()) {
         if (this.editorMode()) {
           this.editorType(docData.document.type.substring('query-'.length));
-          huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-            type: this.editorType(),
-            isSqlDialect: this.getSnippetViewSettings(this.editorType()).sqlDialect
-          });
+          this.notifyDialectChange(
+            this.editorType(),
+            this.getSnippetViewSettings(this.editorType()).sqlDialect
+          );
           this.changeURL(
             this.URLS.editor + '?editor=' + docData.document.id + '&type=' + this.editorType()
           );
@@ -431,6 +431,16 @@ class EditorViewModel {
     }
   }
 
+  notifyDialectChange(dialect, isSqlDialect) {
+    if (dialect && this.lastNotifiedDialect !== dialect) {
+      huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
+        type: dialect,
+        isSqlDialect: isSqlDialect
+      });
+      this.lastNotifiedDialect = dialect;
+    }
+  }
+
   prepareShareModal() {
     const selectedNotebookUuid = this.selectedNotebook() && this.selectedNotebook().uuid();
     if (selectedNotebookUuid) {

+ 2 - 5
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -267,11 +267,8 @@ export default class Snippet {
     this.inFocus = ko.observable(false);
 
     this.inFocus.subscribe(newValue => {
-      if (newValue) {
-        huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
-          type: this.dialect(),
-          isSqlDialect: this.isSqlDialect()
-        });
+      if (newValue && this.dialect()) {
+        this.parentVm.notifyDialectChange(this.dialect(), this.isSqlDialect());
       }
     });