You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ms...@apache.org on 2026/08/26 12:35:58 UTC
(superset) branch sc-116465-agorithm-3 created (now 27c1dc6e45e)
This is an automated email from the ASF dual-hosted git repository.
msyavuz pushed a change to branch sc-116465-agorithm-3
in repository https://gitbox.apache.org/repos/asf/superset.git
at 27c1dc6e45e fix(datasets): warn about affected charts and dashboards on bulk delete
This branch includes the following new commits:
new 27c1dc6e45e fix(datasets): warn about affected charts and dashboards on bulk delete
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix(datasets): warn about affected charts and dashboards on bulk delete
Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
msyavuz pushed a commit to branch sc-116465-agorithm-3
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 27c1dc6e45ed9416b587b285d98ec5059b5cc693
Author: Mehmet Yavuz <me...@ext.preset.io>
AuthorDate: Wed Aug 26 12:35:47 2026 +0000
fix(datasets): warn about affected charts and dashboards on bulk delete
Single-dataset delete fetches related_objects and names the affected
charts and dashboards before the typed-DELETE confirmation, but bulk
delete showed only a generic "Type DELETE to confirm" dialog with no
blast-radius information. Bulk delete is exactly where the risk is
largest.
The bulk confirm now fans out related_objects for every selected dataset
when the delete action fires, aggregates the dependent charts and
dashboards (de-duplicated by id so an object shared across the selection
is counted once), and renders the same Affected Charts / Affected
Dashboards lists the single-row modal uses. The shared list markup is
extracted into an AffectedObjectsList component used by both paths.
---
.../DatasetList/DatasetList.integration.test.tsx | 133 +++++++++
.../pages/DatasetList/DatasetList.testHelpers.tsx | 16 +-
superset-frontend/src/pages/DatasetList/index.tsx | 307 +++++++++++++--------
3 files changed, 347 insertions(+), 109 deletions(-)
diff --git a/superset-frontend/src/pages/DatasetList/DatasetList.integration.test.tsx b/superset-frontend/src/pages/DatasetList/DatasetList.integration.test.tsx
index 85c6ccd7245..800271db2e3 100644
--- a/superset-frontend/src/pages/DatasetList/DatasetList.integration.test.tsx
+++ b/superset-frontend/src/pages/DatasetList/DatasetList.integration.test.tsx
@@ -260,6 +260,139 @@ test('bulk action orchestration: selection → action → cleanup cycle works co
// selection state → action handler → list refresh → state cleanup
}, 45000);
+test('bulk delete confirm names the charts and dashboards that will break', async () => {
+ // Regression for sc-116465: bulk delete used a static "Type DELETE to
+ // confirm" dialog that named no dependents, while single-row delete named
+ // affected charts and counted dashboards. Selecting datasets in bulk must
+ // surface the same blast-radius warning, aggregated across the selection.
+ const withDependents = mockDatasets[0]; // id 1 -- has a chart on a dashboard
+ const noDependents = mockDatasets[1]; // id 2 -- clean
+
+ mockDatasetListEndpoints({
+ result: [withDependents, noDependents],
+ count: 2,
+ });
+
+ // The bulk confirm fans out related_objects per selected dataset. id 1 has a
+ // dependent chart + dashboard; id 2 has none. The union is what the modal
+ // must show.
+ fetchMock.get(`glob:*/api/v1/dataset/${withDependents.id}/related_objects*`, {
+ charts: {
+ count: 1,
+ result: [{ id: 101, slice_name: 'QA Delete Target Chart' }],
+ },
+ dashboards: {
+ count: 1,
+ result: [{ id: 201, title: 'Executive Dashboard' }],
+ },
+ });
+ fetchMock.get(`glob:*/api/v1/dataset/${noDependents.id}/related_objects*`, {
+ charts: { count: 0, result: [] },
+ dashboards: { count: 0, result: [] },
+ });
+ fetchMock.delete(API_ENDPOINTS.DATASET_BULK_DELETE, {
+ message: '2 datasets deleted successfully',
+ });
+
+ renderDatasetList(mockAdminUser);
+ await waitFor(() => {
+ expect(screen.getByTestId('listview-table')).toBeInTheDocument();
+ });
+
+ await userEvent.click(screen.getByRole('button', { name: /bulk select/i }));
+ const bulkSelectControls = await screen.findByTestId('bulk-select-controls');
+ const table = screen.getByTestId('listview-table');
+ await within(table).findAllByRole('checkbox');
+
+ for (const name of [withDependents.table_name, noDependents.table_name]) {
+ // eslint-disable-next-line no-await-in-loop
+ const cell = await within(table).findByText(name);
+ // eslint-disable-next-line no-await-in-loop
+ await userEvent.click(within(cell.closest('tr')!).getByRole('checkbox'));
+ }
+ await waitFor(() => {
+ expect(screen.getByTestId('bulk-select-copy')).toHaveTextContent(
+ /2 Selected/i,
+ );
+ });
+
+ await userEvent.click(
+ await within(bulkSelectControls).findByRole('button', { name: 'Delete' }),
+ );
+
+ const modal = await screen.findByRole('dialog');
+
+ // The dependents are named and counted, matching the single-row delete modal.
+ // findByText waits out the async related_objects fan-out.
+ expect(await within(modal).findByText('Affected Charts')).toBeInTheDocument();
+ expect(within(modal).getByText('Affected Dashboards')).toBeInTheDocument();
+ expect(within(modal).getByText('QA Delete Target Chart')).toBeInTheDocument();
+ expect(within(modal).getByText('Executive Dashboard')).toBeInTheDocument();
+ expect(modal).toHaveTextContent(
+ /linked to 1 charts that appear on 1 dashboards/i,
+ );
+}, 45000);
+
+test('bulk delete confirm de-duplicates a dashboard shared by two datasets', async () => {
+ // The blast-radius count is a union, not a sum: two selected datasets that
+ // both feed the same dashboard must count that dashboard once, or the warning
+ // over-states the damage and erodes trust in the number.
+ const first = mockDatasets[0]; // id 1
+ const second = mockDatasets[1]; // id 2
+
+ mockDatasetListEndpoints({ result: [first, second], count: 2 });
+
+ // Both datasets list the SAME dashboard (id 201) but distinct charts.
+ const sharedDashboard = { id: 201, title: 'Executive Dashboard' };
+ fetchMock.get(`glob:*/api/v1/dataset/${first.id}/related_objects*`, {
+ charts: { count: 1, result: [{ id: 101, slice_name: 'Chart A' }] },
+ dashboards: { count: 1, result: [sharedDashboard] },
+ });
+ fetchMock.get(`glob:*/api/v1/dataset/${second.id}/related_objects*`, {
+ charts: { count: 1, result: [{ id: 102, slice_name: 'Chart B' }] },
+ dashboards: { count: 1, result: [sharedDashboard] },
+ });
+ fetchMock.delete(API_ENDPOINTS.DATASET_BULK_DELETE, {
+ message: '2 datasets deleted successfully',
+ });
+
+ renderDatasetList(mockAdminUser);
+ await waitFor(() => {
+ expect(screen.getByTestId('listview-table')).toBeInTheDocument();
+ });
+
+ await userEvent.click(screen.getByRole('button', { name: /bulk select/i }));
+ const bulkSelectControls = await screen.findByTestId('bulk-select-controls');
+ const table = screen.getByTestId('listview-table');
+ await within(table).findAllByRole('checkbox');
+
+ for (const name of [first.table_name, second.table_name]) {
+ // eslint-disable-next-line no-await-in-loop
+ const cell = await within(table).findByText(name);
+ // eslint-disable-next-line no-await-in-loop
+ await userEvent.click(within(cell.closest('tr')!).getByRole('checkbox'));
+ }
+ await waitFor(() => {
+ expect(screen.getByTestId('bulk-select-copy')).toHaveTextContent(
+ /2 Selected/i,
+ );
+ });
+
+ await userEvent.click(
+ await within(bulkSelectControls).findByRole('button', { name: 'Delete' }),
+ );
+
+ const modal = await screen.findByRole('dialog');
+
+ // 2 distinct charts, 1 distinct dashboard (deduped) -- not 2 dashboards.
+ await within(modal).findByText('Affected Charts');
+ expect(modal).toHaveTextContent(
+ /linked to 2 charts that appear on 1 dashboards/i,
+ );
+ // The shared dashboard is listed a single time.
+ expect(within(modal).getAllByText('Executive Dashboard')).toHaveLength(1);
+}, 45000);
+
/**
* Renders the list with one regular dataset plus the given semantic-view row,
* bulk-selects both, opens the bulk Archive confirm, and asserts the modal
diff --git a/superset-frontend/src/pages/DatasetList/DatasetList.testHelpers.tsx b/superset-frontend/src/pages/DatasetList/DatasetList.testHelpers.tsx
index c0f4b88a627..6fec296376f 100644
--- a/superset-frontend/src/pages/DatasetList/DatasetList.testHelpers.tsx
+++ b/superset-frontend/src/pages/DatasetList/DatasetList.testHelpers.tsx
@@ -479,10 +479,24 @@ export const setupDuplicateMocks = () => {
};
export const setupBulkDeleteMocks = () => {
- fetchMock.removeRoutes({ names: [API_ENDPOINTS.DATASET_BULK_DELETE] });
+ fetchMock.removeRoutes({
+ names: [
+ API_ENDPOINTS.DATASET_BULK_DELETE,
+ API_ENDPOINTS.DATASET_RELATED_OBJECTS,
+ ],
+ });
fetchMock.delete(API_ENDPOINTS.DATASET_BULK_DELETE, {
message: '3 datasets deleted successfully',
});
+ // Bulk delete now fans out related_objects per selected dataset to warn about
+ // dependent charts/dashboards (sc-116465). Default to no dependents; a test
+ // that asserts the warning sets up its own per-id routes instead of this
+ // helper (fetch-mock matches the first-registered route for an id).
+ fetchMock.get(
+ API_ENDPOINTS.DATASET_RELATED_OBJECTS,
+ { charts: { count: 0, result: [] }, dashboards: { count: 0, result: [] } },
+ { name: API_ENDPOINTS.DATASET_RELATED_OBJECTS },
+ );
};
// Setup error mocks for negative flow testing
diff --git a/superset-frontend/src/pages/DatasetList/index.tsx b/superset-frontend/src/pages/DatasetList/index.tsx
index 9d387ca0ea0..3367867f242 100644
--- a/superset-frontend/src/pages/DatasetList/index.tsx
+++ b/superset-frontend/src/pages/DatasetList/index.tsx
@@ -199,6 +199,92 @@ type RelatedObjects = {
result: Array<Record<string, unknown>>;
};
+type DatasetRelatedObjects = {
+ charts: RelatedObjects;
+ dashboards: RelatedObjects;
+};
+
+/**
+ * The "Affected Dashboards" / "Affected Charts" lists rendered inside a dataset
+ * delete confirmation, capped at 10 each with an overflow footer. Shared by the
+ * single-row delete modal and the bulk-delete confirm so both name and count
+ * the at-risk objects identically -- previously only the single-row path
+ * surfaced them, leaving bulk delete with no blast-radius warning (sc-116465).
+ */
+const AffectedObjectsList: FunctionComponent<DatasetRelatedObjects> = ({
+ charts,
+ dashboards,
+}) => (
+ <>
+ {dashboards.count >= 1 && (
+ <>
+ <h4>{t('Affected Dashboards')}</h4>
+ <List
+ split={false}
+ size="small"
+ dataSource={dashboards.result.slice(0, 10)}
+ renderItem={(result: {
+ id: Key | null | undefined;
+ title: string;
+ }) => (
+ <List.Item key={result.id} compact>
+ <List.Item.Meta
+ avatar={<span>•</span>}
+ title={
+ <Typography.Link
+ href={ensureAppRoot(`/dashboard/${result.id}`)}
+ target="_atRiskItem"
+ >
+ {result.title}
+ </Typography.Link>
+ }
+ />
+ </List.Item>
+ )}
+ footer={
+ dashboards.result.length > 10 && (
+ <div>{t('... and %s others', dashboards.result.length - 10)}</div>
+ )
+ }
+ />
+ </>
+ )}
+ {charts.count >= 1 && (
+ <>
+ <h4>{t('Affected Charts')}</h4>
+ <List
+ split={false}
+ size="small"
+ dataSource={charts.result.slice(0, 10)}
+ renderItem={(result: {
+ id: Key | null | undefined;
+ slice_name: string;
+ }) => (
+ <List.Item key={result.id} compact>
+ <List.Item.Meta
+ avatar={<span>•</span>}
+ title={
+ <Typography.Link
+ href={ensureAppRoot(`/explore/?slice_id=${result.id}`)}
+ target="_atRiskItem"
+ >
+ {result.slice_name}
+ </Typography.Link>
+ }
+ />
+ </List.Item>
+ )}
+ footer={
+ charts.result.length > 10 && (
+ <div>{t('... and %s others', charts.result.length - 10)}</div>
+ )
+ }
+ />
+ </>
+ )}
+ </>
+);
+
const DatasetList: FunctionComponent<DatasetListProps> = ({
addDangerToast,
addSuccessToast,
@@ -222,6 +308,14 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
// change with the selection. Captured when the bulk action fires, before
// the modal opens.
const [pendingBulkSemanticCount, setPendingBulkSemanticCount] = useState(0);
+ // Charts/dashboards that depend on the current bulk selection, aggregated
+ // across every selected dataset so the bulk confirm can warn about the blast
+ // radius the same way the single-row delete modal does (sc-116465). Fetched
+ // when the bulk action fires; `null` until the lookup resolves.
+ const [pendingBulkRelated, setPendingBulkRelated] =
+ useState<DatasetRelatedObjects | null>(null);
+ const [pendingBulkRelatedLoading, setPendingBulkRelatedLoading] =
+ useState(false);
const [datasets, setDatasets] = useState<Dataset[]>([]);
const [datasetCount, setDatasetCount] = useState(0);
const [loading, setLoading] = useState(true);
@@ -624,6 +718,57 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
setDatasetCurrentlyDuplicating(dataset);
}, []);
+ /**
+ * Fan out `related_objects` for every regular dataset in a bulk selection and
+ * aggregate the dependent charts/dashboards, de-duplicating by id so an object
+ * shared by two selected datasets is counted once. Semantic-view rows are
+ * skipped: they delete through a different endpoint and have no
+ * `related_objects` lookup. A per-request failure is swallowed so a single
+ * unreachable lookup never blocks the confirmation -- the warning is a
+ * best-effort safety net, not a gate.
+ */
+ const fetchBulkRelatedObjects = useCallback((selected: Dataset[]) => {
+ const datasetRows = selected.filter(d => !isSemanticView(d));
+ if (datasetRows.length === 0) {
+ setPendingBulkRelated(null);
+ setPendingBulkRelatedLoading(false);
+ return;
+ }
+ setPendingBulkRelated(null);
+ setPendingBulkRelatedLoading(true);
+ Promise.all(
+ datasetRows.map(({ id }) =>
+ SupersetClient.get({
+ endpoint: `/api/v1/dataset/${id}/related_objects`,
+ })
+ .then(({ json = {} }) => json as Partial<DatasetRelatedObjects>)
+ .catch(() => null),
+ ),
+ ).then(results => {
+ const chartsById = new Map<unknown, Record<string, unknown>>();
+ const dashboardsById = new Map<unknown, Record<string, unknown>>();
+ results.forEach(result => {
+ result?.charts?.result?.forEach(chart => {
+ chartsById.set(chart.id, chart);
+ });
+ result?.dashboards?.result?.forEach(dashboard => {
+ dashboardsById.set(dashboard.id, dashboard);
+ });
+ });
+ setPendingBulkRelated({
+ charts: {
+ count: chartsById.size,
+ result: Array.from(chartsById.values()),
+ },
+ dashboards: {
+ count: dashboardsById.size,
+ result: Array.from(dashboardsById.values()),
+ },
+ });
+ setPendingBulkRelatedLoading(false);
+ });
+ }, []);
+
const handleBulkDatasetExport = useCallback(
async (datasetsToExport: Dataset[]) => {
// The combined Datasources list mixes regular datasets (SqlaTable) with
@@ -1284,6 +1429,10 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
};
const handleBulkDatasetDelete = (datasetsToDelete: Dataset[]) => {
+ // Drop the resolved dependents so a later selection never briefly shows the
+ // previous selection's affected charts/dashboards before its own fetch lands.
+ setPendingBulkRelated(null);
+ setPendingBulkRelatedLoading(false);
// Misrouting here sends a semantic-view id to the dataset delete
// endpoint, which looks rows up by bare numeric id against `tables`
// only (see the export handler's comment) — hence the shared predicate.
@@ -1400,92 +1549,10 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
datasetCurrentlyDeleting.dashboards.count,
)}
</p>
- {datasetCurrentlyDeleting.dashboards.count >= 1 && (
- <>
- <h4>{t('Affected Dashboards')}</h4>
- <List
- split={false}
- size="small"
- dataSource={datasetCurrentlyDeleting.dashboards.result.slice(
- 0,
- 10,
- )}
- renderItem={(result: {
- id: Key | null | undefined;
- title: string;
- }) => (
- <List.Item key={result.id} compact>
- <List.Item.Meta
- avatar={<span>•</span>}
- title={
- <Typography.Link
- href={ensureAppRoot(`/dashboard/${result.id}`)}
- target="_atRiskItem"
- >
- {result.title}
- </Typography.Link>
- }
- />
- </List.Item>
- )}
- footer={
- datasetCurrentlyDeleting.dashboards.result.length >
- 10 && (
- <div>
- {t(
- '... and %s others',
- datasetCurrentlyDeleting.dashboards.result.length -
- 10,
- )}
- </div>
- )
- }
- />
- </>
- )}
- {datasetCurrentlyDeleting.charts.count >= 1 && (
- <>
- <h4>{t('Affected Charts')}</h4>
- <List
- split={false}
- size="small"
- dataSource={datasetCurrentlyDeleting.charts.result.slice(
- 0,
- 10,
- )}
- renderItem={(result: {
- id: Key | null | undefined;
- slice_name: string;
- }) => (
- <List.Item key={result.id} compact>
- <List.Item.Meta
- avatar={<span>•</span>}
- title={
- <Typography.Link
- href={ensureAppRoot(
- `/explore/?slice_id=${result.id}`,
- )}
- target="_atRiskItem"
- >
- {result.slice_name}
- </Typography.Link>
- }
- />
- </List.Item>
- )}
- footer={
- datasetCurrentlyDeleting.charts.result.length > 10 && (
- <div>
- {t(
- '... and %s others',
- datasetCurrentlyDeleting.charts.result.length - 10,
- )}
- </div>
- )
- }
- />
- </>
- )}
+ <AffectedObjectsList
+ charts={datasetCurrentlyDeleting.charts}
+ dashboards={datasetCurrentlyDeleting.dashboards}
+ />
{DatasetDeleteRelatedExtension && (
<DatasetDeleteRelatedExtension
dataset={datasetCurrentlyDeleting}
@@ -1562,29 +1629,52 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
: t('Please confirm')
}
description={
- softDelete ? (
- bulkIsRecoverable ? (
- archiveConfirmDescription(datasetsLabelLower(), true)
+ <>
+ {softDelete ? (
+ bulkIsRecoverable ? (
+ archiveConfirmDescription(datasetsLabelLower(), true)
+ ) : (
+ <>
+ {tn(
+ '%s of the selected items is a semantic view, which cannot be archived: it will be deleted permanently and cannot be recovered.',
+ '%s of the selected items are semantic views, which cannot be archived: they will be deleted permanently and cannot be recovered.',
+ pendingBulkSemanticCount,
+ pendingBulkSemanticCount,
+ )}{' '}
+ {t(
+ 'The remaining %s will be moved to Recently Archived.',
+ datasetsLabelLower(),
+ )}
+ </>
+ )
) : (
- <>
- {tn(
- '%s of the selected items is a semantic view, which cannot be archived: it will be deleted permanently and cannot be recovered.',
- '%s of the selected items are semantic views, which cannot be archived: they will be deleted permanently and cannot be recovered.',
- pendingBulkSemanticCount,
- pendingBulkSemanticCount,
- )}{' '}
- {t(
- 'The remaining %s will be moved to Recently Archived.',
- datasetsLabelLower(),
- )}
- </>
- )
- ) : (
- t(
- 'Are you sure you want to delete the selected %s?',
- datasetsLabelLower(),
- )
- )
+ t(
+ 'Are you sure you want to delete the selected %s?',
+ datasetsLabelLower(),
+ )
+ )}
+ {pendingBulkRelatedLoading && (
+ <p>{t('Checking for affected charts and dashboards…')}</p>
+ )}
+ {pendingBulkRelated &&
+ (pendingBulkRelated.charts.count > 0 ||
+ pendingBulkRelated.dashboards.count > 0) && (
+ <>
+ <p>
+ {t(
+ 'The selected %s are linked to %s charts that appear on %s dashboards. Deleting them will break those objects.',
+ datasetsLabelLower(),
+ pendingBulkRelated.charts.count,
+ pendingBulkRelated.dashboards.count,
+ )}
+ </p>
+ <AffectedObjectsList
+ charts={pendingBulkRelated.charts}
+ dashboards={pendingBulkRelated.dashboards}
+ />
+ </>
+ )}
+ </>
}
onConfirm={handleBulkDatasetDelete}
>
@@ -1598,6 +1688,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
setPendingBulkSemanticCount(
selected.filter(isSemanticView).length,
);
+ fetchBulkRelatedObjects(selected);
confirmDelete(selected);
},
type: 'danger',