Browse Source

HUE-6256 [presentation] Clear dead snippet from presentationSnippets list

Romain Rigaux 8 years ago
parent
commit
e0f6b7e

+ 8 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1494,7 +1494,7 @@ var EditorViewModel = (function() {
 
 
     self.fetchResultData = function (rows, startOver) {
     self.fetchResultData = function (rows, startOver) {
       if (! self.isFetchingData) {
       if (! self.isFetchingData) {
-        if( self.status() == 'available') {
+        if (self.status() == 'available') {
           startLongOperationTimeout();
           startLongOperationTimeout();
           self.isFetchingData = true;
           self.isFetchingData = true;
           hueAnalytics.log('notebook', 'fetchResult/' + rows + '/' + startOver);
           hueAnalytics.log('notebook', 'fetchResult/' + rows + '/' + startOver);
@@ -2670,6 +2670,7 @@ var EditorViewModel = (function() {
         self.editorType('notebook');
         self.editorType('notebook');
         self.preEditorTogglingSnippet(_notebook.snippets()[0]);
         self.preEditorTogglingSnippet(_notebook.snippets()[0]);
         var _variables = _notebook.snippets()[0].variables();
         var _variables = _notebook.snippets()[0].variables();
+        var _statementKeys = [];
         // Split statements
         // Split statements
         _notebook.type('notebook');
         _notebook.type('notebook');
         _notebook.snippets()[0].statementsList().forEach(function (sql_statement) {
         _notebook.snippets()[0].statementsList().forEach(function (sql_statement) {
@@ -2691,8 +2692,14 @@ var EditorViewModel = (function() {
             _snippet.init();
             _snippet.init();
             _notebook.presentationSnippets()[sql_statement.hashCode()] = _snippet;
             _notebook.presentationSnippets()[sql_statement.hashCode()] = _snippet;
           }
           }
+          _statementKeys.push(sql_statement.hashCode());
           _newSnippets.push(_snippet);
           _newSnippets.push(_snippet);
         });
         });
+        $.each(_notebook.presentationSnippets(), function(key, statement) { // Dead statements
+          if (! key in _statementKeys) {
+            delete _notebook.presentationSnippets()[key];
+          }
+        });
       } else {
       } else {
         self.editorType(options.editor_type);
         self.editorType(options.editor_type);
         // Revert to one statement
         // Revert to one statement