Browse Source

HUE-9456 [editor] Use the default editor if not specified in the URL in editor v2

Johan Ahlen 5 năm trước cách đây
mục cha
commit
c601ba99a1

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

@@ -31,7 +31,8 @@ import {
 import {
   CONFIG_REFRESHED_EVENT,
   GET_KNOWN_CONFIG_EVENT,
-  findEditorConnector
+  findEditorConnector,
+  getLastKnownConfig
 } from 'utils/hueConfig';
 
 class EditorViewModel {
@@ -277,20 +278,20 @@ class EditorViewModel {
     return this.snippetViewSettings.default;
   }
 
-  init() {
+  async init() {
     if (this.editorId) {
-      this.openNotebook(this.editorId);
+      await this.openNotebook(this.editorId);
     } else if (
       window.location.getParameter('gist') !== '' ||
       window.location.getParameter('type') !== ''
     ) {
-      this.newNotebook(window.location.getParameter('type'));
+      await this.newNotebook(window.location.getParameter('type'));
     } else if (window.location.getParameter('editor') !== '') {
-      this.openNotebook(window.location.getParameter('editor'));
+      await this.openNotebook(window.location.getParameter('editor'));
     } else if (this.notebooks.length > 0) {
       this.loadNotebook(this.notebooks[0]); // Old way of loading json for /browse
     } else {
-      this.newNotebook();
+      await this.newNotebook();
     }
   }
 
@@ -320,7 +321,18 @@ class EditorViewModel {
   }
 
   async newNotebook(connectorId, callback, queryTab) {
-    const connector = findEditorConnector(connector => connector.id === connectorId);
+    if (!connectorId) {
+      connectorId = getLastKnownConfig().default_sql_interpreter;
+    }
+    let connector;
+    if (connectorId) {
+      connector = findEditorConnector(connector => connector.id === connectorId);
+    } else {
+      const connectors = getLastKnownConfig().app_config.editor.interpreters;
+      if (connectors.length) {
+        connector = connectors[0];
+      }
+    }
     if (!connector) {
       console.warn('No connector found for ID ' + connectorId);
     } else {