Skip to content

Commit

Permalink
Add badge to title for posts & front pages (#61718)
Browse files Browse the repository at this point in the history
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
4 people authored May 16, 2024
1 parent 43cdf75 commit e357a62
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
48 changes: 43 additions & 5 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { Button, __experimentalHStack as HStack } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
Expand Down Expand Up @@ -273,6 +273,16 @@ export default function PagePages() {
[ totalItems, totalPages ]
);

const { frontPageId, postsPageId } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );

return {
frontPageId: siteSettings?.page_on_front,
postsPageId: siteSettings?.page_for_posts,
};
} );

const fields = useMemo(
() => [
{
Expand All @@ -293,7 +303,7 @@ export default function PagePages() {
const addLink =
[ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) &&
item.status !== 'trash';
return addLink ? (
const title = addLink ? (
<Link
params={ {
postId: item.id,
Expand All @@ -305,8 +315,36 @@ export default function PagePages() {
__( '(no title)' ) }
</Link>
) : (
decodeEntities( item.title?.rendered ) ||
__( '(no title)' )
<span>
{ decodeEntities( item.title?.rendered ) ||
__( '(no title)' ) }
</span>
);

let suffix = '';
if ( item.id === frontPageId ) {
suffix = (
<span className="edit-site-page-pages__title-badge">
{ __( 'Front Page' ) }
</span>
);
} else if ( item.id === postsPageId ) {
suffix = (
<span className="edit-site-page-pages__title-badge">
{ __( 'Posts Page' ) }
</span>
);
}

return (
<HStack
className="edit-site-page-pages-title"
alignment="center"
justify="flex-start"
>
{ title }
{ suffix }
</HStack>
);
},
maxWidth: 300,
Expand Down Expand Up @@ -411,7 +449,7 @@ export default function PagePages() {
},
},
],
[ authors, view.type ]
[ authors, view.type, frontPageId, postsPageId ]
);

const postTypeActions = usePostActions( 'page' );
Expand Down
15 changes: 15 additions & 0 deletions packages/edit-site/src/components/page-pages/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@
outline: 2px solid transparent;
}
}

.edit-site-page-pages-title span {
text-overflow: ellipsis;
overflow: hidden;
}

.edit-site-page-pages__title-badge {
background: $gray-100;
color: $gray-700;
padding: $grid-unit-05 $grid-unit-10;
border-radius: $radius-block-ui;
font-size: 12px;
font-weight: 400;
flex-shrink: 0;
}

0 comments on commit e357a62

Please sign in to comment.