-
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
Template Parts: Avoid duplicate names on conversion from group of blocks #47082
Template Parts: Avoid duplicate names on conversion from group of blocks #47082
Conversation
…le is unique on conversion.
Size Change: +7 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in 376faba. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3895396872
|
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 testing well, and nice work grouping together the utility functions logically in utils/template-part-create.js
, that looks like a good approach to me! ✨
I think I just found a subtle issue when we go to create a duplicate template part when the template part we're matching against hasn't had any user changes — apologies, I didn't catch this in the initial testing, since I'd been using a theme I've made lots of changes to! Looks like it's a pretty small change to tidy it up, so I've opened up a follow-up PR in #47128 |
*/ | ||
export const getCleanTemplatePartSlug = ( title ) => { | ||
return kebabCase( title ).replace( /[^\w-]+/g, '' ) || 'wp-custom-part'; | ||
}; |
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.
These three would be great functions to unit test.
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.
Sounds good, I'll look at figuring this out 👍
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.
PR for tests #47224
Follow up to #46996
What?
When selecting a group of blocks and the using "Create template part" from the menu, make sure that the name used for the template part in the modal is not a duplicate. This matches with the functionality in #46996.
Why?
Original issue is #42473
How?
Since creation and conversion of template parts is two different components, I've taken the liberty of moving shared functionality to the
utils
directory. Open to thoughts on whether this is the right place?Testing Instructions
Screenshots or screencast