Skip to content

Commit eecc955

Browse files
authored
[Site Editor]: Sort template parts by type in navigation screen (#50841)
1 parent 166256e commit eecc955

File tree

1 file changed

+20
-1
lines changed
  • packages/edit-site/src/components/sidebar-navigation-screen-templates

1 file changed

+20
-1
lines changed

packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ const config = {
4646
'Manage what patterns are available when editing your site.'
4747
),
4848
},
49+
sortCallback: ( items ) => {
50+
const groupedByArea = items.reduce(
51+
( accumulator, item ) => {
52+
const key = accumulator[ item.area ] ? item.area : 'rest';
53+
accumulator[ key ].push( item );
54+
return accumulator;
55+
},
56+
{ header: [], footer: [], sidebar: [], rest: [] }
57+
);
58+
return [
59+
...groupedByArea.header,
60+
...groupedByArea.footer,
61+
...groupedByArea.sidebar,
62+
...groupedByArea.rest,
63+
];
64+
},
4965
},
5066
};
5167

@@ -75,10 +91,13 @@ export default function SidebarNavigationScreenTemplates() {
7591
per_page: -1,
7692
}
7793
);
78-
const sortedTemplates = templates ? [ ...templates ] : [];
94+
let sortedTemplates = templates ? [ ...templates ] : [];
7995
sortedTemplates.sort( ( a, b ) =>
8096
a.title.rendered.localeCompare( b.title.rendered )
8197
);
98+
if ( config[ postType ].sortCallback ) {
99+
sortedTemplates = config[ postType ].sortCallback( sortedTemplates );
100+
}
82101

83102
const browseAllLink = useLink( {
84103
path: '/' + postType + '/all',

0 commit comments

Comments
 (0)