Răsfoiți Sursa

HUE-9004 [editor] Remove execution progress tracking from the snippet in notebook 2

Johan Ahlen 6 ani în urmă
părinte
comite
e7d9a465e5

+ 0 - 19
desktop/core/src/desktop/js/apps/notebook2/app.js

@@ -880,25 +880,6 @@ export const initNotebook2 = () => {
         huePubSub.publish(SHOW_NORMAL_RESULT_EVENT);
       });
 
-      $(document).on('progress', (e, options) => {
-        if (options.data === 100) {
-          window.setTimeout(() => {
-            $('#snippet_' + options.snippet.id())
-              .find('.progress-snippet')
-              .animate(
-                {
-                  height: '0'
-                },
-                100,
-                () => {
-                  options.snippet.progress(0);
-                  huePubSub.publish(REDRAW_FIXED_HEADERS_EVENT);
-                }
-              );
-          }, 2000);
-        }
-      });
-
       let hideTimeout = -1;
       $(document).on('hideAutocomplete', () => {
         window.clearTimeout(hideTimeout);

+ 31 - 3
desktop/core/src/desktop/js/apps/notebook2/components/ko.executableProgressBar.js

@@ -14,6 +14,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import $ from 'jquery';
 import ko from 'knockout';
 
 import 'ko/bindings/ko.publish';
@@ -21,6 +22,9 @@ import 'ko/bindings/ko.publish';
 import componentUtils from 'ko/components/componentUtils';
 import { EXECUTABLE_UPDATED_EVENT, EXECUTION_STATUS } from 'apps/notebook2/execution/executable';
 import DisposableComponent from 'ko/components/DisposableComponent';
+import { sleep } from 'utils/hueUtils';
+import { REDRAW_FIXED_HEADERS_EVENT } from 'apps/notebook2/events';
+import huePubSub from 'utils/huePubSub';
 
 export const NAME = 'executable-progress-bar';
 
@@ -31,7 +35,7 @@ const TEMPLATE = `
 `;
 
 class ExecutableProgressBar extends DisposableComponent {
-  constructor(params) {
+  constructor(params, element) {
     super();
     this.activeExecutable = params.activeExecutable;
 
@@ -63,10 +67,27 @@ class ExecutableProgressBar extends DisposableComponent {
       return Math.max(2, this.progress()) + '%';
     });
 
-    this.subscribe(EXECUTABLE_UPDATED_EVENT, executable => {
+    this.subscribe(EXECUTABLE_UPDATED_EVENT, async executable => {
       if (this.activeExecutable() === executable) {
         this.status(executable.status);
         this.progress(executable.progress);
+        if (executable.progress === 100) {
+          await sleep(2000);
+          $(element)
+            .parent()
+            .find('.progress-snippet')
+            .animate(
+              {
+                height: '0'
+              },
+              100
+            );
+        } else {
+          $(element)
+            .parent()
+            .find('.progress-snippet')
+            .css('height', '');
+        }
       }
     });
 
@@ -77,4 +98,11 @@ class ExecutableProgressBar extends DisposableComponent {
   }
 }
 
-componentUtils.registerComponent(NAME, ExecutableProgressBar, TEMPLATE);
+componentUtils.registerComponent(
+  NAME,
+  {
+    createViewModel: (params, componentInfo) =>
+      new ExecutableProgressBar(params, componentInfo.element)
+  },
+  TEMPLATE
+);

+ 0 - 1
desktop/core/src/desktop/js/apps/notebook2/components/ko.snippetEditorActions.js

@@ -141,7 +141,6 @@ class SnippetEditorActions {
 
     this.snippet.result.explanation('');
     this.snippet.errors([]);
-    this.snippet.progress(0);
     this.snippet.status(STATUS.ready);
 
     $.post('/notebook/api/explain', {

+ 0 - 7
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -756,16 +756,11 @@ export default class Snippet {
       defaultShowLogs = $.totalStorage('hue.editor.showLogs');
     }
     this.showLogs = ko.observable(snippet.showLogs || defaultShowLogs);
-    this.progress = ko.observable(snippet.progress || 0);
     this.jobs = ko.observableArray(snippet.jobs || []);
 
     this.executeNextTimeout = -1;
     this.refreshTimeouts = {};
 
-    this.progress.subscribe(val => {
-      $(document).trigger('progress', { data: val, snippet: this });
-    });
-
     this.showLogs.subscribe(val => {
       huePubSub.publish(REDRAW_FIXED_HEADERS_EVENT);
       if (this.parentVm.editorMode()) {
@@ -1083,7 +1078,6 @@ export default class Snippet {
   //   this.parentNotebook.forceHistoryInitialHeight(true);
   //   this.errors([]);
   //   huePubSub.publish('editor.clear.highlighted.errors', this.ace());
-  //   this.progress(0);
   //   this.jobs([]);
   //
   //   this.parentNotebook.historyCurrentPage(1);
@@ -1348,7 +1342,6 @@ export default class Snippet {
       // this.checkStatus();
     } else if (this.status() === STATUS.loading) {
       this.status(STATUS.failed);
-      this.progress(0);
       this.jobs([]);
     } else if (this.status() === STATUS.readyExecute) {
       this.execute();