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(); @@ -516,6 +519,8 @@ const DatabaseModal: FunctionComponent = ({ setEditNewDb(false); setFileList([]); setImportingModal(false); + setImportingErrorMessage(''); + setPasswordFields([]); setPasswords({}); setConfirmedOverwrite(false); onHide(); @@ -531,8 +536,7 @@ const DatabaseModal: FunctionComponent = ({ }, importResource, } = useImportResource('database', t('database'), msg => { - addDangerToast(msg); - onClose(); + setImportingErrorMessage(msg); }); const onChange = (type: any, payload: any) => { @@ -804,6 +808,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([]); }; @@ -964,7 +974,14 @@ const DatabaseModal: FunctionComponent = ({ } }, [importingModal]); + useEffect(() => { + setPasswordFields([...passwordsNeeded]); + }, [passwordsNeeded]); + const onDbImport = async (info: UploadChangeParam) => { + setImportingErrorMessage(''); + setPasswordFields([]); + setPasswords({}); setImportingModal(true); setFileList([ { @@ -983,9 +1000,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')); @@ -1186,7 +1216,7 @@ const DatabaseModal: FunctionComponent = ({ ); }; - if (fileList.length > 0 && (alreadyExists.length || passwordsNeeded.length)) { + if (fileList.length > 0 && (alreadyExists.length || passwordFields.length)) { return ( [ @@ -1217,6 +1247,7 @@ const DatabaseModal: FunctionComponent = ({ /> {passwordNeededField()} {confirmOverwriteField()} + {importingErrorAlert()} ); } @@ -1479,6 +1510,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 {