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 e951350  saving this for now
e951350 is described below

commit e9513502f5cb61ebfdefc33e534a9f0acce081e3
Author: hughhhh <[email protected]>
AuthorDate: Mon Jul 19 18:36:57 2021 -0400

    saving this for now
---
 .../DatabaseModal/DatabaseConnectionForm.tsx       | 50 +++++++++++-----------
 .../CRUD/data/database/DatabaseModal/index.tsx     | 48 ++++++++++++++++++---
 .../src/views/CRUD/data/database/types.ts          |  2 +-
 superset/db_engine_specs/gsheets.py                |  2 -
 4 files changed, 70 insertions(+), 32 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 e750fe8..847424c 100644
--- 
a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
+++ 
b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
@@ -60,7 +60,10 @@ interface FieldPropTypes {
   onParametersUploadFileChange: (value: any) => string;
   changeMethods: { onParametersChange: (value: any) => string } & {
     onChange: (value: any) => string;
-  } & { onParametersUploadFileChange: (value: any) => string };
+  } & { onParametersUploadFileChange: (value: any) => string } & {
+    onAddTableCatalog: () => void;
+    onRemoveTableCatalog: (value: number) => void;
+  };
   validationErrors: JsonObject | null;
   getValidation: () => void;
   db?: DatabaseObject;
@@ -197,10 +200,10 @@ const TableCatalog = ({
   isEditMode,
   getValidation,
   validationErrors,
+  db,
 }: FieldPropTypes) => {
-  const [tableCatalog, setTableCatalog] = useState<Record<string, string>>([
-    {},
-  ]);
+  const tableCatalog = db.catalog
+  console.log(tableCatalog);
   return (
     <div>
       <>
@@ -212,50 +215,43 @@ const TableCatalog = ({
         </Select>
       </>
       <>
-        {tableCatalog.map(sheet => (
+        {tableCatalog.map((sheet, idx) => (
           <>
             <Input
-              name="table-catalog-name-1"
+              name={`table-catalog-name-${idx}`}
               placeholder="Enter create a name for this sheet"
               onChange={e => {
-                console.log(e.target.value);
-                setTableCatalog([{ name: `table-catalog-${e.target.value}` }]);
+                tableCatalog[idx].name = e.target.value;
               }}
+              value={sheet.name}
+            />
+            <CloseOutlined
+              onClick={() => changeMethods.onRemoveTableCatalog(idx)}
             />
-            {/* <CloseOutlined
-              onClick={() => {
-                const index = tableCatalog.indexOf(sheet);
-                console.log(index)
-                if (index > -1) {
-                  tableCatalog.splice(index, 1);
-                  console.log(tableCatalog);
-                  setTableCatalog(tableCatalog);
-                }
-              }}
-            /> */}
             <ValidatedInput
               name={sheet.name}
-              type="gsheet"
               required={required}
               validationMethods={{ onBlur: getValidation }}
               errorMessage={validationErrors?.table_catalog}
               placeholder="Paste the shareable Google Sheet URL here"
               onChange={changeMethods.onParametersChange}
               onPaste={e => {
+                const sheetUrl = e.clipboardData.getData('Text');
+                tableCatalog[idx].value = sheetUrl;
                 changeMethods.onParametersChange({
                   target: {
-                    name: 'table-catalog-value-1',
-                    value: e.clipboardData.getData('Text'),
+                    name: sheet.name,
+                    value: sheetUrl,
                   },
                 });
               }}
+              value={sheet.value}
             />
           </>
         ))}
         <StyledFooterButton
           onClick={() => {
-            console.log('add button');
-            setTableCatalog([...tableCatalog, {}]);
+            changeMethods.onAddTableCatalog();
           }}
         >
           Add sheet
@@ -474,6 +470,8 @@ const DatabaseConnectionForm = ({
   onParametersChange,
   onChange,
   onParametersUploadFileChange,
+  onAddTableCatalog,
+  onRemoveTableCatalog,
   validationErrors,
   getValidation,
   db,
@@ -499,6 +497,8 @@ const DatabaseConnectionForm = ({
   onParametersUploadFileChange?: (
     event: FormEvent<InputProps> | { target: HTMLInputElement },
   ) => void;
+  onAddTableCatalog: () => void;
+  onRemoveTableCatalog: () => void;
   validationErrors: JsonObject | null;
   getValidation: () => void;
 }) => (
@@ -522,6 +522,8 @@ const DatabaseConnectionForm = ({
               onParametersChange,
               onChange,
               onParametersUploadFileChange,
+              onAddTableCatalog,
+              onRemoveTableCatalog,
             },
             validationErrors,
             getValidation,
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 65105aa..83316d9 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
@@ -126,6 +126,8 @@ enum ActionType {
   textChange,
   extraInputChange,
   extraEditorChange,
+  addTableCatalogSheet,
+  removeTableCatalogSheet,
 }
 
 interface DBReducerPayloadType {
@@ -161,7 +163,13 @@ type DBReducerActionType =
       };
     }
   | {
-      type: ActionType.reset;
+      type: ActionType.reset | ActionType.addTableCatalogSheet;
+    }
+  | {
+      type: ActionType.removeTableCatalogSheet;
+      payload: {
+        indexToDelete: number;
+      };
     }
   | {
       type: ActionType.configMethodChange;
@@ -181,6 +189,7 @@ function dbReducer(
   };
   let query = '';
 
+  console.log(action);
   switch (action.type) {
     case ActionType.extraEditorChange:
       return {
@@ -228,20 +237,19 @@ function dbReducer(
         [action.payload.name]: action.payload.value,
       };
     case ActionType.parametersChange:
-      if (action.payload.name.startsWith('table-catalog')) {
+      if (true) { // todo: find condition to make the valide for googke sheets 
only
         // formatting wrapping google sheets table catalog
         return {
           ...trimmedState,
           parameters: {
             ...trimmedState.parameters,
             catalog: {
-              ...trimmedState.parameters?.table_catalog,
+              ...trimmedState.parameters?.catalog,
               [action.payload.name.substring(14)]: action.payload.value, // 
removing table-catalog from key
             },
           },
         };
       }
-
       return {
         ...trimmedState,
         parameters: {
@@ -249,6 +257,22 @@ function dbReducer(
           [action.payload.name]: action.payload.value,
         },
       };
+    case ActionType.addTableCatalogSheet:
+      if (trimmedState.catalog !== undefined) {
+        return {
+          ...trimmedState,
+          catalog: [...trimmedState.catalog, {}],
+        };
+      }
+      return {
+        ...trimmedState,
+        catalog: [{}],
+      };
+    case ActionType.removeTableCatalogSheet:
+      trimmedState.catalog.splice(action.payload.indexToDelete, 1);
+      return {
+        ...trimmedState,
+      };
     case ActionType.editorChange:
       return {
         ...trimmedState,
@@ -572,6 +596,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> 
= ({
         engine,
       },
     });
+    setDB({ type: ActionType.addTableCatalogSheet });
   };
 
   const renderAvailableSelector = () => (
@@ -845,6 +870,9 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> 
= ({
             value: target.value,
           })
         }
+        onAddTableCatalog={() => {
+          console.log('hello');
+        }}
         getValidation={() => getValidation(db)}
         validationErrors={validationErrors}
       />
@@ -1061,7 +1089,7 @@ const DatabaseModal: 
FunctionComponent<DatabaseModalProps> = ({
         </>
       ) : (
         <>
-          {/* Step 1 */}
+          {/* Dyanmic Form Step 1 */}
           {!isLoading &&
             (!db ? (
               <SelectDatabaseStyles>
@@ -1106,6 +1134,16 @@ const DatabaseModal: 
FunctionComponent<DatabaseModalProps> = ({
                   isPublic={isPublic}
                   sslForced={sslForced}
                   dbModel={dbModel}
+                  onAddTableCatalog={() => {
+                    console.log('hey');
+                    setDB({ type: ActionType.addTableCatalogSheet });
+                  }}
+                  onRemoveTableCatalog={idx => {
+                    setDB({
+                      type: ActionType.removeTableCatalogSheet,
+                      payload: { indexToDelete: idx },
+                    });
+                  }}
                   onParametersChange={({
                     target,
                   }: {
diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts 
b/superset-frontend/src/views/CRUD/data/database/types.ts
index aa87fa9..d20c9cb 100644
--- a/superset-frontend/src/views/CRUD/data/database/types.ts
+++ b/superset-frontend/src/views/CRUD/data/database/types.ts
@@ -41,7 +41,7 @@ export type DatabaseObject = {
     encryption?: boolean;
     credentials_info?: string;
     query?: string | object;
-    table_catalog?: object;
+    catalog?: [];
   };
   configuration_method: CONFIGURATION_METHOD;
   engine?: string;
diff --git a/superset/db_engine_specs/gsheets.py 
b/superset/db_engine_specs/gsheets.py
index 38bd1c0..bc183da 100644
--- a/superset/db_engine_specs/gsheets.py
+++ b/superset/db_engine_specs/gsheets.py
@@ -45,12 +45,10 @@ ma_plugin = MarshmallowPlugin()
 
 class GSheetsParametersSchema(Schema):
     catalog = fields.Dict(required=False)
-    query = fields.Dict(required=False)
 
 
 class GSheetsParametersType(TypedDict):
     credentials_info: Dict[str, Any]
-    query: Dict[str, Any]
     table_catalog: Dict[str, str]
 
 

Reply via email to