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: Avoid same key warnings in template parts area listings #54863

Merged
merged 3 commits into from
Sep 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function TemplateAreas() {

<ul className="edit-site-template-card__template-areas-list">
{ templateParts.map( ( { templatePart, block } ) => (
<li key={ templatePart.slug }>
<li key={ block.clientId }>
<TemplateAreaItem
area={ templatePart.area }
clientId={ block.clientId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import {
CheckboxControl,
__experimentalUseNavigator as useNavigator,
__experimentalInputControl as InputControl,
__experimentalNumberControl as NumberControl,
__experimentalTruncate as Truncate,
Expand Down Expand Up @@ -62,10 +61,6 @@ function TemplateAreaButton( { postId, icon, title } ) {
}

export default function HomeTemplateDetails() {
const navigator = useNavigator();
const {
params: { postType, postId },
} = navigator;
const { editEntityRecord } = useDispatch( coreStore );

const {
Expand All @@ -75,34 +70,30 @@ export default function HomeTemplateDetails() {
postsPageTitle,
postsPageId,
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 _postsPageRecord = siteSettings?.page_for_posts
? select( coreStore ).getEntityRecord(
'postType',
'page',
siteSettings?.page_for_posts
)
: EMPTY_OBJECT;
} = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const { getSettings, getCurrentTemplateTemplateParts } = unlock(
select( editSiteStore )
);
const siteSettings = getEntityRecord( 'root', 'site' );
const _postsPageRecord = siteSettings?.page_for_posts
? getEntityRecord(
'postType',
'page',
siteSettings?.page_for_posts
)
: EMPTY_OBJECT;

return {
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 ]
);
return {
allowCommentsOnNewPosts:
siteSettings?.default_comment_status === 'open',
postsPageTitle: _postsPageRecord?.title?.rendered,
postsPageId: _postsPageRecord?.id,
postsPerPage: siteSettings?.posts_per_page,
templatePartAreas: getSettings()?.defaultTemplatePartAreas,
currentTemplateParts: getCurrentTemplateTemplateParts(),
};
}, [] );

const [ commentsOnNewPostsValue, setCommentsOnNewPostsValue ] =
useState( '' );
Expand All @@ -126,11 +117,12 @@ export default function HomeTemplateDetails() {
*/
const templateAreas = useMemo( () => {
return currentTemplateParts.length && templatePartAreas
? currentTemplateParts.map( ( { templatePart } ) => ( {
? currentTemplateParts.map( ( { templatePart, block } ) => ( {
...templatePartAreas?.find(
( { area } ) => area === templatePart?.area
),
...templatePart,
clientId: block.clientId,
} ) )
: [];
}, [ currentTemplateParts, templatePartAreas ] );
Expand Down Expand Up @@ -214,9 +206,9 @@ export default function HomeTemplateDetails() {
>
<ItemGroup>
{ templateAreas.map(
( { label, icon, theme, slug, title } ) => (
( { clientId, label, icon, theme, slug, title } ) => (
<SidebarNavigationScreenDetailsPanelRow
key={ slug }
key={ clientId }
>
<TemplateAreaButton
postId={ `${ theme }//${ slug }` }
Expand Down
Loading