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 2021/06/14 07:27:56 UTC

[GitHub] [superset] betodealmeida commented on a change in pull request #15107: feat: show spinner on exports

betodealmeida commented on a change in pull request #15107:
URL: https://github.com/apache/superset/pull/15107#discussion_r650190972



##########
File path: superset-frontend/src/utils/export.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 parseCookie from 'src/utils/parseCookie';
+import rison from 'rison';
+import shortid from 'shortid';
+
+export default function handleResourceExport(
+  resource: string,
+  ids: number[],
+  done: () => void,
+  interval = 200,
+): void {
+  const token = shortid.generate();
+  const url = `/api/v1/${resource}/export/?q=${rison.encode(
+    ids,
+  )}&token=${token}`;
+
+  // create new iframe for export
+  const iframe = document.createElement('iframe');
+  iframe.style.display = 'none';

Review comment:
       I don't, once the export response finishes a "Save file" dialog pops up automatically even if the iframe is hidden.

##########
File path: superset-frontend/src/utils/export.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 parseCookie from 'src/utils/parseCookie';
+import rison from 'rison';
+import shortid from 'shortid';
+
+export default function handleResourceExport(
+  resource: string,
+  ids: number[],
+  done: () => void,
+  interval = 200,
+): void {
+  const token = shortid.generate();
+  const url = `/api/v1/${resource}/export/?q=${rison.encode(
+    ids,
+  )}&token=${token}`;
+
+  // create new iframe for export
+  const iframe = document.createElement('iframe');
+  iframe.style.display = 'none';
+  iframe.src = url;
+  document.body.appendChild(iframe);
+
+  const timer = window.setInterval(() => {
+    const cookie = parseCookie();

Review comment:
       The type is `CookieMap`, defined in `parseCookie.ts`. Do you mean making it explicit here?

##########
File path: superset/charts/api.py
##########
@@ -918,12 +919,15 @@ def export(self, **kwargs: Any) -> Response:
                 return self.response_404()
         buf.seek(0)
 
-        return send_file(
+        response = send_file(
             buf,
             mimetype="application/zip",
             as_attachment=True,
             attachment_filename=filename,
         )
+        if token:
+            response.set_cookie(token, "done", max_age=600)

Review comment:
       Right, I set it here with an expiration of 5 minutes so we don't need to delete the cookie. Each export has a unique token for the cookie name, so users can do multiple exports at the same time.

##########
File path: superset-frontend/src/views/CRUD/dashboard/DashboardList.tsx
##########
@@ -170,6 +172,14 @@ function DashboardList(props: DashboardListProps) {
     );
   }
 
+  const handleBulkDashboardExport = (dashboardsToExport: Dashboard[]) => {
+    const ids = dashboardsToExport.map(({ id }) => id);
+    handleResourceExport('chart', ids, () => {

Review comment:
       Ouch, good catch!

##########
File path: superset-frontend/src/views/CRUD/data/savedquery/SavedQueryList.tsx
##########
@@ -238,6 +240,16 @@ function SavedQueryList({
     );
   };
 
+  const handleBulkSavedQueryExport = (
+    savedQueriesToExport: SavedQueryObject[],
+  ) => {
+    const ids = savedQueriesToExport.map(({ id }) => id);
+    handleResourceExport('chart', ids, () => {

Review comment:
       Too much copy-and-paste :(




-- 
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.

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