Pārlūkot izejas kodu

AMBARI-12655. Hosts Page Performance: Filter update/save related problems (rzang)

Richard Zang 10 gadi atpakaļ
vecāks
revīzija
8b96592a0e

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

@@ -75,6 +75,9 @@ App.TableServerViewMixin = Em.Mixin.create({
    * @param type
    */
   updateFilter: function (iColumn, value, type) {
+    // Do not even trigger update flow if it's a blank update
+    if (this.isBlankFilterUpdate(iColumn, value, type)) { return; }
+
     var self = this;
     this.set('controller.resetStartIndex', false);
     this.saveFilterConditions(iColumn, value, type, false);
@@ -90,6 +93,29 @@ App.TableServerViewMixin = Em.Mixin.create({
     }
   },
 
+  /**
+   * 1) Has previous saved filter
+   * 2) Value to update is empty
+   * 3) Value to update is same as before
+   * Returns true if (!1&&2 || 1&&3)
+   * @param iColumn
+   * @param value
+   * @param type
+   * @returns {boolean|*}
+   */
+  isBlankFilterUpdate: function(iColumn, value, type) {
+    var result = false;
+    var filterConfitions = this.get('filterConditions');
+    var filterCondition = filterConfitions? filterConfitions.findProperty('iColumn', iColumn) : null;
+    if ((!filterCondition && Em.isEmpty(value))
+    || (filterCondition && filterCondition.value == value)
+    || (filterCondition && typeof filterCondition.value == 'object'
+        && JSON.stringify(filterCondition.value) == JSON.stringify(value))) {
+      result = true;
+    }
+    return result;
+  },
+
   /**
    * success callback for updater request
    */

+ 10 - 2
ambari-web/app/views/common/table_view.js

@@ -104,7 +104,7 @@ App.TableView = Em.View.extend(App.UserPref, {
     var name = this.get('controller.name');
     var self = this;
     var filterConditions = App.db.getFilterConditions(name);
-    if (filterConditions) {
+    if (!Em.isEmpty(filterConditions)) {
       this.set('filterConditions', filterConditions);
 
       var childViews = this.get('childViews');
@@ -367,6 +367,8 @@ App.TableView = Em.View.extend(App.UserPref, {
       };
       this.get('filterConditions').push(filterCondition);
     }
+    // remove empty entries
+    this.set('filterConditions', this.get('filterConditions').filter(function(item){ return !Em.isEmpty(item.value); }));
     App.db.setFilterConditions(this.get('controller.name'), this.get('filterConditions'));
   },
 
@@ -383,7 +385,13 @@ App.TableView = Em.View.extend(App.UserPref, {
   },
 
   clearFilterCondition: function() {
-    App.db.setFilterConditions(this.get('controller.name'), null);
+    var result = false;
+    var currentFCs = App.db.getFilterConditions(this.get('controller.name'));
+    if (currentFCs != null) {
+      App.db.setFilterConditions(this.get('controller.name'), null);
+      result = true;
+    }
+    return result;
   },
 
   /**

+ 4 - 4
ambari-web/test/mixins/common/table_server_view_mixin_test.js

@@ -147,18 +147,18 @@ describe('App.MainConfigHistoryView', function() {
       this.clock = sinon.useFakeTimers();
 
       view.set('filteringComplete', false);
-      view.updateFilter(1, '', 'string');
+      view.updateFilter(1, '1', 'string');
       expect(view.get('controller.resetStartIndex')).to.be.false;
-      expect(view.saveFilterConditions.calledWith(1, '', 'string', false)).to.be.true;
+      expect(view.saveFilterConditions.calledWith(1, '1', 'string', false)).to.be.true;
       view.set('filteringComplete', true);
       this.clock.tick(view.get('filterWaitingTime'));
-      expect(view.updateFilter.calledWith(1, '', 'string')).to.be.true;
+      expect(view.updateFilter.calledWith(1, '1', 'string')).to.be.true;
       this.clock.restore();
     });
     it('filteringComplete is true', function() {
       view.set('filteringComplete', true);
 
-      view.updateFilter(1, '', 'string');
+      view.updateFilter(1, '1', 'string');
       expect(view.get('controller.resetStartIndex')).to.be.true;
       expect(view.refresh.calledOnce).to.be.true;
     });