You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/07/20 16:25:26 UTC

[superset] branch hugh/gsheets-public updated: working edit

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch hugh/gsheets-public
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/hugh/gsheets-public by this push:
     new 4714264  working edit
4714264 is described below

commit 4714264a76ab221d81fd49b5ef06b24db520361f
Author: hughhhh <hu...@gmail.com>
AuthorDate: Tue Jul 20 12:24:06 2021 -0400

    working edit
---
 .../DatabaseModal/DatabaseConnectionForm.tsx       | 30 ++++++++---
 .../CRUD/data/database/DatabaseModal/index.tsx     | 60 +++++++++++++++++++---
 2 files changed, 75 insertions(+), 15 deletions(-)

diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
index 847424c..86a7918 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
@@ -202,8 +202,8 @@ const TableCatalog = ({
   validationErrors,
   db,
 }: FieldPropTypes) => {
-  const tableCatalog = db.catalog
-  console.log(tableCatalog);
+  const tableCatalog = db.catalog;
+  console.log('tableCatalog', tableCatalog);
   return (
     <div>
       <>
@@ -218,10 +218,16 @@ const TableCatalog = ({
         {tableCatalog.map((sheet, idx) => (
           <>
             <Input
-              name={`table-catalog-name-${idx}`}
               placeholder="Enter create a name for this sheet"
               onChange={e => {
                 tableCatalog[idx].name = e.target.value;
+                changeMethods.onParametersChange({
+                  target: {
+                    type: `catalog-${idx}`,
+                    name: 'name',
+                    value: e.target.value,
+                  },
+                });
               }}
               value={sheet.name}
             />
@@ -234,14 +240,24 @@ const TableCatalog = ({
               validationMethods={{ onBlur: getValidation }}
               errorMessage={validationErrors?.table_catalog}
               placeholder="Paste the shareable Google Sheet URL here"
-              onChange={changeMethods.onParametersChange}
+              onChange={e => {
+                changeMethods.onParametersChange({
+                  target: {
+                    type: `catalog-${idx}`,
+                    name: 'value',
+                    value: e.target.value,
+                  },
+                });
+              }}
               onPaste={e => {
                 const sheetUrl = e.clipboardData.getData('Text');
-                tableCatalog[idx].value = sheetUrl;
                 changeMethods.onParametersChange({
                   target: {
-                    name: sheet.name,
-                    value: sheetUrl,
+                    target: {
+                      type: `catalog-${idx}`,
+                      name: 'value',
+                      value: sheetUrl,
+                    },
                   },
                 });
               }}
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
index 83316d9..d13fc5d 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
@@ -188,6 +188,8 @@ function dbReducer(
     ...(state || {}),
   };
   let query = '';
+  let deserializeExtraJSON = {};
+  let extra_json: DatabaseObject['extra_json'];
 
   console.log(action);
   switch (action.type) {
@@ -237,16 +239,26 @@ function dbReducer(
         [action.payload.name]: action.payload.value,
       };
     case ActionType.parametersChange:
-      if (true) { // todo: find condition to make the valide for googke sheets only
+      if (action.payload.type?.startsWith('catalog')) {
+        // todo: find condition to make the valide for googke sheets only
         // formatting wrapping google sheets table catalog
+        const idx = action.payload.type?.split('-')[1];
+        const catalogToUpdate = trimmedState.catalog[idx];
+        catalogToUpdate[action.payload.name] = action.payload.value;
+
+        console.log('catalog', trimmedState.catalog);
+        const paramatersCatalog = {};
+        trimmedState.catalog.map(item => {
+          paramatersCatalog[item.name] = item.value;
+        });
+
+        console.log('paramsCatalog', paramatersCatalog);
+
         return {
           ...trimmedState,
           parameters: {
             ...trimmedState.parameters,
-            catalog: {
-              ...trimmedState.parameters?.catalog,
-              [action.payload.name.substring(14)]: action.payload.value, // removing table-catalog from key
-            },
+            catalog: paramatersCatalog,
           },
         };
       }
@@ -285,10 +297,8 @@ function dbReducer(
       };
     case ActionType.fetched:
       // convert all the keys in this payload into strings
-      // eslint-disable-next-line no-case-declarations
-      let deserializeExtraJSON = {};
       if (action.payload.extra) {
-        const extra_json = {
+        extra_json = {
           ...JSON.parse(action.payload.extra || ''),
         } as DatabaseObject['extra_json'];
 
@@ -328,6 +338,30 @@ function dbReducer(
         };
       }
 
+      if (
+        action.payload.backend === 'gsheets' &&
+        action.payload.configuration_method ===
+          CONFIGURATION_METHOD.DYNAMIC_FORM
+      ) {
+        // pull catalog from engine params
+        console.log(extra_json?.engine_params);
+        const result = Object.keys(extra_json?.engine_params?.catalog).map(
+          e => {
+            const ret = {};
+            ret.name = e;
+            ret.value = extra_json?.engine_params?.catalog[e];
+            return ret;
+          },
+        );
+        return {
+          ...action.payload,
+          engine: action.payload.backend,
+          configuration_method: action.payload.configuration_method,
+          extra_json: deserializeExtraJSON,
+          catalog: result,
+        };
+      }
+
       return {
         ...action.payload,
         encrypted_extra: action.payload.encrypted_extra || '',
@@ -987,6 +1021,16 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
                   value: target.value,
                 })
               }
+              onAddTableCatalog={() => {
+                console.log('hey');
+                setDB({ type: ActionType.addTableCatalogSheet });
+              }}
+              onRemoveTableCatalog={idx => {
+                setDB({
+                  type: ActionType.removeTableCatalogSheet,
+                  payload: { indexToDelete: idx },
+                });
+              }}
               getValidation={() => getValidation(db)}
               validationErrors={validationErrors}
             />