From aef6217a80d8b7d30120efe6502505edc01eb8d3 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Fri, 7 Oct 2022 19:40:15 -0400 Subject: [PATCH] fix: Gsheets takes 2 clicks to save (#21740) --- 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..18d87e600d 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 | null) => { + if (db && 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(() => {