From bf0b659e781b1ff8eaa452bf137d1cbfa56b9957 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 9 Jun 2021 17:18:12 -0400 Subject: [PATCH 1/2] additional params to the DatabaseConnectionForm --- .../data/database/DatabaseModal/DatabaseConnectionForm.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx index ab073b13f36e8..14aeb32bb12e3 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -45,9 +45,9 @@ export const FormFieldOrder = [ 'username', 'password', 'database_name', + 'query', 'encryption', 'credentials_info', - 'query', ]; interface FieldPropTypes { @@ -282,10 +282,10 @@ const queryField = ({ value={db?.query} validationMethods={{ onBlur: getValidation }} errorMessage={validationErrors?.query} - placeholder="" + placeholder="e.g. additional parameters" label="Additional Parameters" onChange={changeMethods.onChange} - helpText="Pick a nickname for this database to display as in Superset." + helpText="Add additional custom parameters" /> ); From 0cfec1a3df4610a442c8512944c318c7a707015c Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 9 Jun 2021 18:55:18 -0400 Subject: [PATCH 2/2] save passing params up to api --- .../database/DatabaseModal/DatabaseConnectionForm.tsx | 2 +- .../src/views/CRUD/data/database/DatabaseModal/index.tsx | 9 +++++++++ superset-frontend/src/views/CRUD/data/database/types.ts | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx index 14aeb32bb12e3..d32299c2ed36d 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -284,7 +284,7 @@ const queryField = ({ errorMessage={validationErrors?.query} placeholder="e.g. additional parameters" label="Additional Parameters" - onChange={changeMethods.onChange} + onChange={changeMethods.onParametersChange} helpText="Add additional custom parameters" /> ); diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index 67ad8ea74a94a..e7b8e4dcf3330 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -282,6 +282,15 @@ const DatabaseModal: FunctionComponent = ({ credentials_info: JSON.parse(update.encrypted_extra), }); } + if (update.parameters.query) { + // convert query params into dictionary + update.parameters.query = JSON.parse( + `{"${decodeURI(db.parameters.query || '') + .replace(/"/g, '\\"') + .replace(/&/g, '","') + .replace(/=/g, '":"')}"}`, + ); + } const dbId = await createResource(update as DatabaseObject); if (dbId) { setHasConnectedDb(true); diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index f611dd76cea97..8c0264116da17 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -38,6 +38,7 @@ export type DatabaseObject = { username?: string; password?: string; encryption?: boolean; + query?: string; }; configuration_method: CONFIGURATION_METHOD; engine?: string;