Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Display Error Messages in DB Connection Modal #22200

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions superset-frontend/src/components/ErrorMessage/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function ErrorAlert({
{description && (
<div className="error-body">
<p>{description}</p>
{!isExpandable && body && (
{!isExpandable && (
<span
role="button"
tabIndex={0}
Expand Down Expand Up @@ -213,7 +213,10 @@ export default function ErrorAlert({
>
<>
<p>{subtitle}</p>
<br />
{/* This break was in the original design of the modal but
the spacing looks really off if there is only
subtitle or a body */}
{subtitle && body && <br />}
{body}
</>
</ErrorModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,10 +1372,14 @@ describe('DatabaseModal', () => {
test('Error displays when it is a string', async () => {
const step2of3text = screen.getByText(/step 2 of 3/i);
const errorTitleMessage = screen.getByText(/Database Creation Error/i);
const button = screen.getByText('See more');
userEvent.click(button);
const errorMessage = screen.getByText(/Test Error With String/i);
expect(errorMessage).toBeVisible();
const closeButton = screen.getByText('Close');
userEvent.click(closeButton);
expect(step2of3text).toBeVisible();
expect(errorTitleMessage).toBeVisible();
expect(errorMessage).toBeVisible();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,23 +1156,26 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
: typeof dbErrors === 'string'
? [dbErrors]
: [];
} else if (!isEmpty(validationErrors)) {
alertErrors =
validationErrors?.error_type === 'GENERIC_DB_ENGINE_ERROR'
? [
'We are unable to connect to your database. Click "See more" for database-provided information that may help troubleshoot the issue.',
]
: [];
} else if (
!isEmpty(validationErrors) &&
validationErrors?.error_type === 'GENERIC_DB_ENGINE_ERROR'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amended to this @eschutho

) {
alertErrors = [
validationErrors?.description || validationErrors?.message,
];
}

if (alertErrors.length) {
return (
<ErrorMessageWithStackTrace
title={t('Database Creation Error')}
description={alertErrors[0]}
subtitle={validationErrors?.description}
copyText={validationErrors?.description}
/>
<ErrorAlertContainer>
<ErrorMessageWithStackTrace
title={t('Database Creation Error')}
description={t(
'We are unable to connect to your database. Click "See more" for database-provided information that may help troubleshoot the issue.',
)}
subtitle={alertErrors?.[0] || validationErrors?.description}
copyText={validationErrors?.description}
/>
</ErrorAlertContainer>
);
}
return <></>;
Expand Down Expand Up @@ -1479,6 +1482,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
/>
</StyledAlertMargin>
)}
{showDBError && errorAlert()}
</Tabs.TabPane>
<Tabs.TabPane tab={<span>{t('Advanced')}</span>} key="2">
<ExtraOptions
Expand Down Expand Up @@ -1512,9 +1516,6 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
onChange(ActionType.extraEditorChange, payload);
}}
/>
{showDBError && (
<ErrorAlertContainer>{errorAlert()}</ErrorAlertContainer>
)}
</Tabs.TabPane>
</TabsStyled>
</Modal>
Expand Down Expand Up @@ -1676,9 +1677,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
)}
</div>
{/* Step 2 */}
{showDBError && (
<ErrorAlertContainer>{errorAlert()}</ErrorAlertContainer>
)}
{showDBError && errorAlert()}
</>
))}
</>
Expand Down