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 2022/01/28 12:12:40 UTC

[GitHub] [superset] villebro commented on a change in pull request #18181: fix: Explore long URL problem

villebro commented on a change in pull request #18181:
URL: https://github.com/apache/superset/pull/18181#discussion_r794438875



##########
File path: superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx
##########
@@ -70,24 +74,37 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
     return `${newUrl.pathname}${newUrl.search}`;
   }
 
+  async function generateUrl() {
+    if (formData) {
+      const key = await postFormData(
+        parseInt(formData.datasource.split('_')[0], 10),
+        formData.slice_id,
+        formData,
+      );
+      return `${window.location.origin}${mountExploreUrl(null, {
+        [URL_PARAMS.formDataKey.name]: key,
+      })}`;
+    }
+    const copyUrl = await getCopyUrl();
+    return getShortUrl(copyUrl);
+  }
+
   async function onCopyLink() {
     try {
-      const copyUrl = await getCopyUrl();
-      const shortUrl = await getShortUrl(copyUrl);
-      await copyTextToClipboard(shortUrl);
+      await copyTextToClipboard(await generateUrl());

Review comment:
       nit: we may want to emit a different error when `generateUrl` fails. Now, we would get the toast "'Sorry, your browser does not support copying."

##########
File path: superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx
##########
@@ -70,24 +74,37 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
     return `${newUrl.pathname}${newUrl.search}`;
   }
 
+  async function generateUrl() {
+    if (formData) {
+      const key = await postFormData(
+        parseInt(formData.datasource.split('_')[0], 10),
+        formData.slice_id,
+        formData,
+      );
+      return `${window.location.origin}${mountExploreUrl(null, {
+        [URL_PARAMS.formDataKey.name]: key,
+      })}`;
+    }
+    const copyUrl = await getCopyUrl();
+    return getShortUrl(copyUrl);
+  }
+
   async function onCopyLink() {
     try {
-      const copyUrl = await getCopyUrl();
-      const shortUrl = await getShortUrl(copyUrl);
-      await copyTextToClipboard(shortUrl);
+      await copyTextToClipboard(await generateUrl());
       addSuccessToast(t('Copied to clipboard!'));
     } catch (error) {
+      logging.error(error);
       addDangerToast(t('Sorry, your browser does not support copying.'));
     }
   }
 
   async function onShareByEmail() {
     try {
-      const copyUrl = await getCopyUrl();
-      const shortUrl = await getShortUrl(copyUrl);
-      const bodyWithLink = `${emailBody}${shortUrl}`;
+      const bodyWithLink = `${emailBody}${await generateUrl()}`;
       window.location.href = `mailto:?Subject=${emailSubject}%20&Body=${bodyWithLink}`;
     } catch (error) {
+      logging.error(error);

Review comment:
       similar to the above comment, maybe we could standardize on the errors here. If we just have one error, the one below is probably more appropriate as a catch-all error message.

##########
File path: superset-frontend/src/explore/exploreUtils/formData.ts
##########
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { SupersetClient, JsonObject } from '@superset-ui/core';
+
+export const postFormData = (
+  datasetId: number,
+  chartId: number,

Review comment:
       Should we make this optional and leave it out if it's undefined?

##########
File path: superset-frontend/src/explore/components/ExploreViewContainer/index.jsx
##########
@@ -191,36 +193,38 @@ function ExploreViewContainer(props) {
   };
 
   const addHistory = useCallback(
-    ({ isReplace = false, title } = {}) => {
+    async ({ isReplace = false, title } = {}) => {
       const formData = props.dashboardId
         ? {
             ...props.form_data,
             dashboardId: props.dashboardId,
           }
         : props.form_data;
       const payload = { ...formData };
-      const longUrl = getExploreLongUrl(
-        formData,
-        props.standalone ? URL_PARAMS.standalone.name : null,
-        false,
-        {},
-        props.force,
-      );
+      const chartId = formData.slice_id || 0;

Review comment:
       very minor thought, but I'd prefer to leave it `undefined` if the chart hasn't yet been saved.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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