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

HUE-5796 [assist] Cancel previous assist search calls when typing fast

Johan Ahlen 8 жил өмнө
parent
commit
7800926796

+ 7 - 1
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -290,6 +290,12 @@ var ApiHelper = (function () {
     };
   };
 
+  ApiHelper.prototype.cancelActiveRequest = function (request) {
+    if (typeof request !== 'undefined' && request !== null && request.readyState < 4) {
+      request.abort();
+    }
+  };
+
   /**
    * @param {string} url
    * @param {Object} data
@@ -1672,7 +1678,7 @@ var ApiHelper = (function () {
 
   ApiHelper.prototype.navSearchAutocomplete = function (options) {
     var self = this;
-    $.post('/desktop/api/search/entities_interactive', {
+    return $.post('/desktop/api/search/entities_interactive', {
       query_s: ko.mapping.toJSON(options.query),
       limit: 10,
       sources: '["' + options.source + '"]'

+ 2 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -93,7 +93,8 @@
         minLength: 0,
         limitWidthToInput: false,
         minWidth: 200,
-        disabled: true
+        disabled: true,
+        delay: 400
       }, options);
 
       if (options.addCount) {

+ 4 - 1
desktop/core/src/desktop/templates/assist_search.mako

@@ -304,6 +304,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER
           });
         };
 
+        var previousCall = null;
         self.navAutocompleteSource = function (request, callback) {
           var facetMatch = request.term.match(/([a-z]+):\s*(\S+)?$/i);
           var isFacet = facetMatch !== null;
@@ -313,7 +314,9 @@ from notebook.conf import ENABLE_QUERY_BUILDER
 
           var visiblePanel = self.assistPanel.visiblePanel();
 
-          self.apiHelper.navSearchAutocomplete({
+          self.apiHelper.cancelActiveRequest(previousCall);
+
+          previousCall = self.apiHelper.navSearchAutocomplete({
             source: visiblePanel.type === 'sql' ?
                 (visiblePanel.panelData.selectedSource() ? visiblePanel.panelData.selectedSource().sourceType : 'hive') : visiblePanel.type,
             query:  request.term,

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

@@ -382,9 +382,7 @@ var EditorViewModel = (function() {
     var lastFetchQueriesRequest = null;
 
     self.fetchQueries = function () {
-      if (lastFetchQueriesRequest !== null && lastFetchQueriesRequest.readyState < 4) {
-        lastFetchQueriesRequest.abort();
-      }
+      self.getApiHelper().cancelActiveRequest(lastFetchQueriesRequest);
 
       var QUERIES_PER_PAGE = 50;
       lastQueriesPage = self.queriesCurrentPage();
@@ -869,9 +867,7 @@ var EditorViewModel = (function() {
           return;
         }
 
-        if (lastComplexityRequest && lastComplexityRequest.readyState < 4) {
-          lastComplexityRequest.abort();
-        }
+        self.getApiHelper().cancelActiveRequest(lastComplexityRequest);
 
         logGA('get_query_risk');
         self.complexityCheckRunning(true);
@@ -1198,9 +1194,7 @@ var EditorViewModel = (function() {
     };
 
     self.queryCompatibility = function (targetPlatform) {
-      if (lastCompatibilityRequest && lastCompatibilityRequest.readyState < 4) {
-        lastCompatibilityRequest.abort();
-      }
+      self.getApiHelper().cancelActiveRequest(lastCompatibilityRequest);
 
       logGA('compatibility');
       self.compatibilityCheckRunning(targetPlatform != self.type());