This is an automated email from the ASF dual-hosted git repository. sadpandajoe pushed a commit to branch fix-dashboard-export-excludes-edit-panel in repository https://gitbox.apache.org/repos/asf/superset.git
commit fc8e3069aeb76bfadb11c5cf344edae5c753b91a Author: Joe Li <[email protected]> AuthorDate: Fri Nov 13 00:19:00 2026 +0000 fix(dashboard): disable browser-side PDF and image export in edit mode The browser-side Export to PDF and Download as Image actions capture the live .dashboard node, which also contains the builder side pane while the dashboard is being edited, so the output included the pane. Disable those two actions in edit mode. The webdriver-based exports render the saved dashboard and are unchanged, as are the Excel and YAML exports. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- .../Header/useHeaderActionsDropdownMenu.tsx | 1 + .../DownloadMenuItems/DownloadMenuItems.test.tsx | 55 ++++++++++++++++++++++ .../components/menu/DownloadMenuItems/index.tsx | 11 ++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/Header/useHeaderActionsDropdownMenu.tsx b/superset-frontend/src/dashboard/components/Header/useHeaderActionsDropdownMenu.tsx index a2812f6d056..16f04c9389e 100644 --- a/superset-frontend/src/dashboard/components/Header/useHeaderActionsDropdownMenu.tsx +++ b/superset-frontend/src/dashboard/components/Header/useHeaderActionsDropdownMenu.tsx @@ -202,6 +202,7 @@ export const useHeaderActionsMenu = ({ logEvent, userCanExport, canExportImage, + editMode, }); const reportMenuItem = useHeaderReportMenuItems({ diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx index f73c1e1880d..fc9b358f229 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx @@ -110,6 +110,7 @@ const MenuWrapper = () => { const MenuWrapperWithProps = ( overrides: Partial<ReturnType<typeof createProps>> & { canExportImage?: boolean; + editMode?: boolean; }, ) => { const downloadMenuItem = useDownloadMenuItems({ @@ -1163,3 +1164,57 @@ test('Download as Image hands the warning and info toast callbacks to downloadAs mockAddInfoToast, ); }); + +const isMenuItemDisabled = (label: string) => + screen + .getByText(label) + .closest('[role="menuitem"]') + ?.getAttribute('aria-disabled') === 'true'; + +test('Browser-side PDF and image items are disabled in edit mode and do not export', async () => { + render(<MenuWrapperWithProps editMode />, { + useRedux: true, + initialState: loggedInState, + }); + + expect(isMenuItemDisabled('Export to PDF')).toBe(true); + expect(isMenuItemDisabled('Download as Image')).toBe(true); + + await clickMenuItem('Export to PDF'); + await clickMenuItem('Download as Image'); + + expect(mockDownloadAsPdf).not.toHaveBeenCalled(); + expect(mockDownloadAsImage).not.toHaveBeenCalled(); +}); + +test.each([ + ['editMode is false', false], + ['editMode is not provided', undefined], +])( + 'Browser-side PDF and image items are enabled when %s', + async (_name, editMode) => { + render(<MenuWrapperWithProps editMode={editMode} />, { + useRedux: true, + initialState: loggedInState, + }); + + expect(isMenuItemDisabled('Export to PDF')).toBe(false); + expect(isMenuItemDisabled('Download as Image')).toBe(false); + + await clickMenuItem('Export to PDF'); + + expect(mockDownloadAsPdf).toHaveBeenCalled(); + }, +); + +test('Webdriver screenshot items stay enabled in edit mode', () => { + enableWebDriverScreenshot(); + + render(<MenuWrapperWithProps editMode canExportImage />, { + useRedux: true, + initialState: loggedInState, + }); + + expect(isMenuItemDisabled('Export to PDF')).toBe(false); + expect(isMenuItemDisabled('Download as Image')).toBe(false); +}); diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx index 82780d852a1..e8f41164c9a 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx @@ -72,6 +72,7 @@ export interface UseDownloadMenuItemsProps { disabled?: boolean; userCanExport?: boolean; canExportImage?: boolean; + editMode?: boolean; } export const useDownloadMenuItems = ( @@ -87,6 +88,7 @@ export const useDownloadMenuItems = ( title, userCanExport, canExportImage, + editMode, } = props; const dispatch = useDispatch(); @@ -419,6 +421,11 @@ export const useDownloadMenuItems = ( text ); + // The browser-side export captures the live `.dashboard` node, which also + // contains the builder pane in edit mode. The webdriver export renders the + // saved dashboard, so it is unaffected. + const browserExportBlocked = !!editMode; + const screenshotMenuItems: MenuItem[] = isWebDriverScreenshotEnabled ? [ { @@ -438,13 +445,13 @@ export const useDownloadMenuItems = ( { key: 'download-pdf', label: imageExportLabel(pdfMenuItemTitle), - disabled: imageDisabled, + disabled: imageDisabled || browserExportBlocked, onClick: (e: any) => onDownloadPdf(e.domEvent), }, { key: 'download-image', label: imageExportLabel(imageMenuItemTitle), - disabled: imageDisabled, + disabled: imageDisabled || browserExportBlocked, onClick: (e: any) => onDownloadImage(e.domEvent), }, ];
