Skip to content

Commit

Permalink
[Site Editor]: Sort template parts by type in navigation screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed May 22, 2023
1 parent d6a482e commit a20e855
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ const config = {
'Manage what patterns are available when editing your site.'
),
},
sortCallback: ( items ) => {
const groupedByArea = items.reduce(
( accumulator, item ) => {
const key = accumulator[ item.area ] ? item.area : 'rest';
accumulator[ key ].push( item );
return accumulator;
},
{ header: [], footer: [], sidebar: [], rest: [] }
);
return [
...groupedByArea.header,
...groupedByArea.footer,
...groupedByArea.sidebar,
...groupedByArea.rest,
];
},
},
};

Expand Down Expand Up @@ -75,10 +91,13 @@ export default function SidebarNavigationScreenTemplates() {
per_page: -1,
}
);
const sortedTemplates = templates ? [ ...templates ] : [];
let sortedTemplates = templates ? [ ...templates ] : [];
sortedTemplates.sort( ( a, b ) =>
a.title.rendered.localeCompare( b.title.rendered )
);
if ( config[ postType ].sortCallback ) {
sortedTemplates = config[ postType ].sortCallback( sortedTemplates );
}

const browseAllLink = useLink( {
path: '/' + postType + '/all',
Expand Down

0 comments on commit a20e855

Please sign in to comment.