Kaynağa Gözat

AMBARI-15085. Enhanced graph widgets aren't updated after getting no data (alexantonenko)

Alex Antonenko 9 yıl önce
ebeveyn
işleme
f92714910c

+ 6 - 2
ambari-web/app/mixins/common/widgets/widget_mixin.js

@@ -318,7 +318,9 @@ App.WidgetMixin = Ember.Mixin.create({
             graph.set('hasData', false);
             this.set('isExportButtonHidden', true);
             graph._showMessage('info', this.t('graphs.noData.title'), this.t('graphs.noDataAtTime.message'));
-            this.get('metrics').clear();
+            this.set('metrics', this.get('metrics').reject(function (item) {
+              return this.get('content.metrics').someProperty('name', item.name);
+            }, this));
           }
         }
       }, this);
@@ -341,7 +343,9 @@ App.WidgetMixin = Ember.Mixin.create({
         graph.set('hasData', false);
         this.set('isExportButtonHidden', true);
         graph._showMessage('warn', this.t('graphs.error.title'), this.t('graphs.error.message').format(textStatus, errorThrown));
-        this.get('metrics').clear();
+        this.set('metrics', this.get('metrics').reject(function (item) {
+          return this.get('content.metrics').someProperty('name', item.name);
+        }, this));
       }
     }
   },

+ 27 - 8
ambari-web/test/mixins/common/widget_mixin_test.js

@@ -391,11 +391,19 @@ describe('App.WidgetMixin', function () {
       view = Em.Object.create({
         _showMessage: Em.K
       }),
+      metrics = [
+        {
+          name: 'n0'
+        },
+        {
+          name: 'n1'
+        }
+      ],
       cases = [
         {
           graphView: null,
           isForcedAbort: false,
-          metricsLength: 1,
+          metrics: metrics,
           showMessageCallCount: 0,
           isExportButtonHidden: false,
           title: 'no graph view'
@@ -403,7 +411,7 @@ describe('App.WidgetMixin', function () {
         {
           graphView: {},
           isForcedAbort: false,
-          metricsLength: 1,
+          metrics: metrics,
           showMessageCallCount: 0,
           isExportButtonHidden: false,
           title: 'no childViews property'
@@ -412,7 +420,7 @@ describe('App.WidgetMixin', function () {
           graphView: {},
           childViews: [],
           isForcedAbort: false,
-          metricsLength: 1,
+          metrics: metrics,
           showMessageCallCount: 0,
           isExportButtonHidden: false,
           title: 'no child views'
@@ -421,7 +429,7 @@ describe('App.WidgetMixin', function () {
           graphView: {},
           childViews: [Em.Object.create({})],
           isForcedAbort: false,
-          metricsLength: 1,
+          metrics: metrics,
           showMessageCallCount: 0,
           isExportButtonHidden: false,
           title: 'no view with _showMessage method'
@@ -430,7 +438,11 @@ describe('App.WidgetMixin', function () {
           graphView: {},
           childViews: [Em.Object.create({}), view],
           isForcedAbort: false,
-          metricsLength: 0,
+          metrics: [
+            {
+              name: 'n1'
+            }
+          ],
           showMessageCallCount: 1,
           isExportButtonHidden: true,
           title: 'graph view is available'
@@ -439,7 +451,7 @@ describe('App.WidgetMixin', function () {
           graphView: {},
           childViews: [Em.Object.create({}), view],
           isForcedAbort: true,
-          metricsLength: 1,
+          metrics: metrics,
           showMessageCallCount: 0,
           isExportButtonHidden: false,
           title: 'request is aborted'
@@ -480,7 +492,14 @@ describe('App.WidgetMixin', function () {
 
         beforeEach(function () {
           obj = Em.Object.create(App.WidgetMixin, {
-            metrics: [{}],
+            metrics: metrics,
+            content: {
+              metrics: [
+                {
+                  name: 'n0'
+                }
+              ]
+            },
             isExportButtonHidden: false,
             graphView: item.graphView,
             childViews: item.childViews
@@ -491,7 +510,7 @@ describe('App.WidgetMixin', function () {
         });
 
         it('metrics array', function () {
-          expect(obj.get('metrics')).to.have.length(item.metricsLength);
+          expect(obj.get('metrics')).to.eql(item.metrics);
         });
 
         it('error message', function () {