Browse Source

HUE-5852 [editor] Show spinner on query compatibility checks

Also stored in totalStorage if the validator is open or close
Enrico Berti 8 years ago
parent
commit
ef7dc44

+ 19 - 20
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -815,12 +815,16 @@ var EditorViewModel = (function() {
     self.suggestion = ko.observable(typeof snippet.complexity != "undefined" && snippet.complexity != null ? snippet.complexity : '');
     self.hasSuggestion = ko.observable(false);
 
-    self.complexityCheckActive = ko.observable(true);
-    self.compatibilityCheckActive = ko.observable(true);
+    self.complexityCheckRunning = ko.observable(false);
+    self.compatibilityCheckRunning = ko.observable(false);
 
-    self.showOptimizer = ko.observable(false);
+    self.showOptimizer = ko.observable(self.getApiHelper().getFromTotalStorage('editor', 'show.optimizer', false));
+    self.showOptimizer.subscribe(function (newValue) {
+      if (newValue !== null) {
+        self.getApiHelper().setInTotalStorage('editor', 'show.optimizer', newValue);
+      }
+    });
 
-    self.isOptimizing = ko.observable(false);
 
     if (HAS_OPTIMIZER) {
       var lastComplexityRequest;
@@ -838,7 +842,7 @@ var EditorViewModel = (function() {
         }
 
         logGA('get_query_risk');
-        self.isOptimizing(true);
+        self.complexityCheckRunning(true);
         lastComplexityRequest = $.ajax({
           type: 'POST',
           url: '/notebook/api/optimizer/statement/risk',
@@ -855,29 +859,21 @@ var EditorViewModel = (function() {
               $(document).trigger('error', data.message);
             }
             lastCheckedComplexityStatement = self.statement_raw();
-            self.isOptimizing(false);
+            self.complexityCheckRunning(false);
           }
         });
       };
 
       self.delayedStatement.subscribe(function () {
         if (self.type() === 'hive') {
-          if (self.complexityCheckActive()) {
-            self.checkComplexity();
-          }
-          if (self.compatibilityCheckActive()) {
-            self.queryCompatibility();
-          }
+          self.checkComplexity();
+          self.queryCompatibility();
         }
       });
       if (self.statement_raw()) {
         window.setTimeout(function(){
-          if (self.complexityCheckActive()) {
-            self.checkComplexity();
-          }
-          if (self.compatibilityCheckActive()) {
-            self.queryCompatibility();
-          }
+          self.checkComplexity();
+          self.queryCompatibility();
         }, 2000);
       }
     }
@@ -1170,7 +1166,8 @@ var EditorViewModel = (function() {
       }
 
       logGA('compatibility');
-      self.isOptimizing(true);
+      self.compatibilityCheckRunning(true);
+      self.hasSuggestion(false);
 
       if (!targetPlatform) {
         targetPlatform = self.type();
@@ -1195,6 +1192,7 @@ var EditorViewModel = (function() {
               line: match === null ? null : parseInt(match[1]) - 1,
               col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
             });
+            self.status('with-optimizer-report');
           }
           if (self.suggestion().parseError()) {
             var match = ERROR_REGEX.exec(self.suggestion().parseError());
@@ -1203,6 +1201,7 @@ var EditorViewModel = (function() {
               line: match === null ? null : parseInt(match[1]) - 1,
               col: match === null ? null : (typeof match[3] !== 'undefined' ? parseInt(match[3]) : null)
             });
+            self.status('with-optimizer-report');
           }
           self.hasSuggestion(true);
         } else {
@@ -1211,7 +1210,7 @@ var EditorViewModel = (function() {
       }).fail(function (xhr, textStatus, errorThrown) {
         $(document).trigger("error", xhr.responseText);
       }).always(function () {
-        self.isOptimizing(false);
+        self.compatibilityCheckRunning(false);
       });
     };
 

+ 4 - 4
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1026,11 +1026,11 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
 <script type="text/html" id="code-editor-snippet-body">
   <!-- ko if: HAS_OPTIMIZER -->
-  <div title="${ _('Query Validator') }" data-bind="click: function(){ showOptimizer(!showOptimizer()) }, css: { 'active': showOptimizer }">
+  <div data-bind="click: function(){ showOptimizer(!showOptimizer()) }, css: { 'active': showOptimizer }, attr: { 'title': showOptimizer() ? '${ _ko('Close Query Validator') }' : '${ _ko('Open Query Validator') }'}">
     <div class="round-icon empty">&nbsp;</div>
-    <!-- ko if: !hasSuggestion() -->
+    <!-- ko if: !hasSuggestion() || compatibilityCheckRunning() -->
     <div class="round-icon idle">
-      <i class="fa fa-check"></i>
+      <i class="fa fa-spinner fa-spin"></i>
     </div>
     <!-- /ko -->
     <!-- ko if: hasSuggestion() -->
@@ -1564,7 +1564,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 
 <script type="text/html" id="snippet-execution-status">
   <div class="snippet-execution-status" data-bind="clickForAceFocus: ace">
-    <div class="snippet-progress-container" data-bind="visible: status() != 'canceled'">
+    <div class="snippet-progress-container" data-bind="visible: status() != 'canceled' && status() != 'with-optimizer-report'">
       <div class="progress-snippet progress active" data-bind="css: {
         'progress-starting': progress() == 0 && status() == 'running',
         'progress-warning': progress() > 0 && progress() < 100,