From 6d9159e0b3d8ef868e3b6be29408d8e5468f7fe5 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Mon, 26 Apr 2021 15:36:28 -0400 Subject: [PATCH] Fixed copyTo by only copying explicit input (#98083) --- .../actions/copy_to_dashboard_modal.tsx | 18 +++++++++++++++--- .../functional/apps/dashboard/copy_panel_to.ts | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/plugins/dashboard/public/application/actions/copy_to_dashboard_modal.tsx b/src/plugins/dashboard/public/application/actions/copy_to_dashboard_modal.tsx index cda2f7693062..77b136de9d7c 100644 --- a/src/plugins/dashboard/public/application/actions/copy_to_dashboard_modal.tsx +++ b/src/plugins/dashboard/public/application/actions/copy_to_dashboard_modal.tsx @@ -25,8 +25,13 @@ import { import { DashboardCopyToCapabilities } from './copy_to_dashboard_action'; import { LazyDashboardPicker, withSuspense } from '../../services/presentation_util'; import { dashboardCopyToDashboardAction } from '../../dashboard_strings'; -import { EmbeddableStateTransfer, IEmbeddable } from '../../services/embeddable'; -import { createDashboardEditUrl, DashboardConstants } from '../..'; +import { + EmbeddableStateTransfer, + IEmbeddable, + PanelNotFoundError, +} from '../../services/embeddable'; +import { createDashboardEditUrl, DashboardConstants, DashboardContainer } from '../..'; +import { DashboardPanelState } from '..'; interface CopyToDashboardModalProps { capabilities: DashboardCopyToCapabilities; @@ -53,9 +58,16 @@ export function CopyToDashboardModal({ ); const onSubmit = useCallback(() => { + const dashboard = embeddable.getRoot() as DashboardContainer; + const panelToCopy = dashboard.getInput().panels[embeddable.id] as DashboardPanelState; + if (!panelToCopy) { + throw new PanelNotFoundError(); + } const state = { - input: omit(embeddable.getInput(), 'id'), type: embeddable.type, + input: { + ...omit(panelToCopy.explicitInput, 'id'), + }, }; const path = diff --git a/test/functional/apps/dashboard/copy_panel_to.ts b/test/functional/apps/dashboard/copy_panel_to.ts index 9abdc2ceffc0..641d520801c4 100644 --- a/test/functional/apps/dashboard/copy_panel_to.ts +++ b/test/functional/apps/dashboard/copy_panel_to.ts @@ -91,6 +91,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.dashboard.expectOnDashboard(`Editing ${fewPanelsTitle}`); const newPanelCount = await PageObjects.dashboard.getPanelCount(); expect(newPanelCount).to.be(fewPanelsPanelCount + 1); + + // Save & ensure that view mode is applied properly. + await PageObjects.dashboard.clickQuickSave(); + await testSubjects.existOrFail('saveDashboardSuccess'); + + await PageObjects.dashboard.clickCancelOutOfEditMode(); + const panelOptions = await dashboardPanelActions.getPanelHeading(markdownTitle); + await dashboardPanelActions.openContextMenu(panelOptions); + await dashboardPanelActions.expectMissingEditPanelAction(); }); it('does not show the current dashboard in the dashboard picker', async () => {