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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -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 } = | ||
|
@@ -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
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've refactored the return values a bit. The |
||
}, [] ); | ||
|
||
if ( ! title && ! description ) { | ||
|
@@ -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 } /> } | ||
> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we always use the
Icon
suffix, or can we omit it when there's no name collision?