Skip to content

Commit

Permalink
Abort ajax request on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Feb 7, 2017
1 parent f55353e commit fbf6ff7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
17 changes: 11 additions & 6 deletions superset/assets/javascripts/explorev2/actions/exploreActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export function setFieldValue(fieldName, value, validationErrors) {
}

export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED';
export function chartUpdateStarted() {
return { type: CHART_UPDATE_STARTED };
export function chartUpdateStarted(queryRequest) {
return { type: CHART_UPDATE_STARTED, queryRequest };
}

export const CHART_UPDATE_SUCCEEDED = 'CHART_UPDATE_SUCCEEDED';
Expand All @@ -141,7 +141,10 @@ export function chartUpdateSucceeded(queryResponse) {
}

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

Expand Down Expand Up @@ -228,13 +231,15 @@ export function updateChartStatus(status) {
export const RUN_QUERY = 'RUN_QUERY';
export function runQuery(formData, datasourceType) {
return function (dispatch) {
dispatch(chartUpdateStarted());
const url = getExploreUrl(formData, datasourceType, 'json');
$.getJSON(url, function (queryResponse) {
const queryRequest = $.getJSON(url, function (queryResponse) {
dispatch(chartUpdateSucceeded(queryResponse));
}).fail(function (err) {
dispatch(chartUpdateFailed(err.responseJSON));
if (err.statusText !== 'abort') {
dispatch(chartUpdateFailed(err.responseJSON));
}
});
dispatch(chartUpdateStarted(queryRequest));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const propTypes = {
form_data: PropTypes.object.isRequired,
standalone: PropTypes.bool.isRequired,
triggerQuery: PropTypes.bool.isRequired,
queryRequest: PropTypes.object,
};

class ExploreViewContainer extends React.Component {
Expand Down Expand Up @@ -68,7 +69,7 @@ class ExploreViewContainer extends React.Component {
}

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

getHeight() {
Expand Down Expand Up @@ -182,6 +183,7 @@ function mapStateToProps(state) {
standalone: state.standalone,
triggerQuery: state.triggerQuery,
forcedHeight: state.forced_height,
queryRequest: state.queryRequest,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@ export default function QueryAndSaveBtns(
});
const qryButtonStyle = errorMessage ? 'danger' : 'primary';
const saveButtonDisabled = errorMessage ? true : loading;
const qryOrStropButton = loading ? (
const qryOrStopButton = loading ? (
<Button
id="stop_button"
onClick={onStop}
bsStyle="warning"
>
<i className="fa-stop-circle-o" /> Stop
</Button>
) : (
<Button
id="query_button"
onClick={onQuery}
bsStyle={qryButtonStyle}
>
Expand All @@ -46,7 +44,7 @@ export default function QueryAndSaveBtns(
return (
<div>
<ButtonGroup className="query-and-save">
{qryOrStropButton}
{qryOrStopButton}
<Button
className={saveClasses}
data-target="#save_modal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ export const exploreReducer = function (state, action) {
return Object.assign({}, state, changes);
},
[actions.CHART_UPDATE_SUCCEEDED]() {
if (state.chartStatus === 'stopped') {
return state;
}
return Object.assign(
{},
state,
Expand All @@ -90,6 +87,7 @@ export const exploreReducer = function (state, action) {
chartUpdateEndTime: null,
chartUpdateStartTime: now(),
triggerQuery: false,
queryRequest: action.queryRequest,
});
},
[actions.CHART_UPDATE_STOPPED]() {
Expand All @@ -111,9 +109,6 @@ export const exploreReducer = function (state, action) {
});
},
[actions.CHART_UPDATE_FAILED]() {
if (state.chartStatus === 'stopped') {
return state;
}
return Object.assign({}, state, {
chartStatus: 'failed',
chartAlert: action.queryResponse.error,
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explorev2/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getFieldsState(state, form_data) {
if (field.multi && formData[k].length > 0 && choiceValues.indexOf(formData[k][0]) < 0) {
delete formData[k];
} else if (!field.multi && choiceValues.indexOf(formData[k]) < 0) {
//delete form_data[k];
// delete form_data[k];
// TODO what's not working here?
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { shallow } from 'enzyme';

import ExploreActionButtons from '../../../../javascripts/explorev2/components/ExploreActionButtons';
import ExploreActionButtons from
'../../../../javascripts/explorev2/components/ExploreActionButtons';

describe('ExploreActionButtons', () => {
const defaultProps = {
Expand Down

0 comments on commit fbf6ff7

Please sign in to comment.