superset-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-superset] nytai commented on a change in pull request #10745: feat: add/edit database modal form sections UI
Date Thu, 10 Sep 2020 21:46:28 GMT

nytai commented on a change in pull request #10745:
URL: https://github.com/apache/incubator-superset/pull/10745#discussion_r486649397



##########
File path: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx
##########
@@ -81,53 +120,165 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
   show,
   database = null,
 }) => {
-  // const [disableSave, setDisableSave] = useState(true);
-  const [disableSave] = useState<boolean>(true);
-  const [db, setDB] = useState<Partial<DatabaseObject> | null>(null);
+  const [disableSave, setDisableSave] = useState<boolean>(true);
+  const [db, setDB] = useState<DatabaseObject | null>(null);
   const [isHidden, setIsHidden] = useState<boolean>(true);
 
+  const isEditMode = database !== null;
+
+  // Database fetch logic
+  const {
+    state: { loading: dbLoading, resource: dbFetched },
+    fetchResource,
+    createResource,
+    updateResource,
+  } = useSingleViewResource<DatabaseObject>(
+    'database',
+    t('database'),
+    addDangerToast,
+  );
+
+  // Test Connection logic
+  const testConnection = () => {
+    if (!db || !db.sqlalchemy_uri || !db.sqlalchemy_uri.length) {
+      addDangerToast(t('Please enter a SQLAlchemy URI to test'));
+      return;
+    }
+
+    const connection = {
+      sqlalchemy_uri: db ? db.sqlalchemy_uri : '',
+      database_name:
+        db && db.database_name.length ? db.database_name : undefined,
+      impersonate_user: db ? db.impersonate_user || undefined : undefined,
+      extra: db && db.extra && db.extra.length ? db.extra : undefined,
+      encrypted_extra: db ? db.encrypted_extra || undefined : undefined,
+      server_cert: db ? db.server_cert || undefined : undefined,
+    };
+
+    // TODO: add response logic once endpoint is up
+    SupersetClient.post({
+      endpoint: 'api/v1/database/test_connection',
+      body: JSON.stringify(connection),

Review comment:
       I think if you use `postPayload` instead of body you won't have to add the `Content-Type`
header. 
   
   eg, https://github.com/preset-io/incubator-superset/blob/master/superset-frontend/src/dashboard/actions/dashboardState.js#L191




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


Mime
View raw message