diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index b5bd38a6f68f..392df834dd7b 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -85,8 +85,13 @@ import { } from './styles'; import ModalHeader, { DOCUMENTATION_LINK } from './ModalHeader'; +enum Engines { + GSheet = 'gsheets', + Snowflake = 'snowflake', +} + const engineSpecificAlertMapping = { - gsheets: { + [Engines.GSheet]: { message: 'Why do I need to create a database?', description: 'To begin using your Google Sheets, you need to create a database first. ' + @@ -109,8 +114,6 @@ const TabsStyled = styled(Tabs)` } `; -const googleSheetConnectionEngine = 'gsheets'; - interface DatabaseModalProps { addDangerToast: (msg: string) => void; addSuccessToast: (msg: string) => void; @@ -586,7 +589,7 @@ const DatabaseModal: FunctionComponent = ({ // cast the new encrypted extra object into a string dbToUpdate.encrypted_extra = JSON.stringify(additionalEncryptedExtra); // this needs to be added by default to gsheets - if (dbToUpdate.engine === 'gsheets') { + if (dbToUpdate.engine === Engines.GSheet) { dbToUpdate.impersonate_user = true; } } @@ -605,8 +608,8 @@ const DatabaseModal: FunctionComponent = ({ dbToUpdate.extra = serializeExtra(dbToUpdate?.extra_json); } + setLoading(true); if (db?.id) { - setLoading(true); const result = await updateResource( db.id as number, dbToUpdate as DatabaseObject, @@ -621,7 +624,6 @@ const DatabaseModal: FunctionComponent = ({ } } else if (db) { // Create - setLoading(true); const dbId = await createResource( dbToUpdate as DatabaseObject, dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM, // onShow toast on SQLA Forms @@ -636,14 +638,14 @@ const DatabaseModal: FunctionComponent = ({ addSuccessToast(t('Database connected')); } } - } - - // Import - doesn't use db state - if (!db) { - setLoading(true); + } else { + // Import - doesn't use db state setImportingModal(true); - if (!(fileList[0].originFileObj instanceof File)) return; + if (!(fileList[0].originFileObj instanceof File)) { + return; + } + const dbId = await importResource( fileList[0].originFileObj, passwords, @@ -1083,15 +1085,23 @@ const DatabaseModal: FunctionComponent = ({ // eslint-disable-next-line consistent-return const errorAlert = () => { + let alertErrors: string[] = []; if (isEmpty(dbErrors) === false) { - const message: Array = - typeof dbErrors === 'object' ? Object.values(dbErrors) : []; + alertErrors = typeof dbErrors === 'object' ? Object.values(dbErrors) : []; + } else if (db?.engine === Engines.Snowflake) { + alertErrors = + validationErrors?.error_type === 'GENERIC_DB_ENGINE_ERROR' + ? [validationErrors?.description] + : []; + } + + if (alertErrors.length) { return ( antDErrorAlertStyles(theme)} message={t('Database Creation Error')} - description={message?.[0] || dbErrors} + description={t(alertErrors[0])} /> ); } @@ -1523,7 +1533,7 @@ const DatabaseModal: FunctionComponent = ({ validationErrors={validationErrors} />
infoTooltip(theme)}> - {dbModel.engine !== googleSheetConnectionEngine && ( + {dbModel.engine !== Engines.GSheet && ( <>