diff --git a/src/plugins/dashboard/public/dashboard_app/top_nav/use_dashboard_menu_items.tsx b/src/plugins/dashboard/public/dashboard_app/top_nav/use_dashboard_menu_items.tsx index b107a82bdaa33..2c9d5db938962 100644 --- a/src/plugins/dashboard/public/dashboard_app/top_nav/use_dashboard_menu_items.tsx +++ b/src/plugins/dashboard/public/dashboard_app/top_nav/use_dashboard_menu_items.tsx @@ -156,7 +156,10 @@ export const useDashboardMenuItems = ({ iconType: 'pencil', testId: 'dashboardEditMode', className: 'eui-hideFor--s eui-hideFor--xs', // hide for small screens - editing doesn't work in mobile mode. - run: () => dispatch(setViewMode(ViewMode.EDIT)), + run: () => { + dashboardContainer.clearOverlays(); + dispatch(setViewMode(ViewMode.EDIT)); + }, } as TopNavMenuData, quickSave: { diff --git a/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_panel/customize_panel_action.tsx b/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_panel/customize_panel_action.tsx index e232d2e4e54ef..ec6c2011ca53d 100644 --- a/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_panel/customize_panel_action.tsx +++ b/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_panel/customize_panel_action.tsx @@ -7,9 +7,8 @@ */ import React from 'react'; -import { Subject } from 'rxjs'; import { i18n } from '@kbn/i18n'; -import { OverlayStart, ThemeServiceStart } from '@kbn/core/public'; +import { OverlayRef, OverlayStart, ThemeServiceStart } from '@kbn/core/public'; import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; import { TimeRange } from '@kbn/es-query'; @@ -29,6 +28,15 @@ const VISUALIZE_EMBEDDABLE_TYPE = 'visualization'; type VisualizeEmbeddable = IEmbeddable<{ id: string }, EmbeddableOutput & { visTypeName: string }>; +interface TracksOverlays { + openOverlay: (ref: OverlayRef) => void; + clearOverlays: () => void; +} + +function tracksOverlays(root: unknown): root is TracksOverlays { + return Boolean((root as TracksOverlays).openOverlay && (root as TracksOverlays).clearOverlays); +} + function isVisualizeEmbeddable( embeddable: IEmbeddable | VisualizeEmbeddable ): embeddable is VisualizeEmbeddable { @@ -100,11 +108,9 @@ export class CustomizePanelAction implements Action throw new IncompatibleActionError(); } - const closed$ = new Subject(); - const close = () => { - closed$.next(true); - handle.close(); - }; + // send the overlay ref to the root embeddable if it is capable of tracking overlays + const rootEmbeddable = embeddable.getRoot(); + const overlayTracker = tracksOverlays(rootEmbeddable) ? rootEmbeddable : undefined; const handle = this.overlays.openFlyout( toMountPoint( @@ -113,7 +119,10 @@ export class CustomizePanelAction implements Action timeRangeCompatible={this.isTimeRangeCompatible({ embeddable })} dateFormat={this.dateFormat} commonlyUsedRanges={this.commonlyUsedRanges} - onClose={close} + onClose={() => { + if (overlayTracker) overlayTracker.clearOverlays(); + handle.close(); + }} />, { theme$: this.theme.theme$ } ), @@ -122,5 +131,6 @@ export class CustomizePanelAction implements Action 'data-test-subj': 'customizePanel', } ); + overlayTracker?.openOverlay(handle); } }