add validation error to bottom alert
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 @@
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 @@
onChange(ActionType.extraEditorChange, payload);
}}
/>
- {dbError && errorAlert()}
+ {validationErrors && errorAlert()}
</Tabs.TabPane>
</Tabs>
</Modal>
@@ -1021,7 +1055,7 @@
/>
</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 @@
(
obj: {},
{
+ error_type,
extra,
message,
}: {
+ error_type: string;
extra: { invalid?: string[]; missing?: string[] };
message: string;
},
@@ -671,11 +673,16 @@
// 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 => ({