-
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
base: trunk
Are you sure you want to change the base?
Conversation
5a5a7e9
to
86b2e8f
Compare
Size Change: +386 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 2a04ba1. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11683420405
|
77c8204
to
69c3d6d
Compare
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
} ); | ||
} ); | ||
|
||
describe( '__experimentalGetTemplateInfo', () => { |
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 created the same unit tests for the getTemplateInfo
function: 2a04ba1
Marking this PR as ready for review. Looking forward to your feedback! |
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. |
{ | ||
since: '6.7', | ||
alternative: | ||
"select('core/core-data').getEntityRecord( 'root', '__unstableBase' )?.default_template_part_areas", |
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.
Technically, missing the last piece of the logic:
areas.map( ( item ) => {
return { ...item, icon: getTemplatePartIcon( item.icon ) };
} );
Not sure if I should add this line under the alternative key or simply remove it altogether.
I don't think the It also needs to be clarified to me why this change is needed. Maybe you can expand on that in the PR description or link an issue that has been discussed. Have we considered the |
Thanks for the comment! I updated the PR description explaining why this PR is necessary. Happy to provide more context if needed.
Not really. If you think that it makes sense, I could explore this path! |
@Mamaduka I suggested this approach, see here #65390 (comment) What would be the right endpoint for you for these general filtrable non editable settings ? I can't think of better than the index personally. |
For me the templates endpoint is specific to a post type, so it doesn't really make sense unless we make two API calls, one for template parts and one for templates. That would work for me but it adds more endpoints to preload, while the index endpoint is already preloaded and feels like a good place for some global uneditable settings. |
The index is available to every consumer, and that's one reason Core recommends exposing only a small amount of data about the site. I don't see how default template types and template part areas are relative in this context. IIRC, the only reason we made Logo/Icon available was the lack of proper read capabilities for those settings. The read-only block editor settings REST API endpoint has been mentioned several times. I can find the PRs now, but I remember the most recent discussion between @youknowriad and @TimothyBJacobs. Maybe it's time to invest in this long-term solution. |
Yes, it's a mobile specific endpoint basically only available in the Gutenberg plugin for now. That said, what I want to avoid is an "editor settings" endpoint personally. I don't see these things as "editor" settings, they are "WordPress settings" for me. |
default template and template parts are just titles and descriptions, so being available to everyone is not really an issue IMO but I can see the point. So what would be the ideal solution knowing:
Can we add these to |
I also want us to avoid getting stuck here, so let's think about a path forward that everyone can agree with. |
Then, maybe we can improve the existing P.S. Just saw the latest comments; it seems we're on the same page :)
100%. |
I would love some agreement on the direction here before we actually lose time bike shedding and implementing things that won't be agreed upon. So would love input from @TimothyBJacobs and others. The existing PR you shared @Mamaduka seems about settings that are saved to "site options". As I explained above, this is not the case for the settings that this PR is considering. These are just php filterable static values. The user doesn't update these. So if we are to add these to the "settings" endpoint, they can only be added adhoc if I'm not wrong. not need for generic settings registration or things like that. We could just hard code them in the endpoints no? |
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