From 4d97bf31ee6266164e8bd57e4b6788f7ab937e46 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 24 Sep 2024 16:13:10 -0600 Subject: [PATCH] [map embeddable] fix panel disappears from dashboard when canceling edit after dashboard save (#193911) Part of https://github.com/elastic/kibana/issues/193905. Broke work into separate PRs to backport map embeddable changes to 8.15. Resolves issue for Map embeddable. The problem is that Map embeddable is using a stale result from `parentApi.getAppContext`. Dashboard's `getAppContext` changes the `getCurrentPath` when the dashboard has a saved object id. By using the stale results, `getCurrentPath` returned `#/create` instead of `#/view/`. ### Test steps 1. create new dashboard 2. Click "Add panel" (problem also exists when using "Add from library") 3. Select "Maps" 4. In editor, click "Save and return" 5. Save dashboard 6. Click "Edit" in panel context menu 7. In editor, click "Cancel" 8. Ensure map panel is still displayed in dashboard (cherry picked from commit 882b6fb2f5ebef289dcbbf487ce42f83b95cc58e) --- .../react_embeddable/initialize_edit_api.ts | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/maps/public/react_embeddable/initialize_edit_api.ts b/x-pack/plugins/maps/public/react_embeddable/initialize_edit_api.ts index a9274ed41f0fb..41959c4874223 100644 --- a/x-pack/plugins/maps/public/react_embeddable/initialize_edit_api.ts +++ b/x-pack/plugins/maps/public/react_embeddable/initialize_edit_api.ts @@ -16,33 +16,30 @@ export function initializeEditApi( parentApi?: unknown, savedObjectId?: string ) { - if (!parentApi || !apiHasAppContext(parentApi)) { - return {}; - } - - const parentApiContext = parentApi.getAppContext(); - - return { - getTypeDisplayName: () => { - return MAP_EMBEDDABLE_NAME; - }, - onEdit: async () => { - const stateTransfer = getEmbeddableService().getStateTransfer(); - await stateTransfer.navigateToEditor(APP_ID, { - path: getEditPath(savedObjectId), - state: { - embeddableId: uuid, - valueInput: getState(), - originatingApp: parentApiContext.currentAppId, - originatingPath: parentApiContext.getCurrentPath?.(), + return !parentApi || !apiHasAppContext(parentApi) + ? {} + : { + getTypeDisplayName: () => { + return MAP_EMBEDDABLE_NAME; + }, + onEdit: async () => { + const parentApiContext = parentApi.getAppContext(); + const stateTransfer = getEmbeddableService().getStateTransfer(); + await stateTransfer.navigateToEditor(APP_ID, { + path: getEditPath(savedObjectId), + state: { + embeddableId: uuid, + valueInput: getState(), + originatingApp: parentApiContext.currentAppId, + originatingPath: parentApiContext.getCurrentPath?.(), + }, + }); + }, + isEditingEnabled: () => { + return getMapsCapabilities().save as boolean; + }, + getEditHref: async () => { + return getHttp().basePath.prepend(getFullPath(savedObjectId)); }, - }); - }, - isEditingEnabled: () => { - return getMapsCapabilities().save as boolean; - }, - getEditHref: async () => { - return getHttp().basePath.prepend(getFullPath(savedObjectId)); - }, - }; + }; }