Skip to content

Commit

Permalink
Site Editor: Only mark the 'Site' menu item active when editing a hom…
Browse files Browse the repository at this point in the history
…e template (#42807)

* Site Editor: Only mark the 'Site' menu item active when editing a home template

* Account for front-page

* Fix comment
  • Loading branch information
Mamaduka authored Oct 25, 2022
1 parent a498b86 commit 7200d0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions packages/edit-site/src/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import List from '../list';
import NavigationSidebar from '../navigation-sidebar';
import getIsListPage from '../../utils/get-is-list-page';

export default function EditSiteApp( { reboot } ) {
export default function EditSiteApp( { reboot, homeTemplate } ) {
const { createErrorNotice } = useDispatch( noticesStore );

function onPluginAreaError( name ) {
Expand All @@ -40,6 +40,13 @@ export default function EditSiteApp( { reboot } ) {
{ ( { params } ) => {
const isListPage = getIsListPage( params );

// The existence of a 'front-page' supersedes every other setting.
const homeTemplateType =
params.postId?.includes( 'front-page' ) ||
params.postId === homeTemplate?.postId
? 'site-editor'
: undefined;

return (
<>
{ isListPage ? (
Expand All @@ -54,7 +61,9 @@ export default function EditSiteApp( { reboot } ) {
// Open the navigation sidebar by default when in the list page.
isDefaultOpen={ !! isListPage }
activeTemplateType={
isListPage ? params.postType : undefined
isListPage
? params.postType
: homeTemplateType
}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function NavLink( { params, replace, ...props } ) {
return <NavigationItem { ...linkProps } { ...props } />;
}

const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
const NavigationPanel = ( { activeItem } ) => {
const { homeTemplate, isNavigationOpen, isTemplatePartsMode, siteTitle } =
useSelect( ( select ) => {
const { getEntityRecord } = select( coreDataStore );
Expand Down
8 changes: 7 additions & 1 deletion packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ export function reinitializeEditor( target, settings ) {
window.addEventListener( 'dragover', ( e ) => e.preventDefault(), false );
window.addEventListener( 'drop', ( e ) => e.preventDefault(), false );

render( <EditSiteApp reboot={ reboot } />, target );
render(
<EditSiteApp
reboot={ reboot }
homeTemplate={ settings.__unstableHomeTemplate }
/>,
target
);
}

/**
Expand Down

0 comments on commit 7200d0c

Please sign in to comment.