This is an automated email from the ASF dual-hosted git repository. beto pushed a commit to branch delete_database_extension in repository https://gitbox.apache.org/repos/asf/superset.git
commit 8f981f8ab99da23206a073f0d9f334bdab29bb69 Author: Beto Dealmeida <[email protected]> AuthorDate: Tue May 23 11:25:04 2023 -0400 feat: extension hook for DB delete --- .../superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts | 8 +++----- superset-frontend/src/pages/DatabaseList/index.tsx | 11 ++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts b/superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts index 70f53ab941..db21b2a9db 100644 --- a/superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts +++ b/superset-frontend/packages/superset-ui-core/src/ui-overrides/ExtensionsRegistry.ts @@ -98,15 +98,12 @@ export interface DatabaseConnectionExtension { enabled: () => boolean; /** - * Callback for onsave + * Callbacks */ // TODO: we need to move the db types to superset-ui/core in order to import them correctly onSave: (componentState: any, db: any) => any; - - /** - * Used for parent to store data - */ onEdit?: (componentState: any) => void; + onDelete?: (db: any) => void; } export type Extensions = Partial<{ @@ -124,6 +121,7 @@ export type Extensions = Partial<{ 'welcome.main.replacement': React.ComponentType; 'ssh_tunnel.form.switch': React.ComponentType<SwitchProps>; 'databaseconnection.extraOption': DatabaseConnectionExtension; + /* Custom components to show in the database and dataset delete modals */ 'database.delete.related': React.ComponentType<DatabaseDeleteRelatedExtensionProps>; 'dataset.delete.related': React.ComponentType<DatasetDeleteRelatedExtensionProps>; }>; diff --git a/superset-frontend/src/pages/DatabaseList/index.tsx b/superset-frontend/src/pages/DatabaseList/index.tsx index 9365c021e2..656dac89ea 100644 --- a/superset-frontend/src/pages/DatabaseList/index.tsx +++ b/superset-frontend/src/pages/DatabaseList/index.tsx @@ -53,6 +53,9 @@ const extensionsRegistry = getExtensionsRegistry(); const DatabaseDeleteRelatedExtension = extensionsRegistry.get( 'database.delete.related', ); +const dbConfigExtraExtension = extensionsRegistry.get( + 'databaseconnection.extraOption', +); const PAGE_SIZE = 25; @@ -160,7 +163,8 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { ), ); - function handleDatabaseDelete({ id, database_name: dbName }: DatabaseObject) { + function handleDatabaseDelete(database: DatabaseObject) { + const { id, database_name: dbName } = database; SupersetClient.delete({ endpoint: `/api/v1/database/${id}`, }).then( @@ -168,6 +172,11 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { refreshData(); addSuccessToast(t('Deleted: %s', dbName)); + // Remove any extension-related data + if (dbConfigExtraExtension?.onDelete) { + dbConfigExtraExtension.onDelete(database); + } + // Delete user-selected db from local storage setItem(LocalStorageKeys.db, null);
