-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Site editor sidebar: refactor page details #51093
Conversation
- Refactors page details and the useSelect callbacks - Rolls back the generic data list components since we don't need them anywhere else (premature optimization)
Size Change: +155 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
Outdated
Show resolved
Hide resolved
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.
Thanks for the follow-up @ramonjd! Just left a totally non-blocking comment about the getPageDetails
function and whether it could be removed. Feel free to ignore, as I think it mostly comes down to a code style preference one way or another. This change is all testing nicely for me:
✅ Draft, published, scheduled, and private pages are all displaying correctly, and the details fields all appear to display as on trunk
to me
✅ The useSelect
usage in SidebarNavigationScreenPage
and PageDetails
looks cleaner now, without nested objects 👍
✅ Reverted getMediaDetails
appears to be restored correctly, and the featured image behaviour in the sidebar in the editor looks correct
LGTM! ✨
{ getPageDetails( { | ||
parentTitle, | ||
templateTitle, | ||
...record, | ||
} ).map( ( { label, value } ) => ( |
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.
Not a blocker for this PR, as I think this PR already rearranges things quite nicely, but I was wondering if having a separate getPageDetails
function is necessary if we have a PageDetails
component?
Another way to write it could be to have some sub-components like DetailRow
and DetailLabel
and DetailValue
(still in the same file), and then instead of iterating over the results of the imperative getPageDetails
, we could compose the structure of the page details directly with React components?
Perhaps something like:
<DetailsRow>
<DetailsLabel>{ __( 'Status' ) }</DetailsLabel>
<DetailsValue>...</DetailsValue>
</DetailsRow>
{ !! page?.templateTitle && (
<DetailsRow>
<DetailsLabel>{ __( 'Template' ) }</DetailsLabel>
<DetailsValue>{ decodeEntities( page.templateTitle ) }</DetailsValue>
</DetailsRow>
) }
...
I wouldn't worry about it at all for this PR, and it quite possibly comes down to personal preference — personally, I find reading the React-ey output a little easier to follow than reading the constructed array in getPageDetails
, but this is pretty nit-picky, so do feel free to ignore 😄
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.
Thanks for the review, and for thinking about how to refactor the details.
Yeah, now that you've written it out that way, I tend to agree it's easier to grok where there are components.
I'm not sure yet, but I believe that templates/template parts may get the same details treatment as pages. If that occurs then there might be an obvious path for optimization according to the way you've described.
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 not sure yet, but I believe that templates/template parts may get the same details treatment as pages. If that occurs then there might be an obvious path for optimization according to the way you've described.
Absolutely, I think it's perfectly fine to wait until there's a clearer path for subsequent usage 👍
Thank you Ramon for the follow up! |
* - Rolls back exposing getMedia details from the editor package - Refactors page details and the useSelect callbacks - Rolls back the generic data list components since we don't need them anywhere else (premature optimization) * - Ensuring last modified is visible * Use `availableTemplates` from editor settings to fetch template title using slug * Checking for templateSlug before performing a find * Whoops forgot to extract props from featuredMedia object in useSelect.
What?
The redesign for the site editor sidebar's individual page details were introduced in #50767.
This PR refactors the code by:
getMediaDetails
from the editor package and using fetched attachment media props insteadKudos to @youknowriad and @ntsekouras for raising most of these improvements
Why?
useSelect
is returning only what the components needs and doesn't return__()
Testing Instructions
There should be no regressions.
Screenshots
Trunk
This PR