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(import): Show the error message with db install guide when exist the importing db issue #20573

Merged
merged 2 commits into from
Jul 6, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ErrorAlert: FunctionComponent<IProps> = ({
<>
<br />
{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: ',
)}
<a
href={DOCUMENTATION_LINK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import IconButton from 'src/components/IconButton';
import InfoTooltip from 'src/components/InfoTooltip';
import withToasts from 'src/components/MessageToasts/withToasts';
import ValidatedInput from 'src/components/Form/LabeledErrorBoundInput';
import ErrorAlert from 'src/components/ImportModal/ErrorAlert';
import {
testDatabaseConnection,
useSingleViewResource,
Expand Down Expand Up @@ -446,6 +447,8 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const [confirmedOverwrite, setConfirmedOverwrite] = useState<boolean>(false);
const [fileList, setFileList] = useState<UploadFile[]>([]);
const [importingModal, setImportingModal] = useState<boolean>(false);
const [importingErrorMessage, setImportingErrorMessage] = useState<string>();
const [passwordFields, setPasswordFields] = useState<string[]>([]);

const conf = useCommonConf();
const dbImages = getDatabaseImages();
Expand Down Expand Up @@ -516,6 +519,8 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
setEditNewDb(false);
setFileList([]);
setImportingModal(false);
setImportingErrorMessage('');
setPasswordFields([]);
setPasswords({});
setConfirmedOverwrite(false);
onHide();
Expand All @@ -531,8 +536,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
},
importResource,
} = useImportResource('database', t('database'), msg => {
addDangerToast(msg);
onClose();
setImportingErrorMessage(msg);
});

const onChange = (type: any, payload: any) => {
Expand Down Expand Up @@ -804,6 +808,12 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const handleBackButtonOnConnect = () => {
if (editNewDb) setHasConnectedDb(false);
if (importingModal) setImportingModal(false);
if (importErrored) {
setImportingModal(false);
setImportingErrorMessage('');
setPasswordFields([]);
setPasswords({});
}
setDB({ type: ActionType.reset });
setFileList([]);
};
Expand Down Expand Up @@ -964,7 +974,14 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
}, [importingModal]);

useEffect(() => {
setPasswordFields([...passwordsNeeded]);
}, [passwordsNeeded]);

const onDbImport = async (info: UploadChangeParam) => {
setImportingErrorMessage('');
setPasswordFields([]);
setPasswords({});
setImportingModal(true);
setFileList([
{
Expand All @@ -983,9 +1000,9 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
};

const passwordNeededField = () => {
if (!passwordsNeeded.length) return null;
if (!passwordFields.length) return null;

return passwordsNeeded.map(database => (
return passwordFields.map(database => (
<>
<StyledAlertMargin>
<Alert
Expand Down Expand Up @@ -1016,6 +1033,19 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
));
};

const importingErrorAlert = () => {
if (!importingErrorMessage) return null;

return (
<StyledAlertMargin>
<ErrorAlert
errorMessage={importingErrorMessage}
showDbInstallInstructions={passwordFields.length > 0}
/>
</StyledAlertMargin>
);
};

const confirmOverwrite = (event: React.ChangeEvent<HTMLInputElement>) => {
const targetValue = (event.currentTarget?.value as string) ?? '';
setConfirmedOverwrite(targetValue.toUpperCase() === t('OVERWRITE'));
Expand Down Expand Up @@ -1186,7 +1216,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
);
};

if (fileList.length > 0 && (alreadyExists.length || passwordsNeeded.length)) {
if (fileList.length > 0 && (alreadyExists.length || passwordFields.length)) {
return (
<Modal
css={(theme: SupersetTheme) => [
Expand Down Expand Up @@ -1217,6 +1247,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
/>
{passwordNeededField()}
{confirmOverwriteField()}
{importingErrorAlert()}
</Modal>
);
}
Expand Down Expand Up @@ -1479,6 +1510,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
</Button>
</Upload>
</StyledUploadWrapper>
{importingErrorAlert()}
</SelectDatabaseStyles>
) : (
<>
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down