Skip to content

Commit

Permalink
[8.x] [map embeddable] fix panel disappears from dashboard when cance…
Browse files Browse the repository at this point in the history
…ling edit after dashboard save (#193911) (#193929)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[map embeddable] fix panel disappears from dashboard when canceling
edit after dashboard save
(#193911)](#193911)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-24T22:13:10Z","message":"[map
embeddable] fix panel disappears from dashboard when canceling edit
after dashboard save (#193911)\n\nPart of
#193905. Broke work
into\r\nseparate PRs to backport map embeddable changes to
8.15.\r\n\r\nResolves issue for Map embeddable. The problem is that Map
embeddable is\r\nusing a stale result from `parentApi.getAppContext`.
Dashboard's\r\n`getAppContext` changes the `getCurrentPath` when the
dashboard has a\r\nsaved object id. By using the stale results,
`getCurrentPath` returned\r\n`#/create` instead of `#/view/`.\r\n\r\n###
Test steps\r\n1. create new dashboard\r\n2. Click \"Add panel\" (problem
also exists when using \"Add from library\")\r\n3. Select \"Maps\"\r\n4.
In editor, click \"Save and return\"\r\n5. Save dashboard\r\n6. Click
\"Edit\" in panel context menu\r\n7. In editor, click \"Cancel\"\r\n8.
Ensure map panel is still displayed in
dashboard","sha":"882b6fb2f5ebef289dcbbf487ce42f83b95cc58e","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","v9.0.0","v8.16.0","backport:version","v8.15.3"],"title":"[map
embeddable] fix panel disappears from dashboard when canceling edit
after dashboard
save","number":193911,"url":"https://github.com/elastic/kibana/pull/193911","mergeCommit":{"message":"[map
embeddable] fix panel disappears from dashboard when canceling edit
after dashboard save (#193911)\n\nPart of
#193905. Broke work
into\r\nseparate PRs to backport map embeddable changes to
8.15.\r\n\r\nResolves issue for Map embeddable. The problem is that Map
embeddable is\r\nusing a stale result from `parentApi.getAppContext`.
Dashboard's\r\n`getAppContext` changes the `getCurrentPath` when the
dashboard has a\r\nsaved object id. By using the stale results,
`getCurrentPath` returned\r\n`#/create` instead of `#/view/`.\r\n\r\n###
Test steps\r\n1. create new dashboard\r\n2. Click \"Add panel\" (problem
also exists when using \"Add from library\")\r\n3. Select \"Maps\"\r\n4.
In editor, click \"Save and return\"\r\n5. Save dashboard\r\n6. Click
\"Edit\" in panel context menu\r\n7. In editor, click \"Cancel\"\r\n8.
Ensure map panel is still displayed in
dashboard","sha":"882b6fb2f5ebef289dcbbf487ce42f83b95cc58e"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193911","number":193911,"mergeCommit":{"message":"[map
embeddable] fix panel disappears from dashboard when canceling edit
after dashboard save (#193911)\n\nPart of
#193905. Broke work
into\r\nseparate PRs to backport map embeddable changes to
8.15.\r\n\r\nResolves issue for Map embeddable. The problem is that Map
embeddable is\r\nusing a stale result from `parentApi.getAppContext`.
Dashboard's\r\n`getAppContext` changes the `getCurrentPath` when the
dashboard has a\r\nsaved object id. By using the stale results,
`getCurrentPath` returned\r\n`#/create` instead of `#/view/`.\r\n\r\n###
Test steps\r\n1. create new dashboard\r\n2. Click \"Add panel\" (problem
also exists when using \"Add from library\")\r\n3. Select \"Maps\"\r\n4.
In editor, click \"Save and return\"\r\n5. Save dashboard\r\n6. Click
\"Edit\" in panel context menu\r\n7. In editor, click \"Cancel\"\r\n8.
Ensure map panel is still displayed in
dashboard","sha":"882b6fb2f5ebef289dcbbf487ce42f83b95cc58e"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nathan Reese <[email protected]>
  • Loading branch information
kibanamachine and nreese authored Sep 24, 2024
1 parent 21196a5 commit c9bfe46
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 c9bfe46

Please sign in to comment.