-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Inspector: Display home / posts page badge #62071
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,42 +28,52 @@ import { | |
import { unlock } from '../../lock-unlock'; | ||
|
||
export default function PostCardPanel( { actions } ) { | ||
const { title, icon, isSync } = useSelect( ( select ) => { | ||
const { | ||
getEditedPostAttribute, | ||
getCurrentPostType, | ||
getCurrentPostId, | ||
__experimentalGetTemplateInfo, | ||
} = select( editorStore ); | ||
const { getEditedEntityRecord } = select( coreStore ); | ||
const _type = getCurrentPostType(); | ||
const _id = getCurrentPostId(); | ||
const _record = getEditedEntityRecord( 'postType', _type, _id ); | ||
const _templateInfo = | ||
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes( _type ) && | ||
__experimentalGetTemplateInfo( _record ); | ||
let _isSync = false; | ||
if ( GLOBAL_POST_TYPES.includes( _type ) ) { | ||
if ( PATTERN_POST_TYPE === _type ) { | ||
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead. | ||
const currentSyncStatus = | ||
getEditedPostAttribute( 'meta' )?.wp_pattern_sync_status === | ||
'unsynced' | ||
? 'unsynced' | ||
: getEditedPostAttribute( 'wp_pattern_sync_status' ); | ||
_isSync = currentSyncStatus !== 'unsynced'; | ||
} else { | ||
_isSync = true; | ||
const { isFrontPage, isPostsPage, title, icon, isSync } = useSelect( | ||
( select ) => { | ||
const { | ||
getEditedPostAttribute, | ||
getCurrentPostType, | ||
getCurrentPostId, | ||
__experimentalGetTemplateInfo, | ||
} = select( editorStore ); | ||
const { getEditedEntityRecord } = select( coreStore ); | ||
const siteSettings = getEditedEntityRecord( 'root', 'site' ); | ||
const _type = getCurrentPostType(); | ||
const _id = getCurrentPostId(); | ||
const _record = getEditedEntityRecord( 'postType', _type, _id ); | ||
const _templateInfo = | ||
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes( | ||
_type | ||
) && __experimentalGetTemplateInfo( _record ); | ||
let _isSync = false; | ||
if ( GLOBAL_POST_TYPES.includes( _type ) ) { | ||
if ( PATTERN_POST_TYPE === _type ) { | ||
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead. | ||
const currentSyncStatus = | ||
getEditedPostAttribute( 'meta' ) | ||
?.wp_pattern_sync_status === 'unsynced' | ||
? 'unsynced' | ||
: getEditedPostAttribute( | ||
'wp_pattern_sync_status' | ||
); | ||
_isSync = currentSyncStatus !== 'unsynced'; | ||
} else { | ||
_isSync = true; | ||
} | ||
} | ||
} | ||
return { | ||
title: _templateInfo?.title || getEditedPostAttribute( 'title' ), | ||
icon: unlock( select( editorStore ) ).getPostIcon( _type, { | ||
area: _record?.area, | ||
} ), | ||
isSync: _isSync, | ||
}; | ||
}, [] ); | ||
return { | ||
title: | ||
_templateInfo?.title || getEditedPostAttribute( 'title' ), | ||
icon: unlock( select( editorStore ) ).getPostIcon( _type, { | ||
area: _record?.area, | ||
} ), | ||
isSync: _isSync, | ||
isFrontPage: siteSettings?.page_on_front === _id, | ||
isPostsPage: siteSettings?.page_for_posts === _id, | ||
}; | ||
}, | ||
[] | ||
); | ||
return ( | ||
<div className="editor-post-card-panel"> | ||
<HStack | ||
|
@@ -83,8 +93,19 @@ export default function PostCardPanel( { actions } ) { | |
className="editor-post-card-panel__title" | ||
weight={ 500 } | ||
as="h2" | ||
lineHeight={ '20px' } | ||
> | ||
{ title ? decodeEntities( title ) : __( 'No Title' ) } | ||
{ isFrontPage && ( | ||
<span className="editor-post-card-panel__title-badge"> | ||
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. Is this badge something that can become a generic UI components to move to the components package? We're using it in multiple places now. 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. 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. Yes please #61106 |
||
{ __( 'Front Page' ) } | ||
</span> | ||
) } | ||
{ isPostsPage && ( | ||
<span className="editor-post-card-panel__title-badge"> | ||
{ __( 'Posts Page' ) } | ||
</span> | ||
) } | ||
</Text> | ||
{ actions } | ||
</HStack> | ||
|
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.
In other places the "id" here was typecast into an integer to work. I don't know whether it's needed here. cc @ntsekouras
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.
There was definitely an issue with some endpoint or selector in the past that would return a
string
id, but couldn't pinpoint it now.. By debugging and looking at the code, at least in these checks, both values are numbers. So it's safe to leave as is.