Skip to content

Commit

Permalink
[map embeddable] fix panel disappears from dashboard when canceling e…
Browse files Browse the repository at this point in the history
…dit after dashboard save (#193911)

Part of #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
  • Loading branch information
nreese authored Sep 24, 2024
1 parent c28af87 commit 882b6fb
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions x-pack/plugins/maps/public/react_embeddable/initialize_edit_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
};
};
}

0 comments on commit 882b6fb

Please sign in to comment.