diff --git a/packages/edit-site/CHANGELOG.md b/packages/edit-site/CHANGELOG.md index 808554a1c5b1e..c19db6d317649 100644 --- a/packages/edit-site/CHANGELOG.md +++ b/packages/edit-site/CHANGELOG.md @@ -4,6 +4,7 @@ ### Enhancements - Site editor sidebar: add home template details and controls [#51223](https://github.com/WordPress/gutenberg/pull/51223). +- Site editor sidebar: add footer to template part and ensure nested template areas display [#51669](https://github.com/WordPress/gutenberg/pull/51669). ## 5.12.0 (2023-06-07) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js index 4b5c4fb7de880..f9d7f112a41d5 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js @@ -18,22 +18,28 @@ export default function SidebarNavigationScreenDetailsFooter( { lastModifiedDateTime, } ) { return ( - - - { __( 'Last modified' ) } - - - { createInterpolateElement( - sprintf( - /* translators: %s: is the relative time when the post was last modified. */ - __( '' ), - humanTimeDiff( lastModifiedDateTime ) - ), - { - time: - + <> + { lastModifiedDateTime && ( + + + { __( 'Last modified' ) } + + + { createInterpolateElement( + sprintf( + /* translators: %s: is the relative time when the post was last modified. */ + __( '' ), + humanTimeDiff( lastModifiedDateTime ) + ), + { + time: ( + + + ) } + ); } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js index 55ca9b646f423..8e9903be0fa5e 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js @@ -121,11 +121,9 @@ export default function SidebarNavigationScreenPage() { } footer={ - !! record?.modified && ( - - ) + } /> ) : null; diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/page-details.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/page-details.js index 56a94dc64a2a9..0b8b459e482e6 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/page-details.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/page-details.js @@ -139,7 +139,10 @@ export default function PageDetails( { id } ) { [ record?.parent ] ); return ( - + { getPageDetails( { parentTitle, templateTitle, diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template-part/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template-part/index.js index 7f6344b329222..664c708792dc9 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template-part/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template-part/index.js @@ -19,10 +19,10 @@ import { unlock } from '../../lock-unlock'; import { store as editSiteStore } from '../../store'; import SidebarButton from '../sidebar-button'; import { useAddedBy } from '../list/added-by'; - +import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-details-footer'; import TemplatePartNavigationMenus from './template-part-navigation-menus'; -function useTemplateTitleAndDescription( postType, postId ) { +function useTemplateDetails( postType, postId ) { const { getDescription, getTitle, record } = useEditedEntityRecord( postType, postId @@ -78,7 +78,13 @@ function useTemplateTitleAndDescription( postType, postId ) { ); - return { title, description }; + const footer = !! record?.modified ? ( + + ) : null; + + return { title, description, footer }; } export default function SidebarNavigationScreenTemplatePart() { @@ -88,7 +94,7 @@ export default function SidebarNavigationScreenTemplatePart() { const { record } = useEditedEntityRecord( postType, postId ); - const { title, description } = useTemplateTitleAndDescription( + const { title, description, footer } = useTemplateDetails( postType, postId ); @@ -118,6 +124,7 @@ export default function SidebarNavigationScreenTemplatePart() { content={ } + footer={ footer } /> ); } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/home-template-details.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/home-template-details.js index 51c3d7e5f78e9..c740a1baf37c3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template/home-template-details.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/home-template-details.js @@ -73,19 +73,15 @@ export default function HomeTemplateDetails() { postsPerPage, postsPageTitle, postsPageId, - templateRecord, + currentTemplateParts, } = useSelect( ( select ) => { const { getEntityRecord } = select( coreStore ); const siteSettings = getEntityRecord( 'root', 'site' ); const { getSettings } = unlock( select( editSiteStore ) ); + const _currentTemplateParts = + select( editSiteStore ).getCurrentTemplateTemplateParts(); const siteEditorSettings = getSettings(); - const _templateRecord = - select( coreStore ).getEditedEntityRecord( - 'postType', - postType, - postId - ) || EMPTY_OBJECT; const _postsPageRecord = siteSettings?.page_for_posts ? select( coreStore ).getEntityRecord( 'postType', @@ -95,13 +91,13 @@ export default function HomeTemplateDetails() { : EMPTY_OBJECT; return { - templateRecord: _templateRecord, allowCommentsOnNewPosts: siteSettings?.default_comment_status === 'open', postsPageTitle: _postsPageRecord?.title?.rendered, postsPageId: _postsPageRecord?.id, postsPerPage: siteSettings?.posts_per_page, templatePartAreas: siteEditorSettings?.defaultTemplatePartAreas, + currentTemplateParts: _currentTemplateParts, }; }, [ postType, postId ] @@ -112,24 +108,31 @@ export default function HomeTemplateDetails() { const [ postsCountValue, setPostsCountValue ] = useState( 1 ); const [ postsPageTitleValue, setPostsPageTitleValue ] = useState( '' ); + /* + * This hook serves to set the server-retrieved values, + * postsPageTitle, allowCommentsOnNewPosts, postsPerPage, + * to local state. + */ useEffect( () => { setCommentsOnNewPostsValue( allowCommentsOnNewPosts ); setPostsPageTitleValue( postsPageTitle ); setPostsCountValue( postsPerPage ); }, [ postsPageTitle, allowCommentsOnNewPosts, postsPerPage ] ); + /* + * Merge data in currentTemplateParts with templatePartAreas, + * which contains the template icon and fallback labels + */ const templateAreas = useMemo( () => { - return templateRecord?.blocks && templatePartAreas - ? templateRecord.blocks - .filter( ( { name } ) => name === 'core/template-part' ) - .map( ( { attributes } ) => ( { - ...templatePartAreas?.find( - ( { area } ) => area === attributes?.tagName - ), - ...attributes, - } ) ) + return currentTemplateParts.length && templatePartAreas + ? currentTemplateParts.map( ( { templatePart } ) => ( { + ...templatePartAreas?.find( + ( { area } ) => area === templatePart?.area + ), + ...templatePart, + } ) ) : []; - }, [ templateRecord?.blocks, templatePartAreas ] ); + }, [ currentTemplateParts, templatePartAreas ] ); const setAllowCommentsOnNewPosts = ( newValue ) => { setCommentsOnNewPostsValue( newValue ); @@ -207,15 +210,19 @@ export default function HomeTemplateDetails() { spacing={ 3 } > - { templateAreas.map( ( { label, icon, theme, slug } ) => ( - - - - ) ) } + { templateAreas.map( + ( { label, icon, theme, slug, title } ) => ( + + + + ) + ) } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js index 3b1bdf71fa99f..23f758b6f7c57 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js @@ -43,19 +43,16 @@ function useTemplateDetails( postType, postId ) { ); } - let content = null; - if ( record?.slug === 'home' || record?.slug === 'index' ) { - content = ; - } + const content = + record?.slug === 'home' || record?.slug === 'index' ? ( + + ) : null; - let footer = null; - if ( !! record?.modified ) { - footer = ( - - ); - } + const footer = !! record?.modified ? ( + + ) : null; const description = ( <>