From 9df8d8dda538095ba3b30d1f82aa81acf17e1c95 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Thu, 25 May 2023 13:21:55 -0400 Subject: [PATCH] feat: extension hook for DB delete (#24191) --- .../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 70f53ab941a1d..db21b2a9db689 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; 'databaseconnection.extraOption': DatabaseConnectionExtension; + /* Custom components to show in the database and dataset delete modals */ 'database.delete.related': React.ComponentType; 'dataset.delete.related': React.ComponentType; }>; diff --git a/superset-frontend/src/pages/DatabaseList/index.tsx b/superset-frontend/src/pages/DatabaseList/index.tsx index 9365c021e27ae..656dac89ea97c 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);