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 2022/10/07 21:45:23 UTC
[superset] 01/01: transform db to fit payload
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch verify-catalog
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 6e1971aed169b2209c4c932321eb1239972429cc
Author: hughhhh <hu...@gmail.com>
AuthorDate: Fri Oct 7 17:45:06 2022 -0400
transform db to fit payload
---
superset-frontend/src/types/Database.ts | 1 +
superset-frontend/src/views/CRUD/hooks.ts | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/types/Database.ts b/superset-frontend/src/types/Database.ts
index 434b9d1a6d..c4491dbb99 100644
--- a/superset-frontend/src/types/Database.ts
+++ b/superset-frontend/src/types/Database.ts
@@ -26,4 +26,5 @@ export default interface Database {
impersonate_user: boolean;
server_cert: string;
sqlalchemy_uri: string;
+ catalog: object;
}
diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts
index 49dce7d080..759810e48e 100644
--- a/superset-frontend/src/views/CRUD/hooks.ts
+++ b/superset-frontend/src/views/CRUD/hooks.ts
@@ -668,6 +668,21 @@ export function useAvailableDatabases() {
return [availableDbs, getAvailable] as const;
}
+const transformDB = (db: Partial<DatabaseObject>) => {
+ if (Array.isArray(db.catalog)) {
+ return {
+ ...db,
+ catalog: Object.assign(
+ {},
+ ...db.catalog.map((x: { name: string; value: string }) => ({
+ [x.name]: x.value,
+ })),
+ ),
+ };
+ }
+ return db;
+};
+
export function useDatabaseValidation() {
const [validationErrors, setValidationErrors] = useState<JsonObject | null>(
null,
@@ -676,7 +691,7 @@ export function useDatabaseValidation() {
(database: Partial<DatabaseObject> | null, onCreate = false) =>
SupersetClient.post({
endpoint: '/api/v1/database/validate_parameters/',
- body: JSON.stringify(database),
+ body: JSON.stringify(transformDB(database)),
headers: { 'Content-Type': 'application/json' },
})
.then(() => {