Skip to content

Commit

Permalink
make templateAreas optional
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Nov 25, 2024
1 parent 1f47713 commit 078d2f6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 23 deletions.
6 changes: 1 addition & 5 deletions packages/edit-site/src/components/editor/use-editor-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ function useEditorTitle( postType, postId ) {
postId
);

const {
default_template_part_areas: templateAreas = [],
default_template_types: templateTypes = [],
} =
const { default_template_types: templateTypes = [] } =
select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
) ?? {};

const templateInfo = getTemplateInfo( {
template: _record,
templateAreas,
templateTypes,
} );

Expand Down
6 changes: 1 addition & 5 deletions packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,11 @@ export default function DocumentBar( props ) {
_postId
);

const {
default_template_part_areas: templateAreas = [],
default_template_types: templateTypes = [],
} =
const { default_template_types: templateTypes = [] } =
select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) ??
{};

const _templateInfo = getTemplateInfo( {
templateAreas,
templateTypes,
template: _document,
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export default function EntityRecordItem( { record, checked, onChange } ) {
key
);

const {
default_template_part_areas: templateAreas = [],
default_template_types: templateTypes = [],
} =
const { default_template_types: templateTypes = [] } =
select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
Expand All @@ -47,7 +44,6 @@ export default function EntityRecordItem( { record, checked, onChange } ) {
return {
entityRecordTitle: getTemplateInfo( {
template,
templateAreas,
templateTypes,
} ).title,
hasPostMetaChanges: unlock(
Expand Down
6 changes: 1 addition & 5 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ export default function PostCardPanel( {
postId
);

const {
default_template_part_areas: templateAreas = [],
default_template_types: templateTypes = [],
} =
const { default_template_types: templateTypes = [] } =
select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
Expand All @@ -53,7 +50,6 @@ export default function PostCardPanel( {
].includes( postType )
? getTemplateInfo( {
template: _record,
templateAreas,
templateTypes,
} )
: {};
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/utils/get-template-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const EMPTY_OBJECT = {};
* Helper function to retrieve the corresponding template info for a given template.
* @param {Object} params
* @param {Array} params.templateTypes
* @param {Array} params.templateAreas
* @param {Array} [params.templateAreas]
* @param {Object} params.template
*/
export const getTemplateInfo = ( params ) => {
Expand All @@ -32,13 +32,13 @@ export const getTemplateInfo = ( params ) => {
const templateDescription =
typeof description === 'string' ? description : description?.raw;

const templateAreasWithIcon = templateAreas.map( ( item ) => ( {
const templateAreasWithIcon = templateAreas?.map( ( item ) => ( {
...item,
icon: getTemplatePartIcon( item.icon ),
} ) );

const templateIcon =
templateAreasWithIcon.find( ( item ) => area === item.area )?.icon ||
templateAreasWithIcon?.find( ( item ) => area === item.area )?.icon ||
layout;

return {
Expand Down

0 comments on commit 078d2f6

Please sign in to comment.