superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [Bug] Resize should trigger chart re-render (#4322)
Date Thu, 01 Feb 2018 02:02:23 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 133f98a  [Bug] Resize should trigger chart re-render (#4322)
133f98a is described below

commit 133f98ad584ebde433af38dae83eee4b87dd355b
Author: Grace Guo <grace.guo@airbnb.com>
AuthorDate: Wed Jan 31 18:02:16 2018 -0800

    [Bug] Resize should trigger chart re-render (#4322)
---
 superset/assets/javascripts/chart/Chart.jsx        |  4 +-
 .../assets/spec/javascripts/chart/Chart_spec.jsx   | 71 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/superset/assets/javascripts/chart/Chart.jsx b/superset/assets/javascripts/chart/Chart.jsx
index d370c79..111c48e 100644
--- a/superset/assets/javascripts/chart/Chart.jsx
+++ b/superset/assets/javascripts/chart/Chart.jsx
@@ -87,7 +87,7 @@ class Chart extends React.PureComponent {
   componentDidUpdate(prevProps) {
     if (
         this.props.queryResponse &&
-        this.props.chartStatus === 'success' &&
+        ['success', 'rendered'].indexOf(this.props.chartStatus) > -1 &&
         !this.props.queryResponse.error && (
         prevProps.annotationData !== this.props.annotationData ||
         prevProps.queryResponse !== this.props.queryResponse ||
@@ -210,7 +210,7 @@ class Chart extends React.PureComponent {
         {!this.props.chartAlert &&
           <ChartBody
             containerId={this.containerId}
-            vizType={this.props.formData.viz_type}
+            vizType={this.props.vizType}
             height={this.height}
             width={this.width}
             ref={(inner) => {
diff --git a/superset/assets/spec/javascripts/chart/Chart_spec.jsx b/superset/assets/spec/javascripts/chart/Chart_spec.jsx
new file mode 100644
index 0000000..f4754f4
--- /dev/null
+++ b/superset/assets/spec/javascripts/chart/Chart_spec.jsx
@@ -0,0 +1,71 @@
+import React from 'react';
+import { shallow } from 'enzyme';
+import { describe, it } from 'mocha';
+import { expect } from 'chai';
+import sinon from 'sinon';
+
+import { chart as initChart } from '../../../javascripts/chart/chartReducer';
+import Chart from '../../../javascripts/chart/Chart';
+
+describe('Chart', () => {
+  const chart = {
+    ...initChart,
+    queryResponse: {
+      form_data: {},
+      error: null,
+      status: 'success',
+    },
+  };
+  const mockedProps = {
+    ...chart,
+    chartKey: 'slice_223',
+    containerId: 'slice-container-223',
+    datasource: {},
+    formData: {},
+    vizType: 'pie',
+    height: 300,
+    width: 400,
+    actions: {
+      runQuery: () => {},
+    },
+  };
+
+  describe('renderViz', () => {
+    let wrapper;
+    let stub;
+    beforeEach(() => {
+      wrapper = shallow(
+        <Chart {...mockedProps} />,
+      );
+      stub = sinon.stub(wrapper.instance(), 'renderViz');
+    });
+
+    it('should not call when loading', () => {
+      const prevProp = wrapper.props();
+      wrapper.setProps({
+        height: 100,
+      });
+      wrapper.instance().componentDidUpdate(prevProp);
+      expect(stub.callCount).to.equals(0);
+    });
+
+    it('should call after chart stop loading', () => {
+      const prevProp = wrapper.props();
+      wrapper.setProps({
+        chartStatus: 'success',
+      });
+      wrapper.instance().componentDidUpdate(prevProp);
+      expect(stub.callCount).to.equals(1);
+    });
+
+    it('should call after resize', () => {
+      const prevProp = wrapper.props();
+      wrapper.setProps({
+        chartStatus: 'rendered',
+        height: 100,
+      });
+      wrapper.instance().componentDidUpdate(prevProp);
+      expect(stub.callCount).to.equals(1);
+    });
+  });
+});

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message