-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Move default template types and template part areas to REST API #66459
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
Changes from 1 commit
b795e9c
61b90b5
6aaf160
d141278
bde1d80
de703b5
f8962ce
fc95c3f
d20b8ad
d361487
afe5365
ac06843
69c3d6d
a5647de
2a04ba1
6723634
7241bad
8f47873
6acc708
7aab231
ffdcc1d
e395bf6
1f47713
078d2f6
fdc291d
b2c0bf5
8f8649b
230ba72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { decodeEntities } from '@wordpress/html-entities'; | |
| */ | ||
| import { store as editorStore } from '../../store'; | ||
| import { unlock } from '../../lock-unlock'; | ||
| import { getTemplateInfo } from '../../utils'; | ||
|
|
||
| export default function EntityRecordItem( { record, checked, onChange } ) { | ||
| const { name, kind, title, key } = record; | ||
|
|
@@ -33,11 +34,21 @@ export default function EntityRecordItem( { record, checked, onChange } ) { | |
| name, | ||
| key | ||
| ); | ||
|
|
||
| const templateAreas = | ||
| select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) | ||
| ?.defaultTemplatePartAreas || []; | ||
|
|
||
| const templateTypes = | ||
| select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) | ||
| ?.defaultTemplateTypes || []; | ||
|
|
||
| return { | ||
| entityRecordTitle: | ||
| select( editorStore ).__experimentalGetTemplateInfo( | ||
| template | ||
| ).title, | ||
| entityRecordTitle: getTemplateInfo( { | ||
| template, | ||
| templateAreas, | ||
| templateTypes, | ||
| } ).title, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new If we decide to go in this direction, let's update all other similar occurrences.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that you're right! I make |
||
| hasPostMetaChanges: unlock( | ||
| select( editorStore ) | ||
| ).hasPostMetaChanges( name, key ), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { layout } from '@wordpress/icons'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getTemplatePartIcon } from '.'; | ||
|
|
||
| const EMPTY_OBJECT = {}; | ||
|
|
||
| export const getTemplateInfo = ( { | ||
| templateTypes, | ||
| templateAreas, | ||
| template, | ||
| } ) => { | ||
| const { description, slug, title, area } = template; | ||
|
|
||
| const { title: defaultTitle, description: defaultDescription } = | ||
| Object.values( templateTypes ).find( ( type ) => type.slug === slug ) ?? | ||
| EMPTY_OBJECT; | ||
|
|
||
| const templateTitle = typeof title === 'string' ? title : title?.rendered; | ||
| const templateDescription = | ||
| typeof description === 'string' ? description : description?.raw; | ||
|
|
||
| const templateAreasWithIcon = templateAreas.map( ( item ) => ( { | ||
| ...item, | ||
| icon: getTemplatePartIcon( item.icon ), | ||
| } ) ); | ||
|
|
||
| const templateIcon = | ||
| templateAreasWithIcon.find( ( item ) => area === item.area )?.icon || | ||
| layout; | ||
|
|
||
| return { | ||
| title: | ||
| templateTitle && templateTitle !== slug | ||
| ? templateTitle | ||
| : defaultTitle || slug, | ||
| description: templateDescription || defaultDescription, | ||
| icon: templateIcon, | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ import mediaUpload from './media-upload'; | |
| export { mediaUpload }; | ||
| export { cleanForSlug } from './url.js'; | ||
| export { getTemplatePartIcon } from './get-template-part-icon'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's funny that we already have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are the same 😁, but I don't think that we can import
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, I think most of these belong in |
||
| export { getTemplateInfo } from './get-template-info'; | ||
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.
If this is a private API, why the doc is being added here. It might be that it's exported publicly as well.
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.
Good catch! Fixed with 1f47713