Skip to content

Commit

Permalink
fix: Gsheets takes 2 clicks to save (#21740)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored Oct 7, 2022
1 parent 0c46149 commit aef6217
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions superset-frontend/src/types/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export default interface Database {
impersonate_user: boolean;
server_cert: string;
sqlalchemy_uri: string;
catalog: object;
}
17 changes: 16 additions & 1 deletion superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,21 @@ export function useAvailableDatabases() {
return [availableDbs, getAvailable] as const;
}

const transformDB = (db: Partial<DatabaseObject> | 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<JsonObject | null>(
null,
Expand All @@ -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(() => {
Expand Down

0 comments on commit aef6217

Please sign in to comment.