This is an automated email from the ASF dual-hosted git repository. villebro pushed a commit to branch 7.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 1eec284270f5b926aa9db39f012810c65bbfb0ab Author: Mike Bridge <[email protected]> AuthorDate: Wed Nov 4 07:43:18 2026 -0600 fix(dashboard): show placeholder for archived charts in version preview (#45745) (cherry picked from commit dd902a0cbf136400bfcca3f80b902616794dc434) --- docs/docs/using-superset/version-history.mdx | 3 ++ .../src/features/versionHistory/api.ts | 24 +++++++++++--- .../useDashboardVersionPreview.test.tsx | 38 ++++++++++++++++++++++ .../versionHistory/useDashboardVersionPreview.ts | 15 +++++++-- superset/translations/messages.pot | 6 ++++ 5 files changed, 79 insertions(+), 7 deletions(-) diff --git a/docs/docs/using-superset/version-history.mdx b/docs/docs/using-superset/version-history.mdx index 020181ab480..5ca8d1389f3 100644 --- a/docs/docs/using-superset/version-history.mdx +++ b/docs/docs/using-superset/version-history.mdx @@ -79,6 +79,9 @@ selections you had before you opened it. A dashboard preview reconstructs the layout as it was, including charts that have since been removed from the dashboard. A chart that has been deleted outright cannot be reconstructed; its slot shows a placeholder instead. +An archived or otherwise unavailable chart also shows a placeholder. An editor +can restore archived charts from **Recently Archived**. Other charts in the +version continue to preview normally. Preview is a close approximation of the version, not a pixel-faithful replay. The dashboard's own saved properties — title, CSS, metadata, description, diff --git a/superset-frontend/src/features/versionHistory/api.ts b/superset-frontend/src/features/versionHistory/api.ts index 1971cf5298f..b50948403ea 100644 --- a/superset-frontend/src/features/versionHistory/api.ts +++ b/superset-frontend/src/features/versionHistory/api.ts @@ -16,7 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -import { JsonObject, SupersetClient } from '@superset-ui/core'; +import { + FeatureFlag, + isFeatureEnabled, + JsonObject, + SupersetClient, +} from '@superset-ui/core'; import rison from 'rison'; import { t } from '@apache-superset/core/translation'; import { DASHBOARD_GET_COLUMNS } from 'src/hooks/apiResources/dashboards'; @@ -213,14 +218,23 @@ export const layoutChartId = (item: JsonObject): number | null => { export function swapUnreachableChartSlots( positionData: JsonObject, unreachableIds: Set<number>, + unavailableIds?: Set<number>, ): JsonObject { - if (unreachableIds.size === 0) { + if (unreachableIds.size === 0 && !unavailableIds?.size) { return positionData; } + const unavailableCode = isFeatureEnabled(FeatureFlag.SoftDelete) + ? t( + 'This chart is archived or unavailable. An editor can restore archived charts from Recently Archived.', + ) + : t('This chart is archived or unavailable.'); const layout: JsonObject = { ...positionData }; Object.entries(layout).forEach(([key, item]) => { const chartId = layoutChartId(item as JsonObject); - if (chartId !== null && unreachableIds.has(chartId)) { + if ( + chartId !== null && + (unreachableIds.has(chartId) || unavailableIds?.has(chartId)) + ) { const meta = (item as JsonObject).meta as JsonObject; layout[key] = { ...(item as JsonObject), @@ -228,7 +242,9 @@ export function swapUnreachableChartSlots( meta: { width: meta?.width, height: meta?.height, - code: t('This chart no longer exists.'), + code: unavailableIds?.has(chartId) + ? unavailableCode + : t('This chart no longer exists.'), }, }; } diff --git a/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.test.tsx b/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.test.tsx index 7d9c1d92bf1..c6f937f3a6c 100644 --- a/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.test.tsx +++ b/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.test.tsx @@ -22,6 +22,7 @@ import { MemoryRouter } from 'react-router-dom'; import { act, renderHook, waitFor } from '@testing-library/react'; import type { AnyAction, Store } from 'redux'; import fetchMock from 'fetch-mock'; +import { FeatureFlag } from '@superset-ui/core'; import type { DataMaskStateWithId, JsonObject } from '@superset-ui/core'; import { hydrateDashboard, @@ -188,6 +189,43 @@ test('resolveSnapshotCharts swaps unreachable charts for a markdown placeholder' }); }); +test.each([true, false])( + 'resolveSnapshotCharts shows archived-chart guidance with soft delete %s', + async softDelete => { + const previousFeatureFlags = window.featureFlags; + window.featureFlags = { + ...previousFeatureFlags, + [FeatureFlag.SoftDelete]: softDelete, + }; + try { + // Explore returns 200 with no slice for an archived or purged chart. + fetchMock.get('glob:*/api/v1/explore/?slice_id=9', { + result: { slice: null, form_data: { slice_id: 9 } }, + }); + const layout = { ...chartSlot('CHART-a', 1), ...chartSlot('CHART-b', 9) }; + + const { charts, positionData } = await resolveSnapshotCharts( + [liveChart(1, 'Live')], + layout, + ); + + expect(charts.map(chart => chart.slice_id)).toEqual([1]); + expect((positionData as JsonObject)['CHART-a'].type).toBe(CHART_TYPE); + const placeholder = (positionData as JsonObject)['CHART-b']; + expect(placeholder.type).toBe(MARKDOWN_TYPE); + expect(placeholder.meta).toEqual({ + width: 4, + height: 50, + code: softDelete + ? 'This chart is archived or unavailable. An editor can restore archived charts from Recently Archived.' + : 'This chart is archived or unavailable.', + }); + } finally { + window.featureFlags = previousFeatureFlags; + } + }, +); + const HYDRATE_TEST = 'HYDRATE_TEST_ACTION'; const mockedHydrateDashboard = hydrateDashboard as unknown as jest.Mock; diff --git a/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.ts b/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.ts index c01160a8ed4..045a29e8eef 100644 --- a/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.ts +++ b/superset-frontend/src/features/versionHistory/useDashboardVersionPreview.ts @@ -123,18 +123,23 @@ export async function resolveSnapshotCharts( }); const unreachable = new Set<number>(); + const unavailable = new Set<number>(); await forEachWithConcurrency( missingIds, EXPLORE_REHYDRATION_CONCURRENCY, async id => { try { const { slice, form_data } = await fetchExploreRehydrationData(id); + if (!slice) { + unavailable.add(id); + return; + } charts.push({ slice_id: id, slice_url: `/explore/?slice_id=${id}`, - slice_name: slice?.slice_name ?? t('Untitled chart'), + slice_name: slice.slice_name ?? t('Untitled chart'), form_data: { ...form_data, slice_id: id }, - description: slice?.description ?? '', + description: slice.description ?? '', description_markeddown: '', editors: [], modified: '', @@ -148,7 +153,11 @@ export async function resolveSnapshotCharts( return { charts, - positionData: swapUnreachableChartSlots(positionData, unreachable), + positionData: swapUnreachableChartSlots( + positionData, + unreachable, + unavailable, + ), }; } diff --git a/superset/translations/messages.pot b/superset/translations/messages.pot index 571e89fdcbe..6626681bad5 100644 --- a/superset/translations/messages.pot +++ b/superset/translations/messages.pot @@ -15125,6 +15125,12 @@ msgstr "" msgid "This chart has been moved to a different filter scope." msgstr "" +msgid "This chart is archived or unavailable. An editor can restore archived charts from Recently Archived." +msgstr "" + +msgid "This chart is archived or unavailable." +msgstr "" + msgid "This chart is managed externally and can't be overwritten in Superset." msgstr ""
