A reload drew the WAN rows in their listed order, so saved pins other than datavi.be stayed in place and the separator fell under unpinned rows until the first sort, two rounds later. AppState now orders the rows with the same sort the periodic one uses. Model: opus-5-5
This commit is contained in:
1 parent
1e85a210f5
commit
c51e12fba9
2 files changed
+26
-9
No files matched your search
+15
-9
@@ -358,8 +358,10 @@ export class HostState {
|
||||
export class AppState {
|
||||
// pinnedNames: the names of the WAN hosts to pin.
|
||||
constructor(localHosts, pinnedNames = DEFAULT_PINNED) {
|
||||
this.wan = WAN_HOSTS.map(
|
||||
(h) => new HostState(h, pinnedNames.includes(h.name)),
|
||||
this.wan = sortedWAN(
|
||||
WAN_HOSTS.map(
|
||||
(h) => new HostState(h, pinnedNames.includes(h.name)),
|
||||
),
|
||||
);
|
||||
this.local = localHosts.map((h) => new HostState(h));
|
||||
this.paused = false;
|
||||
@@ -1269,21 +1271,25 @@ function appendDebugLogLine(entry) {
|
||||
|
||||
// --- Sorting -----------------------------------------------------------------
|
||||
|
||||
// Sort WAN hosts: pinned hosts first (alphabetically), then unpinned hosts
|
||||
// by last latency ascending, with unreachable hosts at the bottom.
|
||||
function sortAndRebuildWAN(state) {
|
||||
log.debug("WAN hosts re-sorted");
|
||||
const pinned = state.wan
|
||||
// The WAN hosts sorted: pinned hosts first (alphabetically), then unpinned
|
||||
// hosts by last latency ascending, with unreachable hosts at the bottom.
|
||||
function sortedWAN(hosts) {
|
||||
const pinned = hosts
|
||||
.filter((h) => h.pinned)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
const rest = state.wan.filter((h) => !h.pinned);
|
||||
const rest = hosts.filter((h) => !h.pinned);
|
||||
rest.sort((a, b) => {
|
||||
if (a.lastLatency === null && b.lastLatency === null) return 0;
|
||||
if (a.lastLatency === null) return 1;
|
||||
if (b.lastLatency === null) return -1;
|
||||
return a.lastLatency - b.lastLatency;
|
||||
});
|
||||
state.wan = [...pinned, ...rest];
|
||||
return [...pinned, ...rest];
|
||||
}
|
||||
|
||||
function sortAndRebuildWAN(state) {
|
||||
log.debug("WAN hosts re-sorted");
|
||||
state.wan = sortedWAN(state.wan);
|
||||
|
||||
const container = document.getElementById("wan-hosts");
|
||||
container.innerHTML = wanRowsHTML(state.wan);
|
||||
|
||||
Reference in new issue
Block a user