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

DataViews: add front page to pages page sidebar #57759

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
} from '@wordpress/components';
import { layout } from '@wordpress/icons';
import { useMemo } from '@wordpress/element';
import { useEntityRecords } from '@wordpress/core-data';
import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -41,13 +42,36 @@ export default function SidebarNavigationScreenPagesDataViews() {
per_page: -1,
}
);
const templates = useMemo(
() =>
templateRecords?.filter( ( { slug } ) =>

const { frontPage, postsPage } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPage: siteSettings?.page_on_front,
postsPage: siteSettings?.page_for_posts,
};
}, [] );

const templates = useMemo( () => {
if ( ! templateRecords ) {
return [];
}

const isHomePageBlog = frontPage === postsPage;
const homeTemplate =
templateRecords?.find(
( template ) => template.slug === 'front-page'
) ||
templateRecords?.find( ( template ) => template.slug === 'home' ) ||
templateRecords?.find( ( template ) => template.slug === 'index' );

return [
isHomePageBlog ? homeTemplate : null,
...templateRecords?.filter( ( { slug } ) =>
[ '404', 'search' ].includes( slug )
),
[ templateRecords ]
);
].filter( Boolean );
}, [ templateRecords, frontPage, postsPage ] );

return (
<SidebarNavigationScreen
Expand Down