Skip to content

Commit

Permalink
Fix redirect to SQL Lab (apache#5777)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Aug 30, 2018
1 parent ad52d4f commit 419576b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions superset/assets/src/chart/chartAction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import URI from 'urijs';

import { getExploreUrlAndPayload, getAnnotationJsonUrl } from '../explore/exploreUtils';
import { requiresQuery, ANNOTATION_SOURCE_TYPES } from '../modules/AnnotationTypes';
import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger';
Expand Down Expand Up @@ -201,23 +203,28 @@ export function runQuery(formData, force = false, timeout = 60, key) {
};
}

export const SQLLAB_REDIRECT_FAILED = 'SQLLAB_REDIRECT_FAILED';
export function sqllabRedirectFailed(error, key) {
return { type: SQLLAB_REDIRECT_FAILED, error, key };
}

export function redirectSQLLab(formData) {
return function () {
const { url } = getExploreUrlAndPayload({ formData, endpointType: 'query' });
return function (dispatch) {
const { url, payload } = getExploreUrlAndPayload({ formData, endpointType: 'query' });
$.ajax({
type: 'GET',
type: 'POST',
url,
data: {
form_data: JSON.stringify(payload),
},
success: (response) => {
const redirectUrl = new URL(window.location);
redirectUrl.pathname = '/superset/sqllab';
for (const k of redirectUrl.searchParams.keys()) {
redirectUrl.searchParams.delete(k);
}
redirectUrl.searchParams.set('datasourceKey', formData.datasource);
redirectUrl.searchParams.set('sql', response.query);
window.open(redirectUrl.href, '_blank');
const redirectUrl = new URI(window.location);
redirectUrl
.pathname('/superset/sqllab')
.search({ datasourceKey: formData.datasource, sql: response.query });
window.open(redirectUrl.href(), '_blank');
},
error: () => notify.error(t("The SQL couldn't be loaded")),
error: (xhr, status, error) => dispatch(sqllabRedirectFailed(error, formData.slice_id)),
});
};
}
Expand Down
6 changes: 6 additions & 0 deletions superset/assets/src/chart/chartReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export default function chartReducer(charts = {}, action) {
annotationQuery,
};
},
[actions.SQLLAB_REDIRECT_FAILED](state) {
return { ...state,
chartStatus: 'failed',
chartAlert: t('An error occurred while redirecting to SQL Lab: %s', action.error),
};
},
};

/* eslint-disable no-param-reassign */
Expand Down

0 comments on commit 419576b

Please sign in to comment.