-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Pages: update useView
logic
#63889
Pages: update useView
logic
#63889
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: -57 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
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'm getting a crash when oppening the pages list, I think it is because the setView is defined after being used in the effects.
4bf53ef
to
9dfc39d
Compare
I've updated this PR based on this slack thread. In addition to prevent view config resets when the layout changes, this PR also changes user behavior: when selecting one of the default views, the layout is reset to the preferred by the default view. This change will need to be done in Templates & Patterns as well. I haven't yet tested the custom views, but wanted to share what I have for thoughts. |
}, | ||
], | ||
}, | ||
return [ |
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.
The main change here is removing the [ postType ]
key.
icon: trash, | ||
view: { | ||
...DEFAULT_POST_BASE, | ||
type: LAYOUT_TABLE, |
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 also added type
and layout
to this default view, to account for switching the trash view to the table layout. This was previously done with the useSwitchToTableOnTrash
hook.
const { params } = history.getLocationWithParams(); | ||
history.push( { | ||
...params, | ||
layout: defaultView.type, |
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.
For me ideally, this should not be necessary. I think the "layout" argument in the url should be removed from the links instead.
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.
mmm, I'm not sure I follow: don't we need to make sure the layout reflects the view type? Or are you saying that you don't want the layout URL when the view type is list?
Note we need to update the layout when a new default/custom is loaded. This was a source of complexity/bugs: in trunk, the trash view has its own custom hook for this and custom views that use a layout different than list
don't load properly.
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 pushed 6958d22 to make it work like trunk.
If there's no layout URL param (first time the Pages page loads) and the view.type is list, the URL param won't be updated. Note that, like trunk, once the layout param is present (user changes layout in dataviews, user changes to a default/custom view with a view.type different than list, etc.), it'll stay there even if the user changes back to list.
9dfc39d
to
d46406f
Compare
* When going out of the trash view, it switches back to the previous layout if | ||
* there was an automatic switch to table layout. | ||
*/ | ||
function useSwitchToTableOnTrash() { |
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.
This is removed, we don't want specific logic to any default/custom view. They all should work the same, see slack thread in core-editor channel.
Both default & custom views work now with latest code changes. This is how it works:
To cover all use cases, I essentially rewrote the |
Marked some old conversations as resolved because the implementation changed significantly. |
e7c1564
to
7047e49
Compare
useView
logic
} | ||
|
||
if ( newView ) { | ||
setViewWithUrlUpdate( newView ); |
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 when we switch to a custom view, as here we call setViewWithUrlUpdate which has this code if ( isCustom === 'true' && editedEntityRecord?.id ) { editEntityRecord(
, we will endup calling get editEntityRecord just because of loading the view which may trigger a rerender. Not a big issue.
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.
That's right. I've looked at this but don't see a way to improve it at the moment. Custom views are an experimental feature and this isn't a big issue, so I'll go ahead with this PR anyway because it provides a lot of value.
I'd be happy to pair/look at this in a follow-up.
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.
Works as advertised following what was discussed in the core-editor channel. It could be merged when the end to end tests are updated and passing 👍
7047e49
to
272d355
Compare
Pushed changes to address all feedback and fix the e2e tests. I've set this to auto-merge. |
@@ -438,9 +438,7 @@ test.describe( 'Site Editor Performance', () => { | |||
await Promise.all( | |||
Array.from( { length: perPage }, async ( el, index ) => { | |||
return await page | |||
.getByRole( 'link', { |
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.
This test assumed the page was using the table
layout, which was the active one when the Trash view was loaded — and remained so. This PR changes that behavior and always loads the layout associated with the default view, hence at this point the layout will be list.
The test failed because the Pages are links in the table layout but they are not in the list layout.
There was an issue with this PR that I'm fixing at #64306 |
Alternative to #63854
Raised at #63203 (comment)
What?
This PR updates the
useView
hook to do the following:layout-changes-do-not-alter-view-config.mov
views-reset-previous-view-config.mov
list
, no matter the custom view layout.load-custom-view-layout.mov
http://localhost:8888/wp-admin/site-editor.php?postType=page&activeView=wrong-key
wrong-key.mov
Testing Instructions
Verify those work as expected and test default/custom views in general.