mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
feat: database extension registry (#23174)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com> Co-authored-by: Lily Kuang <lily@preset.io>
This commit is contained in:
@@ -578,12 +578,31 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
sshTunnelPrivateKeyPasswordFields,
|
||||
setSSHTunnelPrivateKeyPasswordFields,
|
||||
] = useState<string[]>([]);
|
||||
const [extraExtensionComponentState, setExtraExtensionComponentState] =
|
||||
useState<object>({});
|
||||
|
||||
const SSHTunnelSwitchComponent =
|
||||
extensionsRegistry.get('ssh_tunnel.form.switch') ?? SSHTunnelSwitch;
|
||||
|
||||
const [useSSHTunneling, setUseSSHTunneling] = useState<boolean>(false);
|
||||
|
||||
let dbConfigExtraExtension = extensionsRegistry.get(
|
||||
'databaseconnection.extraOption',
|
||||
);
|
||||
|
||||
if (dbConfigExtraExtension) {
|
||||
// add method for db modal to store data
|
||||
dbConfigExtraExtension = {
|
||||
...dbConfigExtraExtension,
|
||||
onEdit: componentState => {
|
||||
setExtraExtensionComponentState({
|
||||
...extraExtensionComponentState,
|
||||
...componentState,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const conf = useCommonConf();
|
||||
const dbImages = getDatabaseImages();
|
||||
const connectionAlert = getConnectionAlert();
|
||||
@@ -715,6 +734,19 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
};
|
||||
|
||||
const onSave = async () => {
|
||||
let dbConfigExtraExtensionOnSaveError;
|
||||
dbConfigExtraExtension
|
||||
?.onSave(extraExtensionComponentState, db)
|
||||
.then(({ error }: { error: any }) => {
|
||||
if (error) {
|
||||
dbConfigExtraExtensionOnSaveError = error;
|
||||
addDangerToast(error);
|
||||
}
|
||||
});
|
||||
if (dbConfigExtraExtensionOnSaveError) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
// Clone DB object
|
||||
const dbToUpdate = { ...(db || {}) };
|
||||
|
||||
@@ -803,6 +835,18 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
);
|
||||
if (result) {
|
||||
if (onDatabaseAdd) onDatabaseAdd();
|
||||
dbConfigExtraExtension
|
||||
?.onSave(extraExtensionComponentState, db)
|
||||
.then(({ error }: { error: any }) => {
|
||||
if (error) {
|
||||
dbConfigExtraExtensionOnSaveError = error;
|
||||
addDangerToast(error);
|
||||
}
|
||||
});
|
||||
if (dbConfigExtraExtensionOnSaveError) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (!editNewDb) {
|
||||
onClose();
|
||||
addSuccessToast(t('Database settings updated'));
|
||||
@@ -817,6 +861,19 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
if (dbId) {
|
||||
setHasConnectedDb(true);
|
||||
if (onDatabaseAdd) onDatabaseAdd();
|
||||
dbConfigExtraExtension
|
||||
?.onSave(extraExtensionComponentState, db)
|
||||
.then(({ error }: { error: any }) => {
|
||||
if (error) {
|
||||
dbConfigExtraExtensionOnSaveError = error;
|
||||
addDangerToast(error);
|
||||
}
|
||||
});
|
||||
if (dbConfigExtraExtensionOnSaveError) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (useTabLayout) {
|
||||
// tab layout only has one step
|
||||
// so it should close immediately on save
|
||||
@@ -1596,6 +1653,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
if (!editNewDb) {
|
||||
return (
|
||||
<ExtraOptions
|
||||
extraExtension={dbConfigExtraExtension}
|
||||
db={db as DatabaseObject}
|
||||
onInputChange={({ target }: { target: HTMLInputElement }) =>
|
||||
onChange(ActionType.inputChange, {
|
||||
@@ -1807,6 +1865,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane tab={<span>{t('Advanced')}</span>} key="2">
|
||||
<ExtraOptions
|
||||
extraExtension={dbConfigExtraExtension}
|
||||
db={db as DatabaseObject}
|
||||
onInputChange={({ target }: { target: HTMLInputElement }) =>
|
||||
onChange(ActionType.inputChange, {
|
||||
|
||||
Reference in New Issue
Block a user