Эх сурвалжийг харах

HUE-4747 [editor] Improve the UX of download form submission

Enrico Berti 9 жил өмнө
parent
commit
d55d1fcb6d

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

@@ -33,7 +33,7 @@
       "ace", "autocompleter", "availableSnippets", "history", "images", "inFocus", "selectedStatement", "user",
       "availableDatabases", "hasProperties", "aceMode", "snippetImage", "errorLoadingQueries",
       "cleanedStringMeta", "cleanedDateTimeMeta", "cleanedMeta", "cleanedNumericMeta",
-      "dependents", "canWrite", "queries"
+      "dependents", "canWrite", "queries", "avoidClosing"
     ]
   };
 
@@ -1312,6 +1312,8 @@
     self.retryModalConfirm = null;
     self.retryModalCancel = null;
 
+    self.avoidClosing = false;
+
     self.loadingHistory = ko.observable(self.history().length == 0);
     // TODO: Move fetchHistory and clearHistory into the Snippet and drop self.selectedSnippet. Actually, history should go in the assist in Hue 4.
     self.getSession = function (session_type) {

+ 3 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -3231,7 +3231,9 @@ ${ hueIcons.symbols() }
 
       // Close the notebook snippets when leaving the page
       window.onbeforeunload = function (e) {
-        viewModel.selectedNotebook().close();
+        if (!viewModel.selectedNotebook().avoidClosing) {
+          viewModel.selectedNotebook().close();
+        }
       };
       $(window).data('beforeunload', window.onbeforeunload);
 

+ 4 - 1
desktop/libs/notebook/src/notebook/templates/notebook_ko_components.mako

@@ -318,7 +318,7 @@ except ImportError, e:
 
 <%def name="downloadSnippetResults()">
   <script type="text/html" id="download-results-template">
-    <form method="POST" action="${ url('notebook:download') }" class="download-form" style="display: inline" target="_blank">
+    <form method="POST" action="${ url('notebook:download') }" class="download-form" style="display: inline">
       ${ csrf_token(request) | n,unicode }
       <input type="hidden" name="notebook"/>
       <input type="hidden" name="snippet"/>
@@ -556,6 +556,7 @@ except ImportError, e:
               self.downloadTruncated(result.truncated);
               self.downloadCounter(result.row_counter);
               self.isDownloading(false);
+              self.notebook.avoidClosing = false;
               if (self.downloadTruncated()) {
                 $('#downloadProgressModal').modal('show');
               }
@@ -566,11 +567,13 @@ except ImportError, e:
             catch (e) {
               self.isDownloading(false);
               $('#downloadProgressModal').modal('hide');
+              self.notebook.avoidClosing = false;
             }
           }
           timesChecked++;
         }, 500);
 
+        self.notebook.avoidClosing = true;
         self.$downloadForm.submit();
       };