[Dashboard] Fix error handling in "Save to library" modal for Links panel#231168
[Dashboard] Fix error handling in "Save to library" modal for Links panel#231168olapawlus merged 6 commits intoelastic:mainfrom
Conversation
src/platform/plugins/private/links/public/components/editor/links_editor.tsx
Show resolved
Hide resolved
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
There was a problem hiding this comment.
Thanks for opening this issue and a PR to resolve the issue. I think the current solution resolves the issue too high in the call stack, and leaves other consumers of showSaveModal vulnerable to the same problem. For example, if you try to save a map with no network connect, the save model hangs just like this issue.
So instead of solving the problem for one instance in src/platform/plugins/private/links/public/content_management/save_to_library.tsx, lets solve the problem for all users and make showSaveModal more robust by putting the try/catch around onSave in src/platform/plugins/shared/saved_objects/public/save_modal/show_saved_object_save_modal.tsx
const onSaveConfirmed: MinimalSaveModalProps['onSave'] = async (...args) => {
try {
const response = await onSave(...args);
// close modal if we either hit an error or the saved object got an id
if (Boolean(isSuccess(response) ? response.id : response.error)) {
closeModal();
}
return response;
} catch(error) {
closeModal();
return { error };
}
};
Then links only needs one change, in src/platform/plugins/private/links/public/editor/get_editor_flyout.tsx, where runSaveToLibrary is called. onSaveToLibrary should throw if saveResult.error
onSaveToLibrary={async (newLinks: ResolvedLink[], newLayout: LinksLayoutType) => {
const newState = {
...initialState,
links: newLinks,
layout: newLayout,
};
if (initialState?.savedObjectId) {
const { savedObjectId, ...updateState } = newState;
await linksClient.update({
id: initialState.savedObjectId,
data: {
...updateState,
links: serializeResolvedLinks(newLinks),
},
options: { references: [] },
});
onCompleteEdit?.(newState);
closeFlyout();
} else {
const saveResult = await runSaveToLibrary(newState);
if (saveResult?.error) throw saveResult.error;
onCompleteEdit?.(saveResult);
// If saveResult is undefined, the user cancelled the save as modal and we should not close the flyout
if (saveResult) closeFlyout();
}
}}
Then if wanted, try/catch could be removed from src/platform/plugins/private/links/public/content_management/save_to_library.tsx
Thanks so much for the really helpful explanation of the pattern with returning { error } and then throwing it higher up in the code! |
d13ce7b to
92263e8
Compare
💔 Build Failed
Failed CI StepsTest Failures
Metrics [docs]Async chunks
Page load bundle
History
cc @olapawlus |
nreese
left a comment
There was a problem hiding this comment.
kibana-presentation changes LGTM
code review and tested in chrome
…anel (elastic#231168) Closes elastic#231164 When saving a Links panel to the library from the Dashboard, errors during the save process are not properly caught or displayed to the user. This PR fixes the error handling and ensures that an error toast is shown to the user. Video Demonstration of the fix: https://github.com/user-attachments/assets/a376975c-267b-401f-ad25-d493aef0c7e2
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
1 similar comment
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
…anel (elastic#231168) Closes elastic#231164 When saving a Links panel to the library from the Dashboard, errors during the save process are not properly caught or displayed to the user. This PR fixes the error handling and ensures that an error toast is shown to the user. Video Demonstration of the fix: https://github.com/user-attachments/assets/a376975c-267b-401f-ad25-d493aef0c7e2
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
5 similar comments
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
…anel (elastic#231168) Closes elastic#231164 When saving a Links panel to the library from the Dashboard, errors during the save process are not properly caught or displayed to the user. This PR fixes the error handling and ensures that an error toast is shown to the user. Video Demonstration of the fix: https://github.com/user-attachments/assets/a376975c-267b-401f-ad25-d493aef0c7e2
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
14 similar comments
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Closes #231164
When saving a Links panel to the library from the Dashboard, errors during the save process are not properly caught or displayed to the user.
This PR fixes the error handling and ensures that an error toast is shown to the user.
Video Demonstration of the fix:
Screen.Recording.2025-08-08.at.16.14.58.mov