Browse Source

AMBARI-9864. Double spinner appears after "clear filters" press on Hosts page (alexantonenko)

Alex Antonenko 10 năm trước cách đây
mục cha
commit
303628ce39

+ 17 - 0
ambari-web/app/mixins/common/table_server_view_mixin.js

@@ -87,6 +87,23 @@ App.TableServerViewMixin = Em.Mixin.create({
       this.refresh();
     }
   },
+
+  /**
+   * success callback for updater request
+   */
+  updaterSuccessCb: function () {
+    clearTimeout(this.get('timeOut'));
+    this.set('filteringComplete', true);
+    this.propertyDidChange('pageContent');
+  },
+
+  /**
+   * error callback for updater request
+   */
+  updaterErrorCb: function () {
+    this.set('requestError', arguments);
+  },
+
   /**
    * synchronize properties of view with controller to generate query parameters
    */

+ 2 - 7
ambari-web/app/views/main/host.js

@@ -91,17 +91,12 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, {
    * called when trigger property(<code>refreshTriggers</code>) is changed
    */
   refresh: function () {
-    var self = this;
     this.set('filteringComplete', false);
     var updaterMethodName = this.get('updater.tableUpdaterMap')[this.get('tableName')];
-    this.get('updater')[updaterMethodName](function () {
-      self.set('filteringComplete', true);
-      self.propertyDidChange('pageContent');
-    }, function() {
-      self.set('requestError', arguments);
-    });
+    this.get('updater')[updaterMethodName](this.updaterSuccessCb.bind(this), this.updaterErrorCb.bind(this));
     return true;
   },
+
   /**
    * reset filters value by column to which filter belongs
    * @param columns {Array}

+ 18 - 0
ambari-web/test/mixins/common/table_server_view_mixin_test.js

@@ -162,6 +162,24 @@ describe('App.MainConfigHistoryView', function() {
       expect(view.get('controller.resetStartIndex')).to.be.true;
       expect(view.refresh.calledOnce).to.be.true;
     });
+
+    it('clear filters - refresh() clears timer', function () {
+      this.clock = sinon.useFakeTimers();
+
+      //clear filters simulation
+      view.set('filteringComplete', false);
+      view.updateFilter(0, '', 'string');
+
+      //filters cleared success
+      view.updaterSuccessCb();
+
+      //timeout in updateFilter() runs out
+      this.clock.tick(view.get('filterWaitingTime'));
+
+      //should not call update filter again
+      expect(view.updateFilter.calledOnce).to.be.true;
+      this.clock.restore();
+    })
   });
 
   describe('#resetStartIndex()', function() {