Переглянути джерело

AMBARI-8633 Dashboard > Config History tab does a "double load". (atkach)

Andrii Tkach 10 роки тому
батько
коміт
c1482f8202

+ 9 - 0
ambari-web/app/views/main/dashboard/config_history_view.js

@@ -25,6 +25,7 @@ App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
 
   controllerBinding: 'App.router.mainConfigHistoryController',
   filteringComplete: false,
+  isInitialRendering: true,
 
   /**
    * return filtered number of all content number information displayed on the page footer bar
@@ -37,6 +38,7 @@ App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
   didInsertElement: function () {
     this.addObserver('startIndex', this, 'updatePagination');
     this.addObserver('displayLength', this, 'updatePagination');
+    this.set('isInitialRendering', true);
     this.refresh();
     this.set('controller.isPolling', true);
     this.get('controller').doPolling();
@@ -50,6 +52,12 @@ App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
     clearTimeout(this.get('controller.timeoutRef'));
   },
 
+  updateFilter: function (iColumn, value, type) {
+    if (!this.get('isInitialRendering')) {
+      this._super(iColumn, value, type);
+    }
+  },
+
   sortView: sort.serverWrapperView,
   versionSort: sort.fieldView.extend({
     column: 1,
@@ -178,6 +186,7 @@ App.MainConfigHistoryView = App.TableView.extend(App.TableServerViewMixin, {
     var self = this;
     this.set('filteringComplete', false);
     this.get('controller').load().done(function () {
+      self.set('isInitialRendering', false);
       self.set('filteringComplete', true);
       self.propertyDidChange('pageContent');
       self.set('controller.resetStartIndex', false);

+ 29 - 0
ambari-web/test/views/main/dashboard/config_history_view_test.js

@@ -47,6 +47,7 @@ describe('App.MainConfigHistoryView', function() {
 
       view.didInsertElement();
       expect(view.addObserver.calledTwice).to.be.true;
+      expect(view.get('isInitialRendering')).to.be.true;
       expect(view.get('controller.isPolling')).to.be.true;
       expect(view.get('controller').doPolling.calledOnce).to.be.true;
 
@@ -55,6 +56,34 @@ describe('App.MainConfigHistoryView', function() {
     });
   });
 
+  describe('#updateFilter()', function () {
+    var cases = [
+      {
+        isInitialRendering: false,
+        updateFilterCalled: true,
+        title: 'updateFilter should be called'
+      },
+      {
+        isInitialRendering: true,
+        updateFilterCalled: false,
+        title: 'updateFilter should not be called'
+      }
+    ];
+    beforeEach(function () {
+      sinon.stub(view, 'saveFilterConditions', Em.K);
+    });
+    afterEach(function () {
+      view.saveFilterConditions.restore();
+    });
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        view.set('isInitialRendering', item.isInitialRendering);
+        view.updateFilter(1, 'value', 'string');
+        expect(view.get('saveFilterConditions').calledWith(1, 'value', 'string')).to.equal(item.updateFilterCalled);
+      });
+    });
+  });
+
   describe('#willDestroyElement()', function() {
     it('', function() {
       view.willDestroyElement();