-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: create router adapter for sidebar #60466
Changes from 11 commits
e759036
4db02ef
50e75af
d004005
1119a01
6f49dfa
e6832c0
590e096
74f9481
7cf2a4f
979d1bf
f24027b
d3aec42
7490458
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* WordPress dependencies | ||
*/ | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -12,7 +13,17 @@ import Editor from '../editor'; | |
import PagePages from '../page-pages'; | ||
import PagePatterns from '../page-patterns'; | ||
import PageTemplatesTemplateParts from '../page-templates-template-parts'; | ||
|
||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles'; | ||
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main'; | ||
import SidebarNavigationScreenNavigationMenus from '../sidebar-navigation-screen-navigation-menus'; | ||
import SidebarNavigationScreenPage from '../sidebar-navigation-screen-page'; | ||
import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse'; | ||
import SidebarNavigationScreenTemplate from '../sidebar-navigation-screen-template'; | ||
import SidebarNavigationScreenPattern from '../sidebar-navigation-screen-pattern'; | ||
import SidebarNavigationScreenPatterns from '../sidebar-navigation-screen-patterns'; | ||
import SidebarNavigationScreenNavigationMenu from '../sidebar-navigation-screen-navigation-menu'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import { | ||
TEMPLATE_POST_TYPE, | ||
TEMPLATE_PART_POST_TYPE, | ||
|
@@ -29,19 +40,24 @@ export default function useLayoutAreas() { | |
// Note: Since "sidebar" is not yet supported here, | ||
// returning undefined from "mobile" means show the sidebar. | ||
|
||
// Regular page | ||
// Page list | ||
if ( path === '/page' ) { | ||
const isListLayout = layout === 'list' || ! layout; | ||
return { | ||
key: 'pages-list', | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Manage pages' ) } | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PagePages />, | ||
preview: isListLayout && ( | ||
<Editor | ||
isLoading={ isSiteEditorLoading } | ||
onClick={ () => | ||
history.push( { | ||
path, | ||
postType: 'page', | ||
postId, | ||
canvas: 'edit', | ||
|
@@ -64,14 +80,24 @@ export default function useLayoutAreas() { | |
|
||
// Regular other post types | ||
if ( postType && postId ) { | ||
let sidebar; | ||
if ( postType === 'wp_template_part' || postType === 'wp_block' ) { | ||
sidebar = <SidebarNavigationScreenPattern />; | ||
} else if ( postType === 'wp_template' ) { | ||
sidebar = <SidebarNavigationScreenTemplate />; | ||
} else if ( postType === 'page' ) { | ||
sidebar = <SidebarNavigationScreenPage />; | ||
} else { | ||
sidebar = <SidebarNavigationScreenNavigationMenu />; | ||
} | ||
return { | ||
key: 'page', | ||
areas: { | ||
sidebar, | ||
preview: <Editor isLoading={ isSiteEditorLoading } />, | ||
mobile: | ||
canvas === 'edit' ? ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
) : undefined, | ||
mobile: canvas === 'edit' && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
}; | ||
} | ||
|
@@ -82,6 +108,11 @@ export default function useLayoutAreas() { | |
return { | ||
key: 'templates-list', | ||
areas: { | ||
sidebar: postId ? ( | ||
<SidebarNavigationScreenTemplate /> | ||
) : ( | ||
<SidebarNavigationScreenTemplatesBrowse postType="wp_template" /> | ||
), | ||
content: ( | ||
<PageTemplatesTemplateParts | ||
postType={ TEMPLATE_POST_TYPE } | ||
|
@@ -108,6 +139,9 @@ export default function useLayoutAreas() { | |
return { | ||
key: 'template-parts', | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreenTemplatesBrowse postType="wp_template_part" /> | ||
), | ||
content: ( | ||
<PageTemplatesTemplateParts | ||
postType={ TEMPLATE_PART_POST_TYPE } | ||
|
@@ -133,21 +167,50 @@ export default function useLayoutAreas() { | |
return { | ||
key: 'patterns', | ||
areas: { | ||
sidebar: <SidebarNavigationScreenPatterns />, | ||
content: <PagePatterns />, | ||
mobile: <PagePatterns />, | ||
}, | ||
}; | ||
} | ||
|
||
// Styles | ||
if ( path === '/wp_global_styles' ) { | ||
return { | ||
key: 'styles', | ||
areas: { | ||
sidebar: <SidebarNavigationScreenGlobalStyles />, | ||
preview: <Editor isLoading={ isSiteEditorLoading } />, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually like this personally. It kind of gives clarity about the areas. Ideally we should be passing postId, postType to the Editor component but historically, the active postId/postType are fetched from the site editor store. I think using the store for this is not perfect because the site editor is not just an editor, it can render things that are not "editor" but for now it's like that which means the Editor component is the same between routes (no specific props) while in reality, it's not exactly the same. |
||
mobile: canvas === 'edit' && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
}; | ||
} | ||
|
||
// Navigation | ||
if ( path === '/navigation' ) { | ||
return { | ||
key: 'styles', | ||
areas: { | ||
sidebar: <SidebarNavigationScreenNavigationMenus />, | ||
preview: <Editor isLoading={ isSiteEditorLoading } />, | ||
mobile: canvas === 'edit' && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
}; | ||
} | ||
|
||
// Fallback shows the home page preview | ||
return { | ||
key: 'default', | ||
areas: { | ||
sidebar: <SidebarNavigationScreenMain />, | ||
preview: <Editor isLoading={ isSiteEditorLoading } />, | ||
mobile: | ||
canvas === 'edit' ? ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
) : undefined, | ||
mobile: canvas === 'edit' && ( | ||
<Editor isLoading={ isSiteEditorLoading } /> | ||
), | ||
}, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring made things a lot more simple to follow, thanks @jsnajdr!
I find one little thing missing: fully controlling the mobile views. At the moment, we only use
areas.mobile
for displaying components other than the sidebar. The logic to default to the sidebar ifareas.mobile
is undefined still lives in the layout. Absorbing as part of the router would simplify things further.