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
+25
-8
No files matched your search
@@ -1107,6 +1107,17 @@ test("after the user sets the interval to 10s, unpins datavi.be and pins GitHub,
|
|||||||
assert.deepEqual(pinnedNames(after), ["GitHub"]);
|
assert.deepEqual(pinnedNames(after), ["GitHub"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a reload with Google and GitHub pinned starts with them at the top, by name", (t) => {
|
||||||
|
mockStorage(t, { "netwatch-pinned": '["Google","GitHub"]' });
|
||||||
|
|
||||||
|
const state = new AppState([], savedPinnedNames());
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
state.wan.slice(0, 2).map((h) => h.name),
|
||||||
|
["GitHub", "Google"],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("after the user unpins every target, a reload starts with none pinned", (t) => {
|
test("after the user unpins every target, a reload starts with none pinned", (t) => {
|
||||||
mockStorage(t, {});
|
mockStorage(t, {});
|
||||||
const before = new AppState([], savedPinnedNames());
|
const before = new AppState([], savedPinnedNames());
|
||||||
|
|||||||
+14
-8
@@ -358,8 +358,10 @@ export class HostState {
|
|||||||
export class AppState {
|
export class AppState {
|
||||||
// pinnedNames: the names of the WAN hosts to pin.
|
// pinnedNames: the names of the WAN hosts to pin.
|
||||||
constructor(localHosts, pinnedNames = DEFAULT_PINNED) {
|
constructor(localHosts, pinnedNames = DEFAULT_PINNED) {
|
||||||
this.wan = WAN_HOSTS.map(
|
this.wan = sortedWAN(
|
||||||
|
WAN_HOSTS.map(
|
||||||
(h) => new HostState(h, pinnedNames.includes(h.name)),
|
(h) => new HostState(h, pinnedNames.includes(h.name)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
this.local = localHosts.map((h) => new HostState(h));
|
this.local = localHosts.map((h) => new HostState(h));
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
@@ -1269,21 +1271,25 @@ function appendDebugLogLine(entry) {
|
|||||||
|
|
||||||
// --- Sorting -----------------------------------------------------------------
|
// --- Sorting -----------------------------------------------------------------
|
||||||
|
|
||||||
// Sort WAN hosts: pinned hosts first (alphabetically), then unpinned hosts
|
// The WAN hosts sorted: pinned hosts first (alphabetically), then unpinned
|
||||||
// by last latency ascending, with unreachable hosts at the bottom.
|
// hosts by last latency ascending, with unreachable hosts at the bottom.
|
||||||
function sortAndRebuildWAN(state) {
|
function sortedWAN(hosts) {
|
||||||
log.debug("WAN hosts re-sorted");
|
const pinned = hosts
|
||||||
const pinned = state.wan
|
|
||||||
.filter((h) => h.pinned)
|
.filter((h) => h.pinned)
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.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) => {
|
rest.sort((a, b) => {
|
||||||
if (a.lastLatency === null && b.lastLatency === null) return 0;
|
if (a.lastLatency === null && b.lastLatency === null) return 0;
|
||||||
if (a.lastLatency === null) return 1;
|
if (a.lastLatency === null) return 1;
|
||||||
if (b.lastLatency === null) return -1;
|
if (b.lastLatency === null) return -1;
|
||||||
return a.lastLatency - b.lastLatency;
|
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");
|
const container = document.getElementById("wan-hosts");
|
||||||
container.innerHTML = wanRowsHTML(state.wan);
|
container.innerHTML = wanRowsHTML(state.wan);
|
||||||
|
|||||||
Reference in new issue
Block a user