justinpark commented on code in PR #26391:
URL: https://github.com/apache/superset/pull/26391#discussion_r1439663162


##########
superset-frontend/src/pages/ExportGoogleSheets/index.tsx:
##########
@@ -0,0 +1,76 @@
+/**

Review Comment:
   This blank page appears to be superfluous. It might be more efficient to 
incorporate this logic within the SQL Lab page and only display the page for 
the Google Sheets link if the operation is successful.



##########
superset-frontend/src/SqlLab/components/ResultSet/index.tsx:
##########
@@ -283,10 +320,15 @@ const ResultSet = ({
                 onClick={createExploreResultsOnClick}
               />
             )}
-            {csv && (
-              <Button buttonSize="small" href={getExportCsvUrl(query.id)}>
-                <i className="fa fa-file-text-o" /> {t('Download to CSV')}
-              </Button>
+            {hasExports && (
+              <AntdDropdown overlay={ExportMenu}>
+                <Button>
+                  <Space>
+                    Export

Review Comment:
   ```suggestion
                       {t('Export')}
   ```



##########
superset-frontend/src/pages/ExportGoogleSheets/index.tsx:
##########
@@ -0,0 +1,76 @@
+/**
+ * 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, t } from '@superset-ui/core';
+import React, { useEffect, useState } from 'react';
+import { useDispatch } from 'react-redux';
+import { useParams } from 'react-router-dom';
+import Loading from 'src/components/Loading';
+import {
+  addDangerToast,
+  addInfoToast,
+} from 'src/components/MessageToasts/actions';
+
+export default function ExportGoogleSheets() {
+  const { clientId }: any = useParams();
+  const dispatch = useDispatch();
+  const [{ isLoading, data, error }, setState] = useState<{
+    isLoading: boolean;
+    data: any;
+    error: any;
+  }>({ isLoading: true, data: null, error: null });
+  useEffect(() => {
+    if (!dispatch || !clientId) {
+      return;
+    }
+    dispatch(
+      addInfoToast(t('Exporting results to Google Sheets'), { duration: 0 }),
+    );
+    SupersetClient.get({
+      endpoint: `/api/v1/sqllab/export/${clientId}/google-sheets/`,
+    })
+      .then(res => setState({ data: res.json, isLoading: false, error: null }))
+      .catch(e => setState({ data: null, isLoading: false, error: e }));
+  }, [dispatch, clientId]);

Review Comment:
   You can simplify this logic by using 
[rdk-query](https://redux-toolkit.js.org/tutorials/rtk-query).
   
   ```suggestion
   const gSheetApi = api.injectEndpoints({
     endpoints: builder => ({
       export: builder.query({
         query: ({ clientId }) => ({
           endpoint: `/api/v1/sqllab/export/${clientId}/google-sheets/`,
           transformResponse: ({ json }) => json,
         })
       }),
     }),
   });
   export const { useExportQuery } = gSheetApi;
   
   ```



##########
superset-frontend/src/views/routes.tsx:
##########
@@ -245,6 +252,12 @@ if (isFeatureEnabled(FeatureFlag.TAGGING_SYSTEM)) {
     Component: Tags,
   });
 }
+if (isFeatureEnabled(FeatureFlag.GOOGLE_SHEETS_EXPORT)) {
+  routes.push({
+    path: '/export/:clientId/google-sheets/',
+    Component: ExportGoogleSheets,
+  });
+}

Review Comment:
   ```suggestion
   ```



##########
superset-frontend/src/views/routes.tsx:
##########
@@ -127,6 +127,13 @@ const Profile = lazy(
   () => import(/* webpackChunkName: "Profile" */ 'src/pages/Profile'),
 );
 
+const ExportGoogleSheets = lazy(
+  () =>
+    import(
+      /* webpackChunkName: "ExportGoogleSheets" */ 
'src/pages/ExportGoogleSheets'
+    ),
+);
+

Review Comment:
   ```suggestion
   ```



##########
superset-frontend/src/SqlLab/components/ResultSet/index.tsx:
##########
@@ -264,6 +272,35 @@ const ResultSet = ({
         schema: query?.schema,
       };
 
+      // Antd >= 4.24.0 format:
+      const exportMenuItems = [];
+      exportMenuItems.push({
+        label: t('CSV'),
+        key: 'csv',
+        icon: <Icons.FileOutlined />,
+        onClick: () =>
+          window.open(getExportCsvUrl(query.id), '_blank')?.focus(),
+      });
+      if (isFeatureEnabled(FeatureFlag.GOOGLE_SHEETS_EXPORT)) {
+        exportMenuItems.push({
+          label: t('Google Sheets'),
+          key: 'google-sheets',
+          icon: <Icons.GoogleOutlined />,
+          onClick: () =>
+            window.open(getExportGoogleSheetsUrl(query.id), '_blank')?.focus(),

Review Comment:
   This onClick handler should have the logic for gSheetApi request.
   ```suggestion
        const [trigger, { data, isLoading, isError }] = useLazyExportQuery();
        ---
        onClick: () => trigger({ clientId: getExportGoogleSheetsUrl(query.id) 
}),
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to