Explorar o código

[editor] Automatically open relevant tabs after execution in editor v2

Johan Åhlén %!s(int64=4) %!d(string=hai) anos
pai
achega
912071709d

+ 7 - 2
desktop/core/src/desktop/js/apps/editor/components/ExecutableActions.vue

@@ -18,7 +18,12 @@
 
 <template>
   <div class="snippet-execute-actions">
-    <ExecuteButton :executable="executable" :before-execute="beforeExecute" />
+    <ExecuteButton
+      :executable="executable"
+      :before-execute="beforeExecute"
+      @execute-successful="$emit('execute-successful', $event)"
+      @execute-failed="$emit('execute-failed', $event)"
+    />
     <ExecuteLimitInput :executable="executable" @limit-changed="$emit('limit-changed', $event)" />
   </div>
 </template>
@@ -46,7 +51,7 @@
         default: undefined
       }
     },
-    emits: ['limit-changed']
+    emits: ['execute-failed', 'execute-successful', 'limit-changed']
   });
 </script>
 

+ 3 - 0
desktop/core/src/desktop/js/apps/editor/components/ExecutableActionsKoBridge.vue

@@ -21,6 +21,8 @@
     :executable="executable"
     :before-execute="beforeExecute"
     @limit-changed="limitChanged"
+    @execute-failed="$emit('execute-failed', $event)"
+    @execute-successful="$emit('execute-successful', $event)"
   />
 </template>
 
@@ -48,6 +50,7 @@
         default: undefined
       }
     },
+    emits: ['execute-failed', 'execute-successful'],
     setup(props) {
       const subTracker = new SubscriptionTracker();
       const { executableObservable } = toRefs(props);

+ 31 - 7
desktop/core/src/desktop/js/apps/editor/components/ExecuteButton.vue

@@ -55,20 +55,24 @@
 </template>
 
 <script lang="ts">
-  import { EXECUTABLE_UPDATED_TOPIC, ExecutableUpdatedEvent } from 'apps/editor/execution/events';
   import { defineComponent, PropType, ref, toRefs, watch } from 'vue';
 
+  import { EXECUTE_ACTIVE_EXECUTABLE_TOPIC, ExecuteActiveExecutableEvent } from './events';
+  import { Session } from 'apps/editor/execution/api';
+  import {
+    EXECUTABLE_TRANSITIONED_TOPIC,
+    EXECUTABLE_UPDATED_TOPIC,
+    ExecutableTransitionedEvent,
+    ExecutableUpdatedEvent
+  } from 'apps/editor/execution/events';
+  import { ExecutionStatus } from 'apps/editor/execution/executable';
+  import sessionManager from 'apps/editor/execution/sessionManager';
   import SqlExecutable from 'apps/editor/execution/sqlExecutable';
   import HueButton from 'components/HueButton.vue';
   import SubscriptionTracker from 'components/utils/SubscriptionTracker';
   import huePubSub from 'utils/huePubSub';
   import I18n from 'utils/i18n';
 
-  import { Session } from 'apps/editor/execution/api';
-  import { ExecutionStatus } from 'apps/editor/execution/executable';
-  import sessionManager from 'apps/editor/execution/sessionManager';
-  import { EXECUTE_ACTIVE_EXECUTABLE_TOPIC, ExecuteActiveExecutableEvent } from './events';
-
   const WHITE_SPACE_REGEX = /^\s*$/;
 
   export default defineComponent({
@@ -86,7 +90,13 @@
         default: undefined
       }
     },
-    emits: ['execute-started', 'executable-updated', 'execute-stopping'],
+    emits: [
+      'execute-failed',
+      'execute-started',
+      'execute-successful',
+      'executable-updated',
+      'execute-stopping'
+    ],
     setup(props, { emit }) {
       const { executable, beforeExecute } = toRefs(props);
       const subTracker = new SubscriptionTracker();
@@ -158,6 +168,20 @@
         emit('executable-updated', { executable: updatedExecutable, active });
       });
 
+      subTracker.subscribe<ExecutableTransitionedEvent>(EXECUTABLE_TRANSITIONED_TOPIC, event => {
+        if (event.executable.id === executable.value?.id) {
+          if (
+            event.newStatus === ExecutionStatus.available ||
+            event.newStatus === ExecutionStatus.streaming ||
+            event.newStatus === ExecutionStatus.success
+          ) {
+            emit('execute-successful', executable.value);
+          } else if (event.newStatus === ExecutionStatus.failed) {
+            emit('execute-failed', executable.value);
+          }
+        }
+      });
+
       subTracker.subscribe<ExecuteActiveExecutableEvent>(
         EXECUTE_ACTIVE_EXECUTABLE_TOPIC,
         async eventExecutable => {

+ 1 - 11
desktop/core/src/desktop/js/apps/editor/components/executionAnalysis/ExecutionAnalysisPanel.vue

@@ -76,8 +76,7 @@
         required: true
       }
     },
-    emits: ['execution-error'],
-    setup(props, { emit }) {
+    setup(props) {
       const subTracker = new SubscriptionTracker();
       onBeforeUnmount(subTracker.dispose.bind(subTracker));
 
@@ -89,20 +88,12 @@
       const jobsAvailable = computed(() => !!jobs.length);
       const jobsWithUrls = computed(() => jobs.filter(job => job.url));
 
-      let notifiedErrors = false;
-
       const debouncedUpdate = debounce((executable: Executable): void => {
         const { status, logs } = executable;
         executionLogs.value = logs.fullLog;
         jobs.splice(0, jobs.length, ...logs.jobs);
         errors.splice(0, errors.length, ...logs.errors);
-
         analysisAvailable.value = status !== ExecutionStatus.ready || !!errors.length;
-
-        if (errors.length && !notifiedErrors) {
-          emit('execution-error');
-        }
-        notifiedErrors = !!errors.length;
       }, 5);
 
       const updateFromExecutable = (executable: Executable): void => {
@@ -131,7 +122,6 @@
         jobsAvailable,
         jobsWithUrls,
         errors,
-        notifiedErrors,
         I18n
       };
     }

+ 1 - 10
desktop/core/src/desktop/js/apps/editor/components/executionAnalysis/ExecutionAnalysisPanelKoBridge.vue

@@ -17,11 +17,7 @@
 -->
 
 <template>
-  <ExecutionAnalysisPanel
-    v-if="executable"
-    :executable="executable"
-    @execution-error="onExecutionError"
-  />
+  <ExecutionAnalysisPanel v-if="executable" :executable="executable" />
 </template>
 
 <script lang="ts">
@@ -52,11 +48,6 @@
       subTracker.trackObservable(executableObservable, executable);
 
       return { executable };
-    },
-    methods: {
-      onExecutionError(): void {
-        this.$el.dispatchEvent(new CustomEvent('execution-error', { bubbles: true }));
-      }
     }
   });
 

+ 0 - 3
desktop/core/src/desktop/js/apps/editor/snippet.js

@@ -777,9 +777,6 @@ export default class Snippet {
     if (executable) {
       this.lastExecuted(executable.executeStarted);
       this.status(executable.status);
-      if (executable.result) {
-        this.currentQueryTab('queryResults');
-      }
       if (this.parentVm.editorMode() && executable.history) {
         this.parentNotebook.id(executable.history.id);
         this.parentNotebook.uuid(executable.history.uuid);

+ 8 - 5
desktop/libs/notebook/src/notebook/templates/editor2.mako

@@ -610,9 +610,15 @@
 <script type ="text/html" id="editor-execution-controls">
   <div class="snippet-actions" style="padding: 5px;">
     <div class="pull-left">
-      <executable-actions-ko-bridge data-bind="vueKoProps: {
+      <executable-actions-ko-bridge data-bind="
+        vueEvents: {
+          'execute-successful': function () { currentQueryTab('queryResults') },
+          'execute-failed': function () { currentQueryTab('executionAnalysis') }
+        },
+        vueKoProps: {
           'executable-observable': activeExecutable,
-          'before-execute': beforeExecute
+          'before-execute': beforeExecute,
+
         }"></executable-actions-ko-bridge>
     </div>
     <!-- ko if: isSqlDialect() && !$root.isPresentationMode() -->
@@ -1037,9 +1043,6 @@
               <execution-analysis-panel-ko-bridge class="execution-analysis-bridge" data-bind="
                 vueKoProps: {
                   'executable-observable': activeExecutable
-                },
-                vueEvents: {
-                  'execution-error': function () { currentQueryTab('executionAnalysis') }
                 }
               "></execution-analysis-panel-ko-bridge>
             </div>