This is an automated email from the ASF dual-hosted git repository. hugh pushed a commit to branch hugh/add-validation-to-alerts in repository https://gitbox.apache.org/repos/asf/superset.git
commit 13db62b2915e9b8e6a471c61e61766a4ca095c5c Author: hughhhh <[email protected]> AuthorDate: Wed Jun 23 16:35:33 2021 -0400 add validation error to bottom alert --- .../CRUD/data/database/DatabaseModal/index.tsx | 56 +++++++++++++++++----- superset-frontend/src/views/CRUD/hooks.ts | 9 +++- 2 files changed, 53 insertions(+), 12 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 9eae554..0854724 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -650,15 +650,49 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ setTabKey(key); }; - const errorAlert = () => ( - <Alert - type="error" - css={(theme: SupersetTheme) => antDErrorAlertStyles(theme)} - message="Missing Required Fields" - description="Please complete all required fields." - showIcon - /> - ); + const errorAlert = () => { + const errorAlertMapping = { + CONNECTION_MISSING_PARAMETERS_ERROR: { + message: 'Missing Required Fields', + description: 'Please complete all required fields.', + }, + CONNECTION_INVALID_HOSTNAME_ERROR: { + message: 'Could not verify the host', + description: + 'The host is invalid. Please verify that this field is entered correctly.', + }, + CONNECTION_PORT_CLOSED_ERROR: { + message: 'Port is closed', + description: 'Please verify that port is open to connect.', + }, + }; + + if ( + validationErrors && + Object.keys(validationErrors).length === 0 && + validationErrors.constructor === Object && + !(validationErrors.error_type in errorAlertMapping) + ) { + return <></>; + } + + return ( + <Alert + type="error" + css={(theme: SupersetTheme) => antDErrorAlertStyles(theme)} + message={ + errorAlertMapping[validationErrors?.error_type]?.message || + validationErrors?.error_type + } + description={ + errorAlertMapping[validationErrors?.error_type]?.description || + JSON.stringify(validationErrors) + } + showIcon + closable={false} + /> + ); + }; const renderFinishState = () => { if (!editNewDb) { @@ -895,7 +929,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ onChange(ActionType.extraEditorChange, payload); }} /> - {dbError && errorAlert()} + {validationErrors && errorAlert()} </Tabs.TabPane> </Tabs> </Modal> @@ -1021,7 +1055,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ /> </div> {/* Step 2 */} - {dbError && errorAlert()} + {validationErrors && errorAlert()} </> ))} </> diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index bd8e19c..42aae83 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -660,9 +660,11 @@ export function useDatabaseValidation() { ( obj: {}, { + error_type, extra, message, }: { + error_type: string; extra: { invalid?: string[]; missing?: string[] }; message: string; }, @@ -671,11 +673,16 @@ export function useDatabaseValidation() { // error can't be mapped to a parameter // so leave it alone if (extra.invalid) { - return { ...obj, [extra.invalid[0]]: message }; + return { + ...obj, + [extra.invalid[0]]: message, + error_type, + }; } if (extra.missing) { return { ...obj, + error_type, ...Object.assign( {}, ...extra.missing.map(field => ({
