This is an automated email from the ASF dual-hosted git repository. hugh pushed a commit to branch hugh/validate-edit in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4f2def6f5939656118a0ed43d9a10d24f3999ce5 Author: hughhhh <[email protected]> AuthorDate: Tue Jun 22 17:22:19 2021 -0400 temp working validation --- .../src/views/CRUD/data/database/DatabaseModal/index.tsx | 10 +++++++++- superset-frontend/src/views/CRUD/hooks.ts | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) 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 cdefb58..4f5ab53 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -255,7 +255,7 @@ function dbReducer( return { ...action.payload, - engine: trimmedState.engine, + engine: action.payload.backend, configuration_method: action.payload.configuration_method, extra_json: deserializeExtraJSON, parameters: { @@ -364,6 +364,14 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ // Clone DB object const dbToUpdate = JSON.parse(JSON.stringify(update)); + + // Validtion DB + await getValidation(dbToUpdate, true); + if (validationErrors) { + console.log('got validation errors'); + return; + } + if (dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM) { if (dbToUpdate?.parameters?.query) { // convert query params into dictionary diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index 3132422..b51ff52 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -638,7 +638,7 @@ export function useDatabaseValidation() { null, ); const getValidation = useCallback( - (database: Partial<DatabaseObject> | null) => { + (database: Partial<DatabaseObject> | null, onCreate = false) => { SupersetClient.post({ endpoint: '/api/v1/database/validate_parameters', body: JSON.stringify(database), @@ -653,7 +653,8 @@ export function useDatabaseValidation() { const parsedErrors = errors .filter( (error: { error_type: string }) => - error.error_type !== 'CONNECTION_MISSING_PARAMETERS_ERROR', + error.error_type !== + 'CONNECTION_MISSING_PARAMETERS_ERROR' || onCreate, ) .reduce( ( @@ -662,7 +663,7 @@ export function useDatabaseValidation() { extra, message, }: { - extra: { invalid?: string[] }; + extra: { invalid?: string[]; missing?: string[] }; message: string; }, ) => { @@ -672,10 +673,18 @@ export function useDatabaseValidation() { if (extra.invalid) { return { ...obj, [extra.invalid[0]]: message }; } + if (extra.missing) { + const missingFields = {}; + extra.missing.map(d => { + missingFields[d] = 'This is a required field'; + }); + return { ...obj, ...missingFields }; + } return obj; }, {}, ); + console.log(parsedErrors); setValidationErrors(parsedErrors); }); } else {
