superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [incubator-superset] branch master updated: Fix redirect to SQL Lab (#5777)
Date Thu, 30 Aug 2018 18:17:19 GMT
This is an automated email from the ASF dual-hosted git repository.

beto 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 8af3e1f  Fix redirect to SQL Lab (#5777)
8af3e1f is described below

commit 8af3e1f3a17618ffda70d659d0eb0fe776925673
Author: Beto Dealmeida <roberto@dealmeida.net>
AuthorDate: Thu Aug 30 11:17:15 2018 -0700

    Fix redirect to SQL Lab (#5777)
---
 superset/assets/src/chart/chartAction.js  | 31 +++++++++++++++++++------------
 superset/assets/src/chart/chartReducer.js |  6 ++++++
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/superset/assets/src/chart/chartAction.js b/superset/assets/src/chart/chartAction.js
index 22de6b8..38b5c9c 100644
--- a/superset/assets/src/chart/chartAction.js
+++ b/superset/assets/src/chart/chartAction.js
@@ -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';
@@ -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)),
     });
   };
 }
diff --git a/superset/assets/src/chart/chartReducer.js b/superset/assets/src/chart/chartReducer.js
index ea8de8b..5563d5c 100644
--- a/superset/assets/src/chart/chartReducer.js
+++ b/superset/assets/src/chart/chartReducer.js
@@ -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 */


Mime
View raw message