mistercrunch closed pull request #6519: [RfC] Fix URL too long
URL: https://github.com/apache/incubator-superset/pull/6519
 
 
   

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/explore/components/ExploreViewContainer.jsx 
b/superset/assets/src/explore/components/ExploreViewContainer.jsx
index 162cb16333..ae52a0b46d 100644
--- a/superset/assets/src/explore/components/ExploreViewContainer.jsx
+++ b/superset/assets/src/explore/components/ExploreViewContainer.jsx
@@ -171,7 +171,7 @@ class ExploreViewContainer extends React.Component {
 
   addHistory({ isReplace = false, title }) {
     const { payload } = getExploreUrlAndPayload({ formData: 
this.props.form_data });
-    const longUrl = getExploreLongUrl(this.props.form_data);
+    const longUrl = getExploreLongUrl(this.props.form_data, null, false);
     try {
       if (isReplace) {
         history.replaceState(payload, title, longUrl);
diff --git a/superset/assets/src/explore/exploreUtils.js 
b/superset/assets/src/explore/exploreUtils.js
index 4eac3abce4..e9bcc9ff70 100644
--- a/superset/assets/src/explore/exploreUtils.js
+++ b/superset/assets/src/explore/exploreUtils.js
@@ -2,6 +2,8 @@
 import URI from 'urijs';
 import { availableDomains } from '../utils/hostNamesConfig';
 
+const MAX_URL_LENGTH = 8000;
+
 export function getChartKey(explore) {
   const slice = explore.slice;
   return slice ? (slice.slice_id) : 0;
@@ -40,7 +42,7 @@ export function getURIDirectory(formData, endpointType = 
'base') {
   return directory;
 }
 
-export function getExploreLongUrl(formData, endpointType) {
+export function getExploreLongUrl(formData, endpointType, allowOverflow = 
true, extraSearch = {}) {
   if (!formData.datasource) {
     return null;
   }
@@ -48,11 +50,23 @@ export function getExploreLongUrl(formData, endpointType) {
   const uri = new URI('/');
   const directory = getURIDirectory(formData, endpointType);
   const search = uri.search(true);
+  Object.keys(extraSearch).forEach((key) => {
+    search[key] = extraSearch[key];
+  });
   search.form_data = JSON.stringify(formData);
   if (endpointType === 'standalone') {
     search.standalone = 'true';
   }
-  return uri.directory(directory).search(search).toString();
+  const url = uri.directory(directory).search(search).toString();
+  if (!allowOverflow && url.length > MAX_URL_LENGTH) {
+    const minimalFormData = {
+      datasource: formData.datasource,
+      viz_type: formData.viz_type,
+    };
+    return getExploreLongUrl(
+      minimalFormData, endpointType, false, { URL_IS_TOO_LONG_TO_SHARE: null 
});
+  }
+  return url;
 }
 
 export function getExploreUrlAndPayload({


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to