Skip to content
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]: Sort template parts by type in navigation screen #50841

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: [] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the sidebar template part still a thing? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has never been exposed in the UI, except perhaps if a theme supplies one?

);
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