From c992ff3be472738a34491d6e8ba8ba10167b2f8c Mon Sep 17 00:00:00 2001 From: smileydev <47900232+prosdev0107@users.noreply.github.com> Date: Wed, 6 Jul 2022 15:51:42 -0400 Subject: [PATCH] fix(import): Show the error message with db install guide when exist the importing db issue (#20573) * fix(import): make to update the error display when importing resurce * fix(import): make to update the error message --- .../src/components/ImportModal/ErrorAlert.tsx | 2 +- .../data/database/DatabaseModal/index.tsx | 42 ++++++++++++++++--- superset-frontend/src/views/CRUD/hooks.ts | 4 +- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/components/ImportModal/ErrorAlert.tsx b/superset-frontend/src/components/ImportModal/ErrorAlert.tsx index 52bd54a796188..904dced7bad54 100644 --- a/superset-frontend/src/components/ImportModal/ErrorAlert.tsx +++ b/superset-frontend/src/components/ImportModal/ErrorAlert.tsx @@ -49,7 +49,7 @@ const ErrorAlert: FunctionComponent = ({ <>
{t( - 'Database driver for importing maybe not installed. Visit the Superset documentation page for installation instructions:', + 'Database driver for importing maybe not installed. Visit the Superset documentation page for installation instructions: ', )} = ({ const [confirmedOverwrite, setConfirmedOverwrite] = useState(false); const [fileList, setFileList] = useState([]); const [importingModal, setImportingModal] = useState(false); + const [importingErrorMessage, setImportingErrorMessage] = useState(); + const [passwordFields, setPasswordFields] = useState([]); const conf = useCommonConf(); const dbImages = getDatabaseImages(); @@ -522,6 +525,8 @@ const DatabaseModal: FunctionComponent = ({ setEditNewDb(false); setFileList([]); setImportingModal(false); + setImportingErrorMessage(''); + setPasswordFields([]); setPasswords({}); setConfirmedOverwrite(false); onHide(); @@ -537,8 +542,7 @@ const DatabaseModal: FunctionComponent = ({ }, importResource, } = useImportResource('database', t('database'), msg => { - addDangerToast(msg); - onClose(); + setImportingErrorMessage(msg); }); const onChange = (type: any, payload: any) => { @@ -810,6 +814,12 @@ const DatabaseModal: FunctionComponent = ({ const handleBackButtonOnConnect = () => { if (editNewDb) setHasConnectedDb(false); if (importingModal) setImportingModal(false); + if (importErrored) { + setImportingModal(false); + setImportingErrorMessage(''); + setPasswordFields([]); + setPasswords({}); + } setDB({ type: ActionType.reset }); setFileList([]); }; @@ -970,7 +980,14 @@ const DatabaseModal: FunctionComponent = ({ } }, [importingModal]); + useEffect(() => { + setPasswordFields([...passwordsNeeded]); + }, [passwordsNeeded]); + const onDbImport = async (info: UploadChangeParam) => { + setImportingErrorMessage(''); + setPasswordFields([]); + setPasswords({}); setImportingModal(true); setFileList([ { @@ -989,9 +1006,9 @@ const DatabaseModal: FunctionComponent = ({ }; const passwordNeededField = () => { - if (!passwordsNeeded.length) return null; + if (!passwordFields.length) return null; - return passwordsNeeded.map(database => ( + return passwordFields.map(database => ( <> = ({ )); }; + const importingErrorAlert = () => { + if (!importingErrorMessage) return null; + + return ( + + 0} + /> + + ); + }; + const confirmOverwrite = (event: React.ChangeEvent) => { const targetValue = (event.currentTarget?.value as string) ?? ''; setConfirmedOverwrite(targetValue.toUpperCase() === t('OVERWRITE')); @@ -1225,7 +1255,7 @@ const DatabaseModal: FunctionComponent = ({ ); }; - if (fileList.length > 0 && (alreadyExists.length || passwordsNeeded.length)) { + if (fileList.length > 0 && (alreadyExists.length || passwordFields.length)) { return ( [ @@ -1256,6 +1286,7 @@ const DatabaseModal: FunctionComponent = ({ /> {passwordNeededField()} {confirmOverwriteField()} + {importingErrorAlert()} ); } @@ -1519,6 +1550,7 @@ const DatabaseModal: FunctionComponent = ({ + {importingErrorAlert()} ) : ( <> diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index 1bb0a06dc6d9e..2160a68f8d835 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -468,8 +468,8 @@ export function useImportResource( resourceLabel, [ ...error.errors.map(payload => payload.message), - t('Please re-export your file and try importing again'), - ].join('\n'), + t('Please re-export your file and try importing again.'), + ].join('.\n'), ), ); } else {