File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -299,4 +299,55 @@ describe("groupByRepository", () => {
299299 "acme/zeta" ,
300300 ] ) ;
301301 } ) ;
302+
303+ it ( "sorts the 'other' group last in the alphabetical path" , ( ) => {
304+ const tasks : TestTask [ ] = [
305+ task ( "t1" ) ,
306+ task ( "t2" , {
307+ fullPath : "posthog/zeta" ,
308+ name : "zeta" ,
309+ organization : "PostHog" ,
310+ } ) ,
311+ task ( "t3" , {
312+ fullPath : "posthog/alpha" ,
313+ name : "alpha" ,
314+ organization : "PostHog" ,
315+ } ) ,
316+ ] ;
317+
318+ const groups = groupByRepository ( tasks , [ ] ) ;
319+
320+ expect ( groups . map ( ( g ) => g . id ) ) . toEqual ( [
321+ "posthog/alpha" ,
322+ "posthog/zeta" ,
323+ "other" ,
324+ ] ) ;
325+ } ) ;
326+
327+ it ( "sorts the 'other' group last in the folder-order path" , ( ) => {
328+ const tasks : TestTask [ ] = [
329+ task ( "t1" ) ,
330+ task ( "t2" , {
331+ fullPath : "posthog/code" ,
332+ name : "code" ,
333+ organization : "PostHog" ,
334+ } ) ,
335+ task ( "t3" , {
336+ fullPath : "posthog/posthog" ,
337+ name : "posthog" ,
338+ organization : "PostHog" ,
339+ } ) ,
340+ ] ;
341+
342+ const groups = groupByRepository ( tasks , [
343+ "posthog/posthog" ,
344+ "posthog/code" ,
345+ ] ) ;
346+
347+ expect ( groups . map ( ( g ) => g . id ) ) . toEqual ( [
348+ "posthog/posthog" ,
349+ "posthog/code" ,
350+ "other" ,
351+ ] ) ;
352+ } ) ;
302353} ) ;
Original file line number Diff line number Diff line change @@ -88,11 +88,26 @@ export function groupByRepository<T extends GroupableTask>(
8888 }
8989 }
9090
91+ // The "other" group (tasks without a resolvable repository) always sorts to
92+ // the bottom, regardless of the alphabetical or persisted folder order.
93+ const pinOtherLast = ( a : TaskGroup < T > , b : TaskGroup < T > ) : number | null => {
94+ const aOther = a . id === "other" ;
95+ const bOther = b . id === "other" ;
96+ if ( aOther && bOther ) return 0 ;
97+ if ( aOther ) return 1 ;
98+ if ( bOther ) return - 1 ;
99+ return null ;
100+ } ;
101+
91102 if ( folderOrder . length === 0 ) {
92- return groups . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
103+ return groups . sort (
104+ ( a , b ) => pinOtherLast ( a , b ) ?? a . name . localeCompare ( b . name ) ,
105+ ) ;
93106 }
94107
95108 return groups . sort ( ( a , b ) => {
109+ const pinned = pinOtherLast ( a , b ) ;
110+ if ( pinned !== null ) return pinned ;
96111 const aIndex = folderOrder . indexOf ( a . id ) ;
97112 const bIndex = folderOrder . indexOf ( b . id ) ;
98113 if ( aIndex === - 1 && bIndex === - 1 ) {
You can’t perform that action at this time.
0 commit comments