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

chore: simplify error messaging in database modal #19165

Merged
merged 21 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e5b1ca2
testing for dbconn modal error message
pkdotson Mar 16, 2022
2f37f40
remove consoles and error alert mapping
pkdotson Mar 16, 2022
df138d1
lint fix
pkdotson Mar 16, 2022
6127e6d
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Mar 21, 2022
4d9cfe1
update url message
pkdotson Mar 23, 2022
2167348
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Mar 30, 2022
ce0dbb2
add modal fix
pkdotson Mar 31, 2022
66d58a5
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Mar 31, 2022
10c6771
update comments
pkdotson Apr 12, 2022
3532f33
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 12, 2022
11865ca
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 15, 2022
ddbd832
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 15, 2022
19e1f58
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 15, 2022
1c9fb78
fix err msg bugs
pkdotson Apr 16, 2022
90c9591
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 18, 2022
e08c143
fix pylint
pkdotson Apr 18, 2022
8566c56
fix line
pkdotson Apr 18, 2022
b21a488
fix tests
pkdotson Apr 18, 2022
6a95ab2
fix assertions
pkdotson Apr 18, 2022
ee1a240
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 19, 2022
37b500b
Merge branch 'master' of https://github.com/preset-io/superset into c…
pkdotson Apr 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const TableCatalog = ({
}: FieldPropTypes) => {
const tableCatalog = db?.catalog || [];
const catalogError = validationErrors || {};

Copy link
Member

Choose a reason for hiding this comment

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

nit: Could we add this space back since it is the only change in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep

return (
<StyledCatalogTable>
<h4 className="gsheet-title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,46 +88,6 @@ const engineSpecificAlertMapping = {
},
};

const errorAlertMapping = {
CONNECTION_MISSING_PARAMETERS_ERROR: {
message: t('Missing Required Fields'),
description: t('Please complete all required fields.'),
},
CONNECTION_INVALID_HOSTNAME_ERROR: {
message: t('Could not verify the host'),
description: t(
'The host is invalid. Please verify that this field is entered correctly.',
),
},
CONNECTION_PORT_CLOSED_ERROR: {
message: t('Port is closed'),
description: t('Please verify that port is open to connect.'),
},
CONNECTION_INVALID_PORT_ERROR: {
message: t('Invalid Port Number'),
description: t(
'The port must be a whole number less than or equal to 65535.',
),
},
CONNECTION_ACCESS_DENIED_ERROR: {
message: t('Invalid account information'),
description: t('Either the username or password is incorrect.'),
},
CONNECTION_INVALID_PASSWORD_ERROR: {
message: t('Invalid account information'),
description: t('Either the username or password is incorrect.'),
},
INVALID_PAYLOAD_SCHEMA_ERROR: {
message: t('Incorrect Fields'),
description: t('Please make sure all fields are filled out correctly'),
},
TABLE_DOES_NOT_EXIST_ERROR: {
message: t('URL could not be identified'),
description: t(
'The URL could not be identified. Please check for typos and make sure that "Type of google sheet allowed" selection matches the input',
),
},
};
interface DatabaseModalProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
Expand Down Expand Up @@ -214,7 +174,7 @@ function dbReducer(
};
let query = {};
let query_input = '';
let deserializeExtraJSON = { allows_virtual_table_explore: true };
let deserializeExtraJSON = {};
let extra_json: DatabaseObject['extra_json'];

switch (action.type) {
Expand Down Expand Up @@ -528,8 +488,11 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({

if (dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM) {
// Validate DB before saving
await getValidation(dbToUpdate, true);
if (validationErrors && !isEmpty(validationErrors)) {
const errors = await getValidation(dbToUpdate, true);
if (
(validationErrors && !isEmpty(validationErrors)) ||
!isEmpty(errors)
) {
return;
}
const parameters_schema = isEditMode
Expand Down Expand Up @@ -909,43 +872,21 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
);
};

// eslint-disable-next-line consistent-return
const errorAlert = () => {
if (
isEmpty(dbErrors) ||
(isEmpty(validationErrors) &&
!(validationErrors?.error_type in errorAlertMapping))
) {
return <></>;
}

if (validationErrors) {
if (isEmpty(dbErrors) === false) {
const message: Array<string> =
typeof dbErrors === 'object' ? Object.values(dbErrors) : [];
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}
message={t('Database Creation Error')}
description={message?.[0] || dbErrors}
/>
);
}
const message: Array<string> =
typeof dbErrors === 'object' ? Object.values(dbErrors) : [];
return (
<Alert
type="error"
css={(theme: SupersetTheme) => antDErrorAlertStyles(theme)}
message={t('Database Creation Error')}
description={message?.[0] || dbErrors}
/>
);
return <></>;
};

const renderFinishState = () => {
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ export function useDatabaseValidation() {
{},
);
setValidationErrors(parsedErrors);
return parsedErrors;
});
}
// eslint-disable-next-line no-console
Expand Down
2 changes: 1 addition & 1 deletion superset/db_engine_specs/gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def validate_parameters(
except Exception: # pylint: disable=broad-except
errors.append(
SupersetError(
message="URL could not be identified",
message="The URL could not be identified. Please check for typos and make sure that ‘Type of Google Sheets allowed’ selection matches the input.",
error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
level=ErrorLevel.WARNING,
extra={"catalog": {"idx": idx, "url": True}},
Expand Down