Skip to content

Commit

Permalink
DataViews: add front page to sidebar (#57759)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Jan 12, 2024
1 parent 44ba13d commit 75acb7e
Showing 1 changed file with 30 additions and 6 deletions.
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

0 comments on commit 75acb7e

Please sign in to comment.