Skip to content
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

Fix: Site Editor Template part is missing an icon in the sidebar #68653

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getEntityFields as _getEntityFields,
isEntityReady as _isEntityReady,
} from '../dataviews/store/private-selectors';
import { getTemplatePartIcon } from '../utils';

const EMPTY_INSERTION_POINT = {
rootClientId: undefined,
Expand Down Expand Up @@ -97,15 +98,21 @@ export const getPostIcon = createRegistrySelector(
postType === 'wp_template_part' ||
postType === 'wp_template'
) {
return (
(
select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
)?.default_template_part_areas || []
).find( ( item ) => options.area === item.area )?.icon ||
layout
const templateAreas =
select( coreStore ).getEntityRecord(
'root',
'__unstableBase'
)?.default_template_part_areas || [];

const areaData = templateAreas.find(
( item ) => options.area === item.area
);

if ( areaData?.icon ) {
return getTemplatePartIcon( areaData.icon );
}

return layout;
}
if ( CARD_ICONS[ postType ] ) {
return CARD_ICONS[ postType ];
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/utils/get-template-part-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
footer as footerIcon,
sidebar as sidebarIcon,
symbolFilled as symbolFilledIcon,
layout as layoutIcon,
} from '@wordpress/icons';
/**
* Helper function to retrieve the corresponding icon by name.
Expand All @@ -21,6 +22,8 @@ export function getTemplatePartIcon( iconName ) {
return footerIcon;
} else if ( 'sidebar' === iconName ) {
return sidebarIcon;
} else if ( 'layout' === iconName ) {
return layoutIcon;
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
}
return symbolFilledIcon;
}
4 changes: 2 additions & 2 deletions test/integration/fixtures/blocks/core__separator-color.json
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"isValid": true,
"attributes": {
"opacity": "alpha-channel",
"backgroundColor": "accent",
"tagName": "hr"
"tagName": "hr",
"backgroundColor": "accent"
},
"innerBlocks": []
}
Expand Down
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"isValid": true,
"attributes": {
"opacity": "alpha-channel",
"tagName": "hr",
"style": {
"color": {
"background": "#5da54c"
}
},
"tagName": "hr"
}
},
"innerBlocks": []
}
Expand Down
Loading