-
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: Navigation templates #25739
Changes from 52 commits
da18be9
186b244
6c720c2
dd60398
790ac20
5921992
4036921
5b76047
9e74cc1
4195108
8cb3123
b9b2c02
3d6a135
637354a
f34fc16
af092c0
06faa7c
3ba796d
969ff62
6e1c693
c40e390
9c6e04a
9e2b8e8
88e3f45
485f5fb
1608e3a
0817526
0d8ab08
e694a7b
e5711c2
1a56595
ba847e8
c6b07a0
4f7c00a
6ba556d
976ed93
e72bba7
4e3b47b
d4873a6
1218680
086e39e
c8b1d4c
71ceb5b
7990a9b
bf02206
a081994
24d2293
d239fbb
7a2600d
38c4ce5
787e076
2cc0c62
a369fd7
34d5078
83b3597
d74ae61
51c9075
abfcfa5
41c0bd3
6a4d721
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export const ITEM_CONTENTS = { | ||
david-szabo97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// General | ||
'front-page': { | ||
title: 'Front page', | ||
description: '', | ||
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. We could've added "Display the contents of your Front Page" here, or something along the similar lines. 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. @david-szabo97 @vindl — Let's not forget i18n. Constants files like this should be i18n-ready from the start, otherwise getting everything ready for a testable Site Editor around WP 5.6 will be much more difficult. 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. @mcsf My fault, I should have caught this in review! |
||
}, | ||
archive: { | ||
title: 'Archive', | ||
description: | ||
'Displays the content lists when no other template is found', | ||
}, | ||
single: { | ||
title: 'Single', | ||
description: 'Displays the content of a single post', | ||
}, | ||
singular: { | ||
title: 'Singular', | ||
description: 'Displays the content of a single page', | ||
}, | ||
index: { | ||
title: 'Default (index)', | ||
description: 'Displays the content of a single page', | ||
}, | ||
search: { | ||
title: 'Search results', | ||
description: '', | ||
}, | ||
'404': { | ||
title: '404', | ||
description: 'Displayed when a non-existing page requested', | ||
}, | ||
|
||
// Pages | ||
page: { | ||
title: 'Default (Page)', | ||
description: 'Displays the content of a single page', | ||
}, | ||
|
||
// Posts | ||
home: { | ||
title: 'Posts (home)', | ||
description: 'Displayed on your homepage', | ||
}, | ||
'archive-post': { | ||
title: 'Default (Post archive)', | ||
description: 'Displays a list of posts', | ||
}, | ||
'single-post': { | ||
title: 'Default (Single post)', | ||
description: 'Displays the content of a single post', | ||
}, | ||
}; | ||
|
||
export const GENERAL_TEMPLATES = [ | ||
'front-page', | ||
'archive', | ||
'single', | ||
'singular', | ||
'index', | ||
'search', | ||
'404', | ||
]; | ||
|
||
export const POSTS_GENERAL_TEMPLATES = [ | ||
'single-post', | ||
'archive-post', | ||
'home', | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect, useRef } from '@wordpress/element'; | ||
import { useEffect, useRef, useState } from '@wordpress/element'; | ||
import { | ||
__experimentalNavigation as Navigation, | ||
__experimentalNavigationMenu as NavigationMenu, | ||
__experimentalNavigationItem as NavigationItem, | ||
__experimentalNavigationBackButton as NavigationBackButton, | ||
createSlotFill, | ||
} from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplateSwitcher from './template-switcher'; | ||
import TemplatesMenu from './menus/templates'; | ||
import TemplatePartsMenu from './menus/template-parts'; | ||
|
||
export const { | ||
Fill: NavigationPanelPreviewFill, | ||
Slot: NavigationPanelPreviewSlot, | ||
} = createSlotFill( 'EditSiteNavigationPanelPreview' ); | ||
|
||
const NavigationPanel = () => { | ||
const [ activeMenu, setActiveMenu ] = useState( 'root' ); | ||
const ref = useRef(); | ||
|
||
useEffect( () => { | ||
ref.current.focus(); | ||
}, [ ref ] ); | ||
|
||
const { templateId, templatePartId, templateType, page } = useSelect( | ||
const { templateId, templatePartId, templateType } = useSelect( | ||
( select ) => { | ||
const { | ||
getTemplateId, | ||
getTemplatePartId, | ||
getTemplateType, | ||
getPage, | ||
} = select( 'core/edit-site' ); | ||
|
||
return { | ||
templateId: getTemplateId(), | ||
templatePartId: getTemplatePartId(), | ||
templateType: getTemplateType(), | ||
page: getPage(), | ||
}; | ||
}, | ||
[] | ||
); | ||
|
||
const { | ||
setTemplate, | ||
addTemplate, | ||
removeTemplate, | ||
setTemplatePart, | ||
} = useDispatch( 'core/edit-site' ); | ||
const { setTemplate, setTemplatePart } = useDispatch( 'core/edit-site' ); | ||
|
||
return ( | ||
<div className="edit-site-navigation-panel"> | ||
|
@@ -56,25 +58,37 @@ const NavigationPanel = () => { | |
? `template-${ templateId }` | ||
: `template-part-${ templatePartId }` | ||
} | ||
onActivateMenu={ setActiveMenu } | ||
> | ||
<NavigationBackButton | ||
backButtonLabel={ __( 'Dashboard' ) } | ||
className="edit-site-navigation-panel__back-to-dashboard" | ||
href="index.php" | ||
ref={ ref } | ||
/> | ||
{ activeMenu === 'root' && ( | ||
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'm cool with this change, but I wonder if it might have a11y implications — either way I mean. 🤔 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. Two back button is strange, that was the main reason I removed this back button. I'm not sure how it affects a11y. 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. Right, two back buttons is strange, but at the same time one of them (back to dashboard) is "outside" the navigation menu context. This is all anecdotal, though. |
||
<NavigationBackButton | ||
backButtonLabel={ __( 'Dashboard' ) } | ||
className="edit-site-navigation-panel__back-to-dashboard" | ||
href="index.php" | ||
ref={ ref } | ||
/> | ||
) } | ||
|
||
<NavigationMenu title="Theme"> | ||
<NavigationItem | ||
title="Templates" | ||
navigateToMenu="templates" | ||
/> | ||
|
||
<NavigationMenu title="Home"> | ||
<TemplateSwitcher | ||
page={ page } | ||
activeId={ templateId } | ||
onActiveIdChange={ setTemplate } | ||
<NavigationItem | ||
title="Template parts" | ||
navigateToMenu="template-parts" | ||
/> | ||
|
||
<TemplatesMenu onActiveIdChange={ setTemplate } /> | ||
|
||
<TemplatePartsMenu | ||
onActiveTemplatePartIdChange={ setTemplatePart } | ||
onAddTemplate={ addTemplate } | ||
onRemoveTemplate={ removeTemplate } | ||
/> | ||
</NavigationMenu> | ||
</Navigation> | ||
|
||
david-szabo97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<NavigationPanelPreviewSlot /> | ||
</div> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { | ||
__experimentalNavigationItem as NavigationItem, | ||
__experimentalNavigationMenu as NavigationMenu, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplateNavigationItems from '../template-navigation-items'; | ||
|
||
export default function TemplatePartsMenu( { onActiveTemplatePartIdChange } ) { | ||
const templateParts = useSelect( ( select ) => { | ||
const currentTheme = select( 'core' ).getCurrentTheme()?.textdomain; | ||
|
||
return select( 'core' ).getEntityRecords( | ||
'postType', | ||
'wp_template_part', | ||
{ | ||
theme: currentTheme, | ||
status: [ 'publish', 'auto-draft' ], | ||
per_page: -1, | ||
} | ||
); | ||
}, [] ); | ||
|
||
return ( | ||
<NavigationMenu | ||
menu="template-parts" | ||
title="Template Parts" | ||
parentMenu="root" | ||
> | ||
<TemplateNavigationItems | ||
entityType="wp_template_part" | ||
templates={ templateParts } | ||
onActivate={ onActiveTemplatePartIdChange } | ||
/> | ||
|
||
{ ! templateParts && <NavigationItem title={ __( 'Loading…' ) } /> } | ||
</NavigationMenu> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalNavigationGroup as NavigationGroup, | ||
__experimentalNavigationMenu as NavigationMenu, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplateNavigationItems from '../template-navigation-items'; | ||
|
||
export default function TemplatesPagesMenu( { templates, onActiveIdChange } ) { | ||
const defaultTemplate = templates?.find( ( { slug } ) => slug === 'page' ); | ||
const specificPageTemplates = templates?.filter( ( { slug } ) => | ||
slug.startsWith( 'page-' ) | ||
); | ||
|
||
return ( | ||
<NavigationMenu | ||
menu="templates-pages" | ||
title="Pages" | ||
parentMenu="templates" | ||
> | ||
<NavigationGroup title="Specific"> | ||
<TemplateNavigationItems | ||
templates={ specificPageTemplates } | ||
onActivate={ onActiveIdChange } | ||
/> | ||
</NavigationGroup> | ||
|
||
{ defaultTemplate && ( | ||
<NavigationGroup title="General"> | ||
<TemplateNavigationItems | ||
templates={ defaultTemplate } | ||
onActivate={ onActiveIdChange } | ||
/> | ||
</NavigationGroup> | ||
) } | ||
</NavigationMenu> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalNavigationGroup as NavigationGroup, | ||
__experimentalNavigationMenu as NavigationMenu, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TemplateNavigationItems from '../template-navigation-items'; | ||
import { POSTS_GENERAL_TEMPLATES } from '../constants'; | ||
|
||
export default function TemplatePostsMenu( { templates, onActiveIdChange } ) { | ||
const generalTemplates = templates?.find( ( { slug } ) => | ||
POSTS_GENERAL_TEMPLATES.includes( slug ) | ||
); | ||
const specificTemplates = templates?.filter( ( { slug } ) => | ||
slug.startsWith( 'post-' ) | ||
); | ||
|
||
return ( | ||
<NavigationMenu | ||
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. We could've delayed adding this until we had actual content for it. |
||
menu="templates-posts" | ||
title="Posts" | ||
parentMenu="templates" | ||
> | ||
<NavigationGroup title="Specific"> | ||
<TemplateNavigationItems | ||
templates={ specificTemplates } | ||
onActivate={ onActiveIdChange } | ||
/> | ||
</NavigationGroup> | ||
|
||
<NavigationGroup title="General"> | ||
<TemplateNavigationItems | ||
templates={ generalTemplates } | ||
onActivate={ onActiveIdChange } | ||
/> | ||
</NavigationGroup> | ||
</NavigationMenu> | ||
); | ||
} |
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.
As already mentioned, accessing these files on each request is going to have a negative impact on performance. We can probably store this info once on theme activation and we'll also need it after theme updates.