Skip to content

Commit

Permalink
[Site Editor]: Sort template parts by type in navigation screen (#50841)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored May 22, 2023
1 parent 166256e commit eecc955
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

1 comment on commit eecc955

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in eecc955.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5046547225
📝 Reported issues:

Please sign in to comment.