[Discover] Add unsaved changes modal (#218500)#225252
[Discover] Add unsaved changes modal (#218500)#225252AlexGPlay merged 15 commits intoelastic:mainfrom
Conversation
| const tabs = runtimeStateManager.tabs.byId; | ||
| const hasAnyUnsavedTab = Object.values(tabs).some((tab) => { | ||
| const stateContainer = tab.stateContainer$.getValue(); | ||
| if (!stateContainer) { | ||
| return false; | ||
| } | ||
|
|
||
| return stateContainer.savedSearchState.getHasChanged$().getValue(); | ||
| }); | ||
|
|
||
| if (!hasAnyUnsavedTab) return actions.default(); | ||
|
|
||
| return actions.confirm( | ||
| i18n.translate('discover.confirmModal.confirmTextDescription', { | ||
| defaultMessage: 'Leaving Discover without saving may result in lost changes.', | ||
| }), | ||
| i18n.translate('discover.confirmModal.title', { | ||
| defaultMessage: 'Unsaved changes', | ||
| }) | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Thx @AlexGPlay , so this already works for tabs, which is great, but I guess this could also be tied to
TABS_ENABLED?
or, it should just be tied getHasChanged$()., but then it would work out of the box for Discover, something we could consider
interested in hearing your opinion @elastic/kibana-data-discovery 🙏
There was a problem hiding this comment.
It looks like the current logic would work both when tabs are and aren't enabled, which is great. But whether or not we want to enable it before tabs are released is a separate product question. If we don't want to enable it until then, we could definitely throw in a TABS_ENABLED condition.
There was a problem hiding this comment.
FYI @ninoslavmiskovic this is a feature of tabs, we could already release, warning the users that they might loose there changes when leaving Discover. With our "Single" tab mode, there's less to loose, but still. wdyt
a) Yes, let's use it already
b) No, let's use it when tabs is enabled
c) Let's discuss it on Monday, after the beach party with the flaky ones
There was a problem hiding this comment.
a) it seems risk free and good ux.
Just so I understand this is only for dirty state of a Discover session ?
Not general ad-hoc data exploration? If yes then a) .
Just want to make sure we do not annoy existing scratch pad / ad hoc explores.
There was a problem hiding this comment.
Great, let's make the final call in our Monday sync then. I won't be there, but I'm happy with whatever the team decides.
++ to the "only for dirty state" comment. I haven't tested locally to confirm it works that way, but that should be a requirement.
Two questions to consider since I won't be in Monday:
- Should we offer a third button to quickly open the save modal and reduce friction, e.g. "Cancel" / "Save my session" / "Continue without saving"? Again, probably need copy input for title/body/buttons.
- Should we offer a "Don't ask me again" checkbox for users who find it annoying / don't care, similar to the ES|QL -> classic mode modal?
Might even be worth referring to the ES|QL modal for inspiration:

There was a problem hiding this comment.
There was a problem hiding this comment.
@kertal I agree with following the EUI guidelines. In this case, we'd need to update the ES|QL and Lens modals as well. We'll also need to align in the color of the button and the use (or not) of icons. Also, in the screenshot from EUI, I would make Leave anyway a danger action.
There was a problem hiding this comment.
I've been taking a look at this and there are a couple of things here:
- With the current tools that
onAppLeaveprovides we can't do the "Don't ask me again" checkbox because it provides very limited functionality, pretty much a yes/no question and that's it. Hooking up our own component here isn't doable right now either. - This confirmation modal kind of works the opposite as we want, it only allows for actions when the user stays in the page but no when leaving it. What I mean is that we can't have a
Save changesthat saves the changes and leaves the page. It's pretty much the opposite, like "Stay and save" or "Leave the page"
There was a problem hiding this comment.
thank you @AlexGPlay , So think we need to decide the following due to the limitations:
Should we move forward with the given approach as a first step?
I think what we are discussing here needs a separate issue, will involve more teams, and it's something we should do, but currently, as @AlexGPlay mentions we are limited in this area. We can't provide a custom onAppLeave experience, which would in our case similar like when users want to open new discover sessions, and they are warned they have unsaved changes.
interested in hearing the teams opinion 🙏
There was a problem hiding this comment.
Hmm yeah that definitely has an impact on our plans, thanks for looking into it @AlexGPlay. I agree for the scope of this PR we don't have much choice but to work with what's available to us for now. We can definitely follow up after and see if we can enhance this since I think there's value in offering more than what's possible currently, but even the more limited experience is an improvement on what we have today.
a32106f to
3562306
Compare
7cbe949 to
f2a3e69
Compare
|
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
davismcphee
left a comment
There was a problem hiding this comment.
Code changes look good overall and it worked well when testing! Just left a bit of feedback.
There was a problem hiding this comment.
Thanks for updating these tests to RTL!
src/platform/plugins/shared/discover/public/application/main/discover_main_route.test.tsx
Show resolved
Hide resolved
src/platform/plugins/shared/discover/public/application/main/discover_main_route.test.tsx
Outdated
Show resolved
Hide resolved
src/platform/plugins/shared/discover/public/application/main/discover_main_route.tsx
Show resolved
Hide resolved
| return actions.confirm( | ||
| i18n.translate('discover.confirmModal.confirmTextDescription', { | ||
| defaultMessage: 'Leaving Discover without saving may result in lost changes.', | ||
| }), | ||
| i18n.translate('discover.confirmModal.title', { | ||
| defaultMessage: 'Unsaved changes', | ||
| }) | ||
| ); | ||
| }); |
There was a problem hiding this comment.
@florent-leborgne Could we get a quick copy check on this? We're a bit limited in what we can do with the modal technically since it's managed by code outside of Discover, basically a "yes, leave" or "no, stay" choice for the user. We can only customize the title, body, and confirm button text + colour.
The caveat is that they're not guaranteed to lose their changes (depends on if they navigate to another Discover link before returning), but there's a chance they will if they don't save. This is what it currently looks like:

And the Lens one for comparison:

I know there was some discussion about making broader changes to the various confirmation modals, but we're aiming to keep this PR scoped to just this Discover modal for now.
There was a problem hiding this comment.
Thanks @florent-leborgne, I think that works for now and is an improvement over what we had before. There might be a bit more nuance to consider here, but not worth me holding up the PR over. @AlexGPlay Could you please implement these changes in the PR?
CC @ninoslavmiskovic for awareness. We may want to discuss more and clarify the messaging here, but we can merge this for now and do any necessary changes in a small followup PR if needed.
.../shared/discover/public/application/main/state_management/redux/mocks/runtime_state.mocks.ts
Show resolved
Hide resolved
aaa0dab to
535000c
Compare
| return actions.confirm( | ||
| i18n.translate('discover.confirmModal.confirmTextDescription', { | ||
| defaultMessage: 'Leaving Discover without saving may result in lost changes.', | ||
| }), | ||
| i18n.translate('discover.confirmModal.title', { | ||
| defaultMessage: 'Unsaved changes', | ||
| }) | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Thanks @florent-leborgne, I think that works for now and is an improvement over what we had before. There might be a bit more nuance to consider here, but not worth me holding up the PR over. @AlexGPlay Could you please implement these changes in the PR?
CC @ninoslavmiskovic for awareness. We may want to discuss more and clarify the messaging here, but we can merge this for now and do any necessary changes in a small followup PR if needed.
There was a problem hiding this comment.
Thanks for adding functional tests 👍
There was a problem hiding this comment.
I won't hold up merging the PR over it, but I still don't like the idea of maintaining dedicated mocks for things when the real implementations are readily available, and in general would encourage us to use the real implementations whenever possible. It can help isolate the test logic, but pulls it further away from the actual runtime behaviour which is more important IMO.
17dccfb to
0fe671d
Compare
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
Public APIs missing exports
Page load bundle
History
cc @AlexGPlay |
## Summary Closes elastic#218500 When there are unsaved changes in Discover a modal will prompt the user to either risk losing them or not leaving the page. https://github.com/user-attachments/assets/c516b3a7-0954-496b-8494-574ba8547d27 ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
## Summary Closes elastic#218500 When there are unsaved changes in Discover a modal will prompt the user to either risk losing them or not leaving the page. https://github.com/user-attachments/assets/c516b3a7-0954-496b-8494-574ba8547d27 ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>



Summary
Closes #218500
When there are unsaved changes in Discover a modal will prompt the user to either risk losing them or not leaving the page.
unsaved.changes.modal.mov
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:*label is applied per the guidelines