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

Site Editor: Use the correct icon for Patterns in sidebar card #52931

Merged
merged 1 commit into from Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,7 +7,7 @@ import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';
import { navigation as navigationIcon } from '@wordpress/icons';
import { navigation, symbol } from '@wordpress/icons';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always use the Icon suffix, or can we omit it when there's no name collision?


/**
* Internal dependencies
Expand All @@ -18,11 +18,13 @@ import TemplateAreas from './template-areas';
import LastRevision from './last-revision';
import SidebarCard from '../sidebar-card';

const CARD_ICONS = {
wp_block: symbol,
wp_navigation: navigation,
};

export default function TemplatePanel() {
const {
info: { title, description, icon },
record,
} = useSelect( ( select ) => {
const { title, description, icon, record } = useSelect( ( select ) => {
const { getEditedPostType, getEditedPostId } = select( editSiteStore );
const { getEditedEntityRecord } = select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
Expand All @@ -31,10 +33,14 @@ export default function TemplatePanel() {
const postType = getEditedPostType();
const postId = getEditedPostId();
const _record = getEditedEntityRecord( 'postType', postType, postId );
const info = getTemplateInfo( _record );

const info = _record ? getTemplateInfo( _record ) : {};

return { info, record: _record };
return {
title: info.title,
description: info.description,
icon: info.icon,
record: _record,
};
Comment on lines +38 to +43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored the return values a bit. The info will never have a stable reference, so it's better to return values directly.

}, [] );

if ( ! title && ! description ) {
Expand All @@ -46,9 +52,7 @@ export default function TemplatePanel() {
<SidebarCard
className="edit-site-template-card"
title={ decodeEntities( title ) }
icon={
record?.type === 'wp_navigation' ? navigationIcon : icon
}
icon={ CARD_ICONS[ record?.type ] ?? icon }
description={ decodeEntities( description ) }
actions={ <TemplateActions template={ record } /> }
>
Expand Down