@@ -46,6 +46,22 @@ const config = {
46
46
'Manage what patterns are available when editing your site.'
47
47
) ,
48
48
} ,
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
+ } ,
49
65
} ,
50
66
} ;
51
67
@@ -75,10 +91,13 @@ export default function SidebarNavigationScreenTemplates() {
75
91
per_page : - 1 ,
76
92
}
77
93
) ;
78
- const sortedTemplates = templates ? [ ...templates ] : [ ] ;
94
+ let sortedTemplates = templates ? [ ...templates ] : [ ] ;
79
95
sortedTemplates . sort ( ( a , b ) =>
80
96
a . title . rendered . localeCompare ( b . title . rendered )
81
97
) ;
98
+ if ( config [ postType ] . sortCallback ) {
99
+ sortedTemplates = config [ postType ] . sortCallback ( sortedTemplates ) ;
100
+ }
82
101
83
102
const browseAllLink = useLink ( {
84
103
path : '/' + postType + '/all' ,
0 commit comments