-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix: Filters are reset when switching layout on the pages view. #63854
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
Fix: Filters are reset when switching layout on the pages view. #63854
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +73 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
@@ -59,10 +63,28 @@ function useView( postType ) { | |||
const [ view, setView ] = useState( selectedDefaultView ); | |||
|
|||
useEffect( () => { |
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.
What's the purpose of this effect?
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.
What happens if we just remove the effect?
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.
Ok I'm guessing this hook is about updating the "view" object when the url changes (probably for default views only). Then:
I'd suggest just using setView( previous => { some merge here } )
and only update the stuff that come from the url rather than setting the whole object. It also avoids all these usePrevious...
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 we probably don't need to compute the selectedDefaultView
variable at all. We could just initialize the useState
directly and update this hook to rely on the location params directly as well.
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.
Hi @youknowriad, this effect is what changes the view when the URL goes from ?postType=page&layout=grid&activeView=published
to ?postType=page&layout=grid&activeView=future
. The sidebar does not changes the view directly. The sidebar, just updates URL's. If we remove this effect the sidebar does not works at all.
If we agree on this solution or something similar I will add a comment with that on the effect to make it clear for the future.
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've prepared an alternative PR at #63889
Closed in favor of #63889. |
Fixes an issue noticed by @youknowriad at #63203 (comment).
Right now, on the pages list when we switch layouts the filters are reset. That happens because an effect to synchronize URL parameters with the view was not taking into account the already existing possible customizations of the view.
This PR fixes the issue.
Testing Instructions
I opened the pages list view.
I added some filters.
I switched the layout and verified the filters I added were kept.
I switched the view e.g.: to published I verified the correct published filters, were applied and the previous layout I selected was kept.