You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/30 18:17:17 UTC

[GitHub] betodealmeida closed pull request #5777: Fix redirect to SQL Lab

betodealmeida closed pull request #5777: Fix redirect to SQL Lab
URL: https://github.com/apache/incubator-superset/pull/5777
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/chart/chartAction.js b/superset/assets/src/chart/chartAction.js
index 22de6b8285..38b5c9c23d 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 ea8de8b54d..5563d5c8b2 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 */


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org