Skip to content

Commit 912eb9e

Browse files
Site Editor: Browsing sidebar templates menu restructure (#28291)
1 parent b6c3499 commit 912eb9e

File tree

7 files changed

+205
-152
lines changed

7 files changed

+205
-152
lines changed

packages/e2e-tests/specs/experiments/multi-entity-editing.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ describe( 'Multi-entity editor states', () => {
207207
'.wp-block-template-part .block-editor-block-list__layout'
208208
);
209209

210-
// Our custom template shows up in the " templates > all" menu; let's use it.
211-
await clickTemplateItem( [ 'Templates', 'All' ], templateName );
210+
// Our custom template shows up in the "Templates > General" menu; let's use it.
211+
await clickTemplateItem(
212+
[ 'Templates', 'General templates' ],
213+
templateName
214+
);
212215
await page.waitForXPath(
213216
`//h1[contains(@class, "edit-site-document-actions__title") and contains(text(), '${ templateName }')]`
214217
);

packages/edit-site/src/components/navigation-sidebar/navigation-panel/constants.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,43 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55

6-
export const TEMPLATES_GENERAL = [
7-
'front-page',
8-
'archive',
9-
'singular',
6+
export const TEMPLATES_PRIMARY = [
107
'index',
11-
'search',
8+
'singular',
9+
'archive',
10+
'single',
11+
'page',
12+
'home',
1213
'404',
14+
'search',
15+
];
16+
17+
export const TEMPLATES_SECONDARY = [
18+
'author',
19+
'category',
20+
'taxonomy',
21+
'date',
22+
'tag',
23+
'attachment',
24+
'single-post',
25+
'front-page',
26+
];
27+
28+
export const TEMPLATES_TOP_LEVEL = [
29+
...TEMPLATES_PRIMARY,
30+
...TEMPLATES_SECONDARY,
31+
];
32+
33+
export const TEMPLATES_GENERAL = [ 'page-home' ];
34+
35+
export const TEMPLATES_POSTS_PREFIXES = [
36+
'post-',
37+
'author-',
38+
'single-post-',
39+
'tag-',
1340
];
1441

15-
export const TEMPLATES_POSTS = [ 'home', 'single', 'single-post' ];
42+
export const TEMPLATES_PAGES_PREFIXES = [ 'page-' ];
1643

1744
export const TEMPLATES_NEW_OPTIONS = [
1845
'front-page',
@@ -30,9 +57,10 @@ export const MENU_CONTENT_PAGES = 'content-pages';
3057
export const MENU_CONTENT_POSTS = 'content-posts';
3158
export const MENU_TEMPLATE_PARTS = 'template-parts';
3259
export const MENU_TEMPLATES = 'templates';
33-
export const MENU_TEMPLATES_ALL = 'templates-all';
60+
export const MENU_TEMPLATES_GENERAL = 'templates-general';
3461
export const MENU_TEMPLATES_PAGES = 'templates-pages';
3562
export const MENU_TEMPLATES_POSTS = 'templates-posts';
63+
export const MENU_TEMPLATES_UNUSED = 'templates-unused';
3664

3765
export const SEARCH_DEBOUNCE_IN_MS = 75;
3866

packages/edit-site/src/components/navigation-sidebar/navigation-panel/menus/templates-pages.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/edit-site/src/components/navigation-sidebar/navigation-panel/menus/templates-posts.js

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ import { map } from 'lodash';
77
* WordPress dependencies
88
*/
99
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components';
10-
import { __ } from '@wordpress/i18n';
10+
import { useMemo } from '@wordpress/element';
1111

1212
/**
1313
* Internal dependencies
1414
*/
1515
import TemplateNavigationItem from '../template-navigation-item';
16-
import { MENU_TEMPLATES, MENU_TEMPLATES_ALL } from '../constants';
16+
import { MENU_TEMPLATES } from '../constants';
17+
18+
export default function TemplatesSubMenu( { menu, title, templates } ) {
19+
const templatesFiltered = useMemo(
20+
() =>
21+
templates
22+
?.filter( ( { location } ) => location === menu )
23+
?.map( ( { template } ) => template ) ?? [],
24+
[ menu, templates ]
25+
);
1726

18-
export default function TemplatesAllMenu( { templates } ) {
1927
return (
2028
<NavigationMenu
21-
menu={ MENU_TEMPLATES_ALL }
22-
title={ __( 'All Templates' ) }
29+
menu={ menu }
30+
title={ title }
2331
parentMenu={ MENU_TEMPLATES }
32+
isEmpty={ templatesFiltered.length === 0 }
2433
>
25-
{ map( templates, ( template ) => (
34+
{ map( templatesFiltered, ( template ) => (
2635
<TemplateNavigationItem
2736
item={ template }
2837
key={ `wp_template-${ template.id }` }

0 commit comments

Comments
 (0)