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

chore: add extension for related DB assets on delete #24050

Merged
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 @@ -65,6 +65,9 @@ type ConfigDetailsProps = {
type RightMenuItemIconProps = {
menuChild: MenuObjectChildProps;
};
type DatabaseDeleteRelatedExtensionProps = {
databaseId: number;
};

export type Extensions = Partial<{
'alertsreports.header.icon': React.ComponentType;
Expand All @@ -80,6 +83,7 @@ export type Extensions = Partial<{
'welcome.banner': React.ComponentType;
'welcome.main.replacement': React.ComponentType;
'ssh_tunnel.form.switch': React.ComponentType<SwitchProps>;
'database.delete.related': React.ComponentType<DatabaseDeleteRelatedExtensionProps>;
}>;

/**
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/DeleteModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const StyledDiv = styled.div`
`;

const DescriptionContainer = styled.div`
line-height: 40px;
line-height: ${({ theme }) => theme.gridUnit * 4}px;
padding-top: 16px;
`;

Expand Down
11 changes: 8 additions & 3 deletions superset-frontend/src/pages/DatabaseList/DatabaseList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ describe('Admin DatabaseList', () => {
});
await waitForComponentToPaint(wrapper);

expect(wrapper.find(DeleteModal).props().description).toMatchInlineSnapshot(
`"The database db 0 is linked to 0 charts that appear on 0 dashboards and users have 0 SQL Lab tabs using this database open. Are you sure you want to continue? Deleting the database will break those objects."`,
);
expect(wrapper.find(DeleteModal).props().description)
.toMatchInlineSnapshot(`
<React.Fragment>
<p>
The database db 0 is linked to 0 charts that appear on 0 dashboards and users have 0 SQL Lab tabs using this database open. Are you sure you want to continue? Deleting the database will break those objects.
</p>
</React.Fragment>
`);

act(() => {
wrapper
Expand Down
38 changes: 30 additions & 8 deletions superset-frontend/src/pages/DatabaseList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { FeatureFlag, styled, SupersetClient, t } from '@superset-ui/core';
import {
FeatureFlag,
getExtensionsRegistry,
styled,
SupersetClient,
t,
} from '@superset-ui/core';
import React, { useState, useMemo, useEffect } from 'react';
import rison from 'rison';
import { useSelector } from 'react-redux';
Expand All @@ -43,6 +49,11 @@ import type { MenuObjectProps } from 'src/types/bootstrapTypes';
import DatabaseModal from 'src/features/databases/DatabaseModal';
import { DatabaseObject } from 'src/features/databases/types';

const extensionsRegistry = getExtensionsRegistry();
const DatabaseDeleteRelatedExtension = extensionsRegistry.get(
'database.delete.related',
);

const PAGE_SIZE = 25;

interface DatabaseDeleteObject extends DatabaseObject {
Expand Down Expand Up @@ -512,13 +523,24 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
/>
{databaseCurrentlyDeleting && (
<DeleteModal
description={t(
'The database %s is linked to %s charts that appear on %s dashboards and users have %s SQL Lab tabs using this database open. Are you sure you want to continue? Deleting the database will break those objects.',
databaseCurrentlyDeleting.database_name,
databaseCurrentlyDeleting.chart_count,
databaseCurrentlyDeleting.dashboard_count,
databaseCurrentlyDeleting.sqllab_tab_count,
)}
description={
<>
<p>
{t(
'The database %s is linked to %s charts that appear on %s dashboards and users have %s SQL Lab tabs using this database open. Are you sure you want to continue? Deleting the database will break those objects.',
databaseCurrentlyDeleting.database_name,
databaseCurrentlyDeleting.chart_count,
databaseCurrentlyDeleting.dashboard_count,
databaseCurrentlyDeleting.sqllab_tab_count,
)}
</p>
{DatabaseDeleteRelatedExtension && currentDatabase?.id && (
<DatabaseDeleteRelatedExtension
databaseId={currentDatabase.id}
/>
)}
</>
}
onConfirm={() => {
if (databaseCurrentlyDeleting) {
handleDatabaseDelete(databaseCurrentlyDeleting);
Expand Down