diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index 041d803baad12..9ac93b97b08d3 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -856,7 +856,7 @@ export class Embeddable this.updateInput({ attributes: attrs, savedObjectId }); } - async openConfingPanel( + async openConfigPanel( startDependencies: LensPluginStartDependencies, isNewPanel?: boolean, deletePanel?: () => void diff --git a/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action.test.tsx b/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action.test.tsx index 13c0bcb23e562..e9daa06b9ac07 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action.test.tsx +++ b/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action.test.tsx @@ -95,7 +95,7 @@ describe('open config panel action', () => { }; }, getIsEditable: () => true, - openConfingPanel: jest.fn().mockResolvedValue(Lens Config Panel Component), + openConfigPanel: jest.fn().mockResolvedValue(Lens Config Panel Component), getRoot: () => { return { openOverlay: jest.fn(), diff --git a/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action_helpers.ts b/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action_helpers.ts index 20378c33bf33a..ae7bd559d9d14 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action_helpers.ts +++ b/x-pack/plugins/lens/public/trigger_actions/open_lens_config/edit_action_helpers.ts @@ -6,9 +6,10 @@ */ import React from 'react'; import './helpers.scss'; -import { tracksOverlays } from '@kbn/presentation-containers'; -import { IEmbeddable } from '@kbn/embeddable-plugin/public'; import { toMountPoint } from '@kbn/react-kibana-mount'; +import { tracksOverlays } from '@kbn/presentation-containers'; +import type { IEmbeddable } from '@kbn/embeddable-plugin/public'; +import { ViewMode } from '@kbn/embeddable-plugin/common'; import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; import { isLensEmbeddable } from '../utils'; import type { LensPluginStartDependencies } from '../../plugin'; @@ -24,10 +25,60 @@ interface Context extends StartServices { export async function isEditActionCompatible(embeddable: IEmbeddable) { if (!embeddable?.getInput) return false; // display the action only if dashboard is on editable mode - const inDashboardEditMode = embeddable.getInput().viewMode === 'edit'; + const inDashboardEditMode = embeddable.getInput().viewMode === ViewMode.EDIT; return Boolean(isLensEmbeddable(embeddable) && embeddable.getIsEditable() && inDashboardEditMode); } +type PanelConfigElement = React.ReactElement void }>; + +const openInlineLensConfigEditor = ( + startServices: StartServices, + embeddable: IEmbeddable, + EmbeddableInlineConfigEditor: PanelConfigElement +) => { + const rootEmbeddable = embeddable.getRoot(); + const overlayTracker = tracksOverlays(rootEmbeddable) ? rootEmbeddable : undefined; + + const handle = startServices.overlays.openFlyout( + toMountPoint( + React.createElement(function InlineLensConfigEditor() { + React.useEffect(() => { + document.body.style.overflowY = 'hidden'; + + return () => { + document.body.style.overflowY = 'initial'; + }; + }, []); + + return React.cloneElement(EmbeddableInlineConfigEditor, { + closeFlyout: () => { + overlayTracker?.clearOverlays(); + handle.close(); + }, + }); + }), + startServices + ), + { + size: 's', + type: 'push', + paddingSize: 'm', + 'data-test-subj': 'customizeLens', + className: 'lnsConfigPanel__overlay', + hideCloseButton: true, + onClose: (overlayRef) => { + overlayTracker?.clearOverlays(); + overlayRef.close(); + }, + outsideClickCloses: true, + } + ); + + overlayTracker?.openOverlay(handle, { + focusedPanelId: embeddable.id, + }); +}; + export async function executeEditAction({ embeddable, startDependencies, @@ -39,35 +90,10 @@ export async function executeEditAction({ if (!isCompatibleAction || !isLensEmbeddable(embeddable)) { throw new IncompatibleActionError(); } - const rootEmbeddable = embeddable.getRoot(); - const overlayTracker = tracksOverlays(rootEmbeddable) ? rootEmbeddable : undefined; - const ConfigPanel = await embeddable.openConfingPanel(startDependencies, isNewPanel, deletePanel); + + const ConfigPanel = await embeddable.openConfigPanel(startDependencies, isNewPanel, deletePanel); if (ConfigPanel) { - const handle = startServices.overlays.openFlyout( - toMountPoint( - React.cloneElement(ConfigPanel, { - closeFlyout: () => { - if (overlayTracker) overlayTracker.clearOverlays(); - handle.close(); - }, - }), - startServices - ), - { - className: 'lnsConfigPanel__overlay', - size: 's', - 'data-test-subj': 'customizeLens', - type: 'push', - paddingSize: 'm', - hideCloseButton: true, - onClose: (overlayRef) => { - if (overlayTracker) overlayTracker.clearOverlays(); - overlayRef.close(); - }, - outsideClickCloses: true, - } - ); - overlayTracker?.openOverlay(handle, { focusedPanelId: embeddable.id }); + openInlineLensConfigEditor(startServices, embeddable, ConfigPanel); } }