|
|
@@ -46,6 +46,25 @@ export function DialogSelectServer() {
|
|
|
|
|
|
const current = createMemo(() => items().find((x) => x === server.url) ?? items()[0])
|
|
|
|
|
|
+ const sortedItems = createMemo(() => {
|
|
|
+ const list = items()
|
|
|
+ if (!list.length) return list
|
|
|
+ const active = current()
|
|
|
+ const order = new Map(list.map((url, index) => [url, index] as const))
|
|
|
+ const rank = (value?: ServerStatus) => {
|
|
|
+ if (value?.healthy === true) return 0
|
|
|
+ if (value?.healthy === false) return 2
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+ return list.slice().sort((a, b) => {
|
|
|
+ if (a === active) return -1
|
|
|
+ if (b === active) return 1
|
|
|
+ const diff = rank(store.status[a]) - rank(store.status[b])
|
|
|
+ if (diff !== 0) return diff
|
|
|
+ return (order.get(a) ?? 0) - (order.get(b) ?? 0)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
async function refreshHealth() {
|
|
|
const results: Record<string, ServerStatus> = {}
|
|
|
await Promise.all(
|
|
|
@@ -101,7 +120,7 @@ export function DialogSelectServer() {
|
|
|
<List
|
|
|
search={{ placeholder: "Search servers", autofocus: true }}
|
|
|
emptyMessage="No servers yet"
|
|
|
- items={items}
|
|
|
+ items={sortedItems}
|
|
|
key={(x) => x}
|
|
|
current={current()}
|
|
|
onSelect={(x) => {
|