-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
DataViews: Update template parts view #57952
Conversation
Size Change: -257 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
packages/edit-site/src/components/page-template-parts/dataviews-template-parts.js
Outdated
Show resolved
Hide resolved
c254161
to
1c2ddaa
Compare
packages/edit-site/src/components/page-templates-template-parts/index.js
Outdated
Show resolved
Hide resolved
}, | ||
}; | ||
if ( item.type === TEMPLATE_PART_POST_TYPE ) { | ||
linkProps.state = { |
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 haven't seen this in use, what is it for? I presume it's for setting the path in case the users click the browser's back button after they've gone to the editor by clicking the title. Is this correct? If so, why templates don't need this?
isTemplateRemovable( template ) && template.is_custom, | ||
isEligible: ( template ) => { | ||
if ( | ||
! isTemplateRemovable( template ) || |
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 found this logic difficult to grok. What would you think of rewriting it by stating the conditions for each post type independently? Something along these lines could work:
if (
template.type === TEMPLATE_PART_POST_TYPE &&
isTemplateRemovable( template )
) {
return true;
}
if (
template.type === TEMPLATE_POST_TYPE &&
isTemplateRemovable( template) &&
template.is_custom
) {
return true;
}
return false;
); | ||
} else { | ||
successMessage = __( 'Templates deleted.' ); | ||
successMessage = isTemplate | ||
? __( 'Templates deleted.' ) |
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 mentioned this elsewhere, but I think we could do with using a generic language. For example, Items deleted.
.
The users already have the context of what they are – they know whether they are working with templates or template parts, don't need reminding. And this code would be a lot simpler.
I don't have a strong opposition to doing it this way, and it works fine. I just want to share an alternative that I find clearer for everyone.
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 agree with this and would need less code :). Le't handle this in a follow up though because others might chip in about the clarity of the messages and wouldn't want to block this PR for that.
packages/edit-site/src/components/page-templates-template-parts/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.
I found an issue to fix (details) and left a couple of comments for clarification. Other than that, this is working great 👏
e7c4350
to
ce2a55b
Compare
ce2a55b
to
3cd08ff
Compare
What?
Part of: #55083
This PR updates the template parts list in site editor to use DataViews. Since templates and template parts have almost identical handling I've created a thin DataViews wrapper for both and most changes are checks about the type to use some different labels.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-01-18.at.12.09.35.PM.mov