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

Site editor sidebar: add footer to template part and ensure nested template areas display #51669

Merged
merged 3 commits into from
Jun 20, 2023
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
1 change: 1 addition & 0 deletions packages/edit-site/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@ export default function SidebarNavigationScreenDetailsFooter( {
lastModifiedDateTime,
} ) {
return (
<SidebarNavigationScreenDetailsPanelRow className="edit-site-sidebar-navigation-screen-details-footer">
<SidebarNavigationScreenDetailsPanelLabel>
{ __( 'Last modified' ) }
</SidebarNavigationScreenDetailsPanelLabel>
<SidebarNavigationScreenDetailsPanelValue>
{ createInterpolateElement(
sprintf(
/* translators: %s: is the relative time when the post was last modified. */
__( '<time>%s</time>' ),
humanTimeDiff( lastModifiedDateTime )
),
{
time: <time dateTime={ lastModifiedDateTime } />,
}
) }
</SidebarNavigationScreenDetailsPanelValue>
</SidebarNavigationScreenDetailsPanelRow>
<>
{ lastModifiedDateTime && (
<SidebarNavigationScreenDetailsPanelRow className="edit-site-sidebar-navigation-screen-details-footer">
<SidebarNavigationScreenDetailsPanelLabel>
{ __( 'Last modified' ) }
</SidebarNavigationScreenDetailsPanelLabel>
<SidebarNavigationScreenDetailsPanelValue>
{ createInterpolateElement(
sprintf(
/* translators: %s: is the relative time when the post was last modified. */
__( '<time>%s</time>' ),
humanTimeDiff( lastModifiedDateTime )
),
{
time: (
<time dateTime={ lastModifiedDateTime } />
),
}
) }
</SidebarNavigationScreenDetailsPanelValue>
</SidebarNavigationScreenDetailsPanelRow>
) }
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ export default function SidebarNavigationScreenPage() {
</>
}
footer={
!! record?.modified && (
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record.modified }
/>
)
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record?.modified }
/>
}
/>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export default function PageDetails( { id } ) {
[ record?.parent ]
);
return (
<SidebarNavigationScreenDetailsPanel title={ __( 'Details' ) }>
<SidebarNavigationScreenDetailsPanel
spacing={ 5 }
title={ __( 'Details' ) }
>
{ getPageDetails( {
parentTitle,
templateTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +78,13 @@ function useTemplateTitleAndDescription( postType, postId ) {
</>
);

return { title, description };
const footer = !! record?.modified ? (
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record.modified }
/>
) : null;

return { title, description, footer };
}

export default function SidebarNavigationScreenTemplatePart() {
Expand All @@ -88,7 +94,7 @@ export default function SidebarNavigationScreenTemplatePart() {

const { record } = useEditedEntityRecord( postType, postId );

const { title, description } = useTemplateTitleAndDescription(
const { title, description, footer } = useTemplateDetails(
postType,
postId
);
Expand Down Expand Up @@ -118,6 +124,7 @@ export default function SidebarNavigationScreenTemplatePart() {
content={
<TemplatePartNavigationMenus menus={ navigationMenuIds } />
}
footer={ footer }
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 ]
Expand All @@ -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 );
Expand Down Expand Up @@ -207,15 +210,19 @@ export default function HomeTemplateDetails() {
spacing={ 3 }
>
<ItemGroup>
{ templateAreas.map( ( { label, icon, theme, slug } ) => (
<SidebarNavigationScreenDetailsPanelRow key={ slug }>
<TemplateAreaButton
postId={ `${ theme }//${ slug }` }
title={ label || slug }
icon={ icon }
/>
</SidebarNavigationScreenDetailsPanelRow>
) ) }
{ templateAreas.map(
( { label, icon, theme, slug, title } ) => (
<SidebarNavigationScreenDetailsPanelRow
key={ slug }
>
<TemplateAreaButton
postId={ `${ theme }//${ slug }` }
title={ title?.rendered || label }
icon={ icon }
/>
</SidebarNavigationScreenDetailsPanelRow>
)
) }
</ItemGroup>
</SidebarNavigationScreenDetailsPanel>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ function useTemplateDetails( postType, postId ) {
);
}

let content = null;
if ( record?.slug === 'home' || record?.slug === 'index' ) {
content = <HomeTemplateDetails />;
}
const content =
record?.slug === 'home' || record?.slug === 'index' ? (
<HomeTemplateDetails />
) : null;

let footer = null;
if ( !! record?.modified ) {
footer = (
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record.modified }
/>
);
}
const footer = !! record?.modified ? (
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record.modified }
/>
) : null;

const description = (
<>
Expand Down
Loading