瀏覽代碼

[editor] Supply the executor from the QueryEditorWebComponents module to ensure the same context is used

Johan Ahlen 4 年之前
父節點
當前提交
eef361143c

+ 3 - 0
desktop/core/src/desktop/js/apps/editor/components/QueryEditorWebComponents.d.ts

@@ -14,12 +14,15 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import Executor, { ExecutorOptions } from '../execution/executor';
+
 export interface HueComponentConfig {
   baseUrl?: string;
 }
 
 declare const _default: {
   configure: (config: HueComponentConfig) => void;
+  createExecutor: (options: ExecutorOptions) => Executor;
 };
 
 export default _default;

+ 5 - 1
desktop/core/src/desktop/js/apps/editor/components/QueryEditorWebComponents.ts

@@ -20,6 +20,8 @@ import AceEditor from './aceEditor/AceEditor.vue';
 import ExecutableActions from './ExecutableActions.vue';
 import ExecutableProgressBar from './ExecutableProgressBar.vue';
 import ResultTable from './result/ResultTable.vue';
+import Executor, { ExecutorOptions } from '../execution/executor';
+import 'utils/json.bigDataParse';
 import { wrap } from 'vue/webComponentWrap';
 
 wrap('query-editor', AceEditor);
@@ -37,4 +39,6 @@ const configure = (config: HueComponentConfig): void => {
   }
 };
 
-export default { configure };
+const createExecutor = (options: ExecutorOptions): Executor => new Executor(options);
+
+export default { configure, createExecutor };

+ 12 - 10
desktop/core/src/desktop/js/apps/editor/execution/executor.ts

@@ -25,6 +25,17 @@ export interface ExecutorRaw {
   executables: ExecutableRaw[];
 }
 
+export interface ExecutorOptions {
+  connector: KnockoutObservable<Connector>;
+  compute: KnockoutObservable<Compute>;
+  namespace: KnockoutObservable<Namespace>;
+  database: KnockoutObservable<string>;
+  defaultLimit?: KnockoutObservable<number>;
+  isSqlEngine?: boolean;
+  snippet?: Snippet;
+  isOptimizerEnabled?: boolean;
+}
+
 export default class Executor {
   connector: KnockoutObservable<Connector>;
   compute: KnockoutObservable<Compute>;
@@ -38,16 +49,7 @@ export default class Executor {
   activeExecutable?: Executable;
   variables: VariableIndex = {};
 
-  constructor(options: {
-    connector: KnockoutObservable<Connector>;
-    compute: KnockoutObservable<Compute>;
-    namespace: KnockoutObservable<Namespace>;
-    database: KnockoutObservable<string>;
-    defaultLimit?: KnockoutObservable<number>;
-    isSqlEngine?: boolean;
-    snippet?: Snippet;
-    isOptimizerEnabled?: boolean;
-  }) {
+  constructor(options: ExecutorOptions) {
     this.connector = options.connector;
     this.compute = options.compute;
     this.namespace = options.namespace;

+ 2 - 2
tools/examples/components/sql-scratchpad/src/components/SqlScratchpad.tsx

@@ -39,14 +39,14 @@ export class SqlScratchpad extends React.Component<{}, SqlScratchpadState> {
       const connector = hueConfig.findEditorConnector(() => true); // Returns the first connector
 
       this.setState({
-        executor: new Executor({
+        executor: hueComponents.createExecutor({
           compute: (() => ({ id: 'default' })) as KnockoutObservable<any>,
           connector: (() => connector) as KnockoutObservable<any>,
           database: (() => 'default') as KnockoutObservable<any>,
           namespace: (() => ({ id: 'default' })) as KnockoutObservable<any>,
         })
       })
-    }).catch(err => {
+    }).catch(() => {
       console.warn('Failed loading the Hue config')
     })
   }