File tree Expand file tree Collapse file tree
packages/app/src/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,25 @@ export function DialogSelectServer() {
4646
4747 const current = createMemo ( ( ) => items ( ) . find ( ( x ) => x === server . url ) ?? items ( ) [ 0 ] )
4848
49+ const sortedItems = createMemo ( ( ) => {
50+ const list = items ( )
51+ if ( ! list . length ) return list
52+ const active = current ( )
53+ const order = new Map ( list . map ( ( url , index ) => [ url , index ] as const ) )
54+ const rank = ( value ?: ServerStatus ) => {
55+ if ( value ?. healthy === true ) return 0
56+ if ( value ?. healthy === false ) return 2
57+ return 1
58+ }
59+ return list . slice ( ) . sort ( ( a , b ) => {
60+ if ( a === active ) return - 1
61+ if ( b === active ) return 1
62+ const diff = rank ( store . status [ a ] ) - rank ( store . status [ b ] )
63+ if ( diff !== 0 ) return diff
64+ return ( order . get ( a ) ?? 0 ) - ( order . get ( b ) ?? 0 )
65+ } )
66+ } )
67+
4968 async function refreshHealth ( ) {
5069 const results : Record < string , ServerStatus > = { }
5170 await Promise . all (
@@ -101,7 +120,7 @@ export function DialogSelectServer() {
101120 < List
102121 search = { { placeholder : "Search servers" , autofocus : true } }
103122 emptyMessage = "No servers yet"
104- items = { items }
123+ items = { sortedItems }
105124 key = { ( x ) => x }
106125 current = { current ( ) }
107126 onSelect = { ( x ) => {
You can’t perform that action at this time.
0 commit comments