Skip to content

Commit

Permalink
Inspector: Display home / posts page badge (WordPress#62071)
Browse files Browse the repository at this point in the history
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
6 people authored and patil-vipul committed Jun 17, 2024
1 parent 8190e19 commit f90a7fd
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 36 deletions.
91 changes: 56 additions & 35 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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">
{ __( 'Front Page' ) }
</span>
) }
{ isPostsPage && (
<span className="editor-post-card-panel__title-badge">
{ __( 'Posts Page' ) }
</span>
) }
</Text>
{ actions }
</HStack>
Expand Down
20 changes: 19 additions & 1 deletion packages/editor/src/components/post-card-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
width: 100%;

&.editor-post-card-panel__title {
margin: 3px 0 0 0;
margin: 0;
padding: 2px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
column-gap: $grid-unit-10;
row-gap: $grid-unit-05;
}
}

Expand All @@ -30,3 +36,15 @@
.editor-post-card-panel__icon.is-sync {
fill: var(--wp-block-synced-color);
}

.editor-post-card-panel__title-badge {
background: $gray-100;
color: $gray-700;
padding: 0 $grid-unit-05;
border-radius: $radius-block-ui;
font-size: 12px;
font-weight: 400;
flex-shrink: 0;
line-height: $grid-unit-05 * 5;
display: inline-block;
}

0 comments on commit f90a7fd

Please sign in to comment.