Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Cherry pick 2 fixes #6

Merged
merged 2 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset/assets/javascripts/chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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 ||
Expand Down Expand Up @@ -183,7 +183,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) => {
Expand Down
9 changes: 4 additions & 5 deletions superset/assets/javascripts/chart/chartAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export function chartUpdateSucceeded(queryResponse, key) {
}

export const CHART_UPDATE_STOPPED = 'CHART_UPDATE_STOPPED';
export function chartUpdateStopped(queryRequest, key) {
if (queryRequest) {
queryRequest.abort();
}
export function chartUpdateStopped(key) {
return { type: CHART_UPDATE_STOPPED, key };
}

Expand Down Expand Up @@ -146,7 +143,9 @@ export function runQuery(formData, force = false, timeout = 60, key) {
});
if (err.statusText === 'timeout') {
dispatch(chartUpdateTimeout(err.statusText, timeout, key));
} else if (err.statusText !== 'abort') {
} else if (err.statusText === 'abort') {
dispatch(chartUpdateStopped(key));
} else {
let errObject;
if (err.responseJSON) {
errObject = err.responseJSON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ExploreViewContainer extends React.Component {
}

onStop() {
this.props.actions.chartUpdateStopped(this.props.chart.queryRequest);
return this.props.chart.queryRequest.abort();
}

getWidth() {
Expand Down
71 changes: 71 additions & 0 deletions superset/assets/spec/javascripts/chart/Chart_spec.jsx
Original file line number Diff line number Diff line change
@@ -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);
});
});
});