From 6e1971aed169b2209c4c932321eb1239972429cc Mon Sep 17 00:00:00 2001 From: hughhhh Date: Fri, 7 Oct 2022 17:45:06 -0400 Subject: [PATCH 1/2] 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 434b9d1a6d7fe..c4491dbb9943d 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 49dce7d080001..759810e48e73a 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) => { + 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( null, @@ -676,7 +691,7 @@ export function useDatabaseValidation() { (database: Partial | 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(() => { From 1d4554c3e40f87b75fca8aa0037b21516da6ed83 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Fri, 7 Oct 2022 18:11:09 -0400 Subject: [PATCH 2/2] linting --- superset-frontend/src/views/CRUD/hooks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index 759810e48e73a..18d87e600dee0 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -668,8 +668,8 @@ export function useAvailableDatabases() { return [availableDbs, getAvailable] as const; } -const transformDB = (db: Partial) => { - if (Array.isArray(db.catalog)) { +const transformDB = (db: Partial | null) => { + if (db && Array.isArray(db?.catalog)) { return { ...db, catalog: Object.assign(