From e357a620d36c35d910d5f1632fd1435708b685f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 16 May 2024 19:32:48 +0200 Subject: [PATCH] Add badge to title for posts & front pages (#61718) Co-authored-by: oandregal Co-authored-by: youknowriad Co-authored-by: jameskoster --- .../src/components/page-pages/index.js | 48 +++++++++++++++++-- .../src/components/page-pages/style.scss | 15 ++++++ 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index b9d0977e3234c..00d86ea942a37 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -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'; @@ -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( () => [ { @@ -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 ? ( ) : ( - decodeEntities( item.title?.rendered ) || - __( '(no title)' ) + + { decodeEntities( item.title?.rendered ) || + __( '(no title)' ) } + + ); + + let suffix = ''; + if ( item.id === frontPageId ) { + suffix = ( + + { __( 'Front Page' ) } + + ); + } else if ( item.id === postsPageId ) { + suffix = ( + + { __( 'Posts Page' ) } + + ); + } + + return ( + + { title } + { suffix } + ); }, maxWidth: 300, @@ -411,7 +449,7 @@ export default function PagePages() { }, }, ], - [ authors, view.type ] + [ authors, view.type, frontPageId, postsPageId ] ); const postTypeActions = usePostActions( 'page' ); diff --git a/packages/edit-site/src/components/page-pages/style.scss b/packages/edit-site/src/components/page-pages/style.scss index 9fcc5571d19d9..ee1012e923b51 100644 --- a/packages/edit-site/src/components/page-pages/style.scss +++ b/packages/edit-site/src/components/page-pages/style.scss @@ -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; +}