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

Inspector: Display home / posts page badge #62071

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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,
Copy link
Contributor

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

Copy link
Contributor

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.

};
},
[]
);
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">
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, probably so. Also in use for anchor tags in list view and within data views.

CleanShot 2024-05-29 at 09 46 40
CleanShot 2024-05-29 at 09 47 05

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
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;
}
Loading