mirror of https://github.com/apache/superset.git
chore: simplify error messaging in database modal (#19165)
* testing for dbconn modal error message * remove consoles and error alert mapping * lint fix * update url message * add modal fix * update comments * fix err msg bugs * fix pylint * fix line * fix tests * fix assertions
This commit is contained in:
parent
fa680369ea
commit
ad715429f9
|
@ -34,7 +34,6 @@ export const TableCatalog = ({
|
|||
}: FieldPropTypes) => {
|
||||
const tableCatalog = db?.catalog || [];
|
||||
const catalogError = validationErrors || {};
|
||||
|
||||
return (
|
||||
<StyledCatalogTable>
|
||||
<h4 className="gsheet-title">
|
||||
|
|
|
@ -96,49 +96,6 @@ const engineSpecificAlertMapping = {
|
|||
},
|
||||
};
|
||||
|
||||
const errorAlertMapping = {
|
||||
GENERIC_DB_ENGINE_ERROR: {
|
||||
message: t('Generic database engine error'),
|
||||
},
|
||||
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',
|
||||
),
|
||||
},
|
||||
};
|
||||
const googleSheetConnectionEngine = 'gsheets';
|
||||
|
||||
interface DatabaseModalProps {
|
||||
|
@ -227,7 +184,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) {
|
||||
|
@ -576,8 +533,8 @@ 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)) || errors) {
|
||||
return;
|
||||
}
|
||||
const parameters_schema = isEditMode
|
||||
|
@ -679,7 +636,6 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
|||
passwords,
|
||||
confirmedOverwrite,
|
||||
);
|
||||
|
||||
if (dbId) {
|
||||
onClose();
|
||||
addSuccessToast(t('Database connected'));
|
||||
|
@ -1112,44 +1068,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 ||
|
||||
validationErrors?.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 = () => {
|
||||
|
|
|
@ -777,6 +777,7 @@ export function useDatabaseValidation() {
|
|||
{},
|
||||
);
|
||||
setValidationErrors(parsedErrors);
|
||||
return parsedErrors;
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -216,7 +216,11 @@ class GSheetsEngineSpec(SqliteEngineSpec):
|
|||
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}},
|
||||
|
|
|
@ -76,7 +76,11 @@ def test_validate_parameters_catalog(
|
|||
|
||||
assert errors == [
|
||||
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={
|
||||
|
@ -97,7 +101,11 @@ def test_validate_parameters_catalog(
|
|||
},
|
||||
),
|
||||
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={
|
||||
|
@ -158,7 +166,11 @@ def test_validate_parameters_catalog_and_credentials(
|
|||
errors = GSheetsEngineSpec.validate_parameters(parameters) # ignore: type
|
||||
assert errors == [
|
||||
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={
|
||||
|
|
Loading…
Reference in New Issue