-
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
Move default template types and template part areas to REST API #66459
Conversation
5a5a7e9
to
86b2e8f
Compare
Size Change: +358 B (+0.02%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
86b2e8f
to
95d6d1c
Compare
7b905f6
to
5b83ef7
Compare
export const __experimentalGetDefaultTemplatePartAreas = createRegistrySelector( | ||
( select ) => | ||
createSelector( () => { | ||
const areas = | ||
select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) | ||
?.defaultTemplatePartAreas || []; | ||
|
||
return areas.map( ( item ) => { | ||
return { ...item, icon: getTemplatePartIcon( item.icon ) }; | ||
} ); | ||
} ) | ||
); |
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 that we should deprecate this selector and create a dedicated hook to be reused across the codebase: what do you think?
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 definItely think this is the right approach to get these configuration objects from the server.
I'll defer to other about the details on naming, REST API conventions...
packages/core-data/src/entities.js
Outdated
@@ -31,6 +31,8 @@ export const rootEntitiesConfig = [ | |||
'site_icon_url', | |||
'site_logo', | |||
'timezone_string', | |||
'defaultTemplatePartAreas', | |||
'defaultTemplateTypes', |
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.
Looks like these are the only fields that are camelCase? should they follow the other pattern?
Do you think we can update this PR to target trunk directly (avoid all the changes related to the action)? That way we can land it first. |
Thanks! Sure! Thanks for tagging other folks! After that, I will make the changes, I will mark this PR ready to be reviewed! |
344f380
to
6aaf160
Compare
Flaky tests detected in 230ba72. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12026241537
|
const templateAreas = | ||
select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) | ||
?.default_template_part_areas || []; | ||
|
||
const templateTypes = | ||
select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) | ||
?.default_template_types || []; |
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.
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.
Fixed with e395bf6
'default_template_part_areas', | ||
'default_template_types', |
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.
Changes here also require an update to the preload path in lib/compat/wordpress-6.8/preload.php
. See the comment above the _fields
property.
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.
TIL! Thanks! fdc291d
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.
Why didn't you keep the same order?
dc78bf9
to
1f47713
Compare
745b904
to
078d2f6
Compare
@@ -0,0 +1,38 @@ | |||
<?php |
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 file name is a bit weird but it's not important. Could be rest-api.php or something.
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.
+1. I think a rest-api.php
file is already in WP 6.8 compat dir. We can move this code there.
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.
Done! b2c0bf5
Sorry for the delay, but last week I was busy with other duties! Thanks for your great review! 🙇 |
@Mamaduka I will wait for your approval before merging this PR! |
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.
It looks good to merge ✅ Thanks, @gigitux!
Should I handle backporting this change to WordPress? |
Yes. It's recommended to start backport PR as soon as possible. I think there's an even CI check for it. See https://github.com/WordPress/gutenberg/blob/trunk/backport-changelog/readme.md for additional details. |
deprecated( | ||
"select('core/editor').__experimentalGetDefaultTemplateTypes", | ||
{ | ||
since: '6.7', |
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.
shouldn't this be 6.8? (same below)
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.
Nice catch! I'm going to open a follow-up PR! Thanks 🙇
I created a backport PR: WordPress/wordpress-develop#7895. I'm not sure if I should follow these steps given that this PR has already merged. |
I think those files are used to sync backport tracking issues for a release automatically. See #62973. You could create a |
What?
This PR moves the
defaultTemplateTypes
,defaultTemplatePartAreas
to thegetEntityRecord( 'root', '__unstableBase' ) endpoint
.Given that the impacted selectors aren't specific to the
editor
store, I decided to deprecate them all. I couldn't find a suitable location to ensure accessibility across different packages, leading to some duplicated code. Should we create a@wordpress/template
package (similar to@wordpress/patterns
) to house this logic? Create a dedicated package could help us with #65390 too.Why
This PR is necessary to remove the
core/editor
dependency across the application. In the specific, this refactor is needed to allow the packagefields
to have access to thedefaultTemplateTypes
,defaultTemplatePartAreas
without that editor settings are initialized. More details here: #65390 (comment)Testing Instructions
Visit the Site Editor.
On the sidebar click on
Pattern
.Click on
All template parts
.Ensure that all the patterns are visible (you should see
Header
andFooter
labels too)On the top right, click on
Add New Pattern
.Create a new template part
Ensure that the template part is created correctly.
Visit the Site Editor.
Visit the
Blog Home
.Ensure that the right panel under the template section renders the right data:
Add a block into the footer.
Click save.
Ensure that
are you ready to save
shows the right data:Testing Instructions for Keyboard
Screenshots or screencast