-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: preserve list state between form navigation #425
Conversation
✅ Deploy Preview for dhis2-maintenance-app-beta ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #425 +/- ##
==========================================
- Coverage 62.05% 60.78% -1.28%
==========================================
Files 192 207 +15
Lines 2991 3302 +311
Branches 669 733 +64
==========================================
+ Hits 1856 2007 +151
- Misses 1132 1287 +155
- Partials 3 8 +5 ☔ View full report in Codecov by Sentry. |
795c70b
to
88077f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good. Seems reasonable to use the search state and I like the effort to centralize some of the logic in useLocationSearchState.
One "drawback" with this approach is that we have to ensure that all links back and forth apply the state correctly. I've tried to "abstract" this in useLocationSearchState - but it's still up to the Link and navigation components to pass the states correctly.
Just to point out the pitfall here but the data element forms are not using the DefaultFormContents and hence do not have this updated navigation. Though, within the form, it seems pretty easy to apply this logic. If you wanted to abstract it more, I guess you could have defaultCancel or defaultSubmit actions that get extended? I guess it might depend on how much custom form logic we think we're going to implement.
I really didn't want to keep a different store (eg. context or zustan) and keep that in sync with query-params. So I decided to try out location.state
I think the approach is good. Though I guess one downside of not keeping it in a store is that you're going to lose the state if you say, navigate to Categories add some filters, navigate to Category Combos, navigate back to Categories. I assume though that the need to persist the form filtering is just while you're working on a particularly metadata object type?
Yeah, thanks! I'm aware and will push a fix. The intention is to refactor data elements at some point as well. But yeah, the other ones use
Yeah this is a good point. I have tried to gather specs, and discussed with Karoline about of the desired behaviour. And for now I think we should keep it local. |
🎉 This PR is included in version 0.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
There's been feedback from testers that it can be distruptive to loose the list state when navigating between the form and list. This PR implements enhancements to preserve the list state (eg. the query-params used to store list-filters and pagination).
Implementation details
zustan
) and keep that in sync with query-params. So I decided to try outlocation.state
.search
-params string inlocation.state
when navigating from a link that navigates to the form. This is done by passingstate
tonavigate
or as a prop toreact-router
sLink
-component.useQueryParams
the same - and we reapply it by appending the search-params to links that link back - by settingsearch: location.state.search
. The same way is done if we useuseNavigate
oruseLinkClickHandler
.useLocationSearchState
- but it's still up to the Link and navigation components to pass the states correctly.