v0.42.4_fixes
This commit is contained in:
1 parent
efc6eda4cd
commit
51631810e1
29 files changed
+1192
-394
No files matched your search
+114
-21
@@ -115,8 +115,10 @@ function refreshVhostBackendPopup(status = latestStatus) {
|
||||
}
|
||||
if (!list.children.length) list.append(el("li", t("vhBackendPopupEmpty"), "fine"));
|
||||
const foot = el("p", t("vhBackendPopupHint"), "fine vhost-backend-popup-hint");
|
||||
const closeFocused = current.node.querySelector(".vhost-backend-popup-close") === document.activeElement;
|
||||
current.node.replaceChildren(headingRow, list, foot);
|
||||
current.node.setAttribute("aria-labelledby", heading.id);
|
||||
if (closeFocused) headingRow.querySelector(".vhost-backend-popup-close")?.focus({ preventScroll: true });
|
||||
positionVhostBackendPopup();
|
||||
}
|
||||
function toggleVhostBackendPopup(id, trigger, backendId = null) {
|
||||
@@ -176,12 +178,17 @@ function syncVhostSortDirection() {
|
||||
control.setAttribute("aria-label", t(vhostListPrefs.descending ? "backendSortDescending" : "backendSortAscending"));
|
||||
}
|
||||
function applyPreferences(preferences) {
|
||||
// A queued local change must survive the response to an earlier save.
|
||||
if (!poolPreferenceSaveQueued) poolTablePrefs = normalizePoolTablePrefs(preferences);
|
||||
vhostListPrefs = normalizeVhostListPrefs(preferences);
|
||||
// Updating backend columns should never reconstruct the unrelated Vhost list.
|
||||
// Keep any newer local column change while an earlier write is in flight.
|
||||
const nextPool = poolPreferenceSaveQueued ? poolTablePrefs : normalizePoolTablePrefs(preferences);
|
||||
const nextVhost = normalizeVhostListPrefs(preferences);
|
||||
const poolChanged = JSON.stringify(nextPool) !== JSON.stringify(poolTablePrefs);
|
||||
const vhostChanged = JSON.stringify(nextVhost) !== JSON.stringify(vhostListPrefs);
|
||||
poolTablePrefs = nextPool; vhostListPrefs = nextVhost;
|
||||
const poolSort = $("pool-sort"); if (poolSort) poolSort.value = poolTablePrefs.sort;
|
||||
const vhostSort = $("vhost-sort"); if (vhostSort) vhostSort.value = vhostListPrefs.sort;
|
||||
syncPoolColumns(); syncPoolSortDirection(); syncVhostSortDirection(); applyPoolTableView(); render();
|
||||
if (poolChanged) { syncPoolColumns(); syncPoolSortDirection(); preserveScrollAnchor(applyPoolTableView); }
|
||||
if (vhostChanged) { syncVhostSortDirection(); preserveScrollAnchor(render); }
|
||||
}
|
||||
async function saveVhostListPrefs() {
|
||||
if (!authenticated) return;
|
||||
@@ -242,7 +249,13 @@ function applyPoolTableView() {
|
||||
const result = typeof a === "number" && typeof b === "number" ? a - b : compareText(a, b);
|
||||
return poolTablePrefs.descending ? -result : result;
|
||||
});
|
||||
body.replaceChildren(...rows);
|
||||
// Retain rows that are already ordered correctly. A needless detach of a
|
||||
// focused/anchored table row can jump the page even when sorting is unchanged.
|
||||
let cursor = body.firstElementChild;
|
||||
for (const row of rows) {
|
||||
if (row === cursor) cursor = cursor.nextElementSibling;
|
||||
else body.insertBefore(row, cursor);
|
||||
}
|
||||
let visible = 0;
|
||||
for (const row of rows) { const match = !query || (row.poolSearchValue || "").includes(query); row.hidden = !match; if (match) visible++; }
|
||||
syncPoolColumns(); syncPoolSortDirection();
|
||||
@@ -268,7 +281,9 @@ function initPoolTableTools() {
|
||||
const visible = new Set(poolTablePrefs.columns);
|
||||
if (input.checked) visible.add(input.dataset.poolColumnToggle); else visible.delete(input.dataset.poolColumnToggle);
|
||||
if (!visible.size) { input.checked = true; toast(t("backendColumnsRequired"), true); return; }
|
||||
poolTablePrefs.columns = poolColumns.filter(key => visible.has(key)); void savePoolTablePrefs(); syncPoolColumns(); applyBackendOverviewView();
|
||||
poolTablePrefs.columns = poolColumns.filter(key => visible.has(key));
|
||||
preserveScrollAnchor(() => { syncPoolColumns(); applyBackendOverviewView(); });
|
||||
void savePoolTablePrefs();
|
||||
}));
|
||||
syncPoolColumns(); syncPoolSortDirection();
|
||||
}
|
||||
@@ -469,6 +484,63 @@ const BO_EXTRA_CELLS = {
|
||||
if (extra.h1 + extra.h2) cell.append(el("small", `H2 ${boPercent(extra.h2, extra.h1 + extra.h2)}`));
|
||||
},
|
||||
};
|
||||
// Keep filter buttons and keyed table rows mounted between live samples.
|
||||
// Replacing them every few seconds discards keyboard focus and browser scroll anchors.
|
||||
const BO_FILTERS = [["all", "backendFilterAll"], ["up", "vhUp"], ["down", "vhDown"], ["other", "backendFilterOther"]];
|
||||
function syncBackendOverviewFilters(filters, counts) {
|
||||
if (filters.getAttribute("aria-label") !== t("backendFilterLabel")) filters.setAttribute("aria-label", t("backendFilterLabel"));
|
||||
for (const [key, label] of BO_FILTERS) {
|
||||
let chip = [...filters.children].find(button => button.dataset.boFilter === key);
|
||||
if (!chip) {
|
||||
chip = el("button", undefined, `bo-chip is-${key}`);
|
||||
chip.type = "button"; chip.dataset.uiIconName = "none"; chip.dataset.boFilter = key;
|
||||
chip.append(el("span"), el("b"));
|
||||
chip.addEventListener("click", () => { boFilter = key; applyBackendOverviewView(); });
|
||||
filters.append(chip);
|
||||
}
|
||||
const pressed = String(boFilter === key);
|
||||
if (chip.getAttribute("aria-pressed") !== pressed) chip.setAttribute("aria-pressed", pressed);
|
||||
const title = chip.querySelector("span"), count = chip.querySelector("b");
|
||||
if (title.textContent !== t(label)) title.textContent = t(label);
|
||||
if (count.textContent !== String(counts[key])) count.textContent = String(counts[key]);
|
||||
count.classList.toggle("is-zero", !counts[key]);
|
||||
}
|
||||
}
|
||||
function syncBackendOverviewRows(body, rendered) {
|
||||
const rowKey = row => row.dataset.boRowKey !== undefined ? `row:${row.dataset.boRowKey}` : `detail:${row.dataset.boDetailKey}`;
|
||||
const existing = new Map([...body.children].map(row => [rowKey(row), row]));
|
||||
const rows = rendered.map(next => {
|
||||
const key = rowKey(next);
|
||||
const current = existing.get(key);
|
||||
if (!current || current.children.length !== next.children.length || current.dataset.boColumns !== next.dataset.boColumns) return next;
|
||||
if (current.className !== next.className) current.className = next.className;
|
||||
for (let index = 0; index < current.cells.length; index++) {
|
||||
const cell = current.cells[index], updated = next.cells[index];
|
||||
if (cell.className !== updated.className) cell.className = updated.className;
|
||||
if (cell.title !== updated.title) cell.title = updated.title;
|
||||
if (cell.colSpan !== updated.colSpan) cell.colSpan = updated.colSpan;
|
||||
if (updated.dataset.boColumn && cell.dataset.boColumn !== updated.dataset.boColumn) cell.dataset.boColumn = updated.dataset.boColumn;
|
||||
if (updated.dataset.boColumn === "toggle") {
|
||||
// The expansion control itself must survive refreshes, not just regain focus.
|
||||
const button = cell.querySelector("button"), nextButton = updated.querySelector("button");
|
||||
if (button && nextButton) {
|
||||
if (button.getAttribute("aria-expanded") !== nextButton.getAttribute("aria-expanded")) button.setAttribute("aria-expanded", nextButton.getAttribute("aria-expanded"));
|
||||
} else cell.replaceChildren(...updated.childNodes);
|
||||
} else if (cell.innerHTML !== updated.innerHTML) {
|
||||
cell.replaceChildren(...updated.childNodes);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
});
|
||||
// Do not detach rows already in the correct position: moving a focused row
|
||||
// needlessly also breaks the scroll anchor on some browsers.
|
||||
let cursor = body.firstElementChild;
|
||||
for (const row of rows) {
|
||||
if (row === cursor) cursor = cursor.nextElementSibling;
|
||||
else body.insertBefore(row, cursor);
|
||||
}
|
||||
while (cursor) { const next = cursor.nextElementSibling; cursor.remove(); cursor = next; }
|
||||
}
|
||||
function applyBackendOverviewView() {
|
||||
if (overviewViewsHidden()) { overviewViewsPending = true; return; }
|
||||
const body = $("bo-rows"); if (!body) return;
|
||||
@@ -479,14 +551,7 @@ function applyBackendOverviewView() {
|
||||
for (const item of boItems) counts[item.group]++;
|
||||
const summary = $("bo-summary"); if (summary) summary.textContent = boItems.length ? t("backendSummary").replace("{up}", counts.up).replace("{total}", boItems.length) : "";
|
||||
const filters = $("bo-filters");
|
||||
if (filters) {
|
||||
filters.setAttribute("aria-label", t("backendFilterLabel"));
|
||||
filters.replaceChildren(...[["all", "backendFilterAll"], ["up", "vhUp"], ["down", "vhDown"], ["other", "backendFilterOther"]].map(([key, label]) => {
|
||||
const chip = el("button", undefined, `bo-chip is-${key}`), count = el("b", String(counts[key]), counts[key] ? "" : "is-zero");
|
||||
chip.type = "button"; chip.dataset.uiIconName = "none"; chip.setAttribute("aria-pressed", String(boFilter === key));
|
||||
chip.append(el("span", t(label)), count); chip.addEventListener("click", () => { boFilter = key; applyBackendOverviewView(); }); return chip;
|
||||
}));
|
||||
}
|
||||
if (filters) syncBackendOverviewFilters(filters, counts);
|
||||
const key = poolTablePrefs.sort;
|
||||
const list = boItems.filter(item => (boFilter === "all" || item.group === boFilter) && (!query || item.search.includes(query)));
|
||||
list.sort((left, right) => {
|
||||
@@ -503,10 +568,15 @@ function applyBackendOverviewView() {
|
||||
visibleColumns.has("p95") && ["p95", t("backendColP95"), true], visibleColumns.has("probe") && ["probe", t("backendColProbe"), true], visibleColumns.has("cache") && ["cache", t("backendColCache")], visibleColumns.has("traffic") && ["traffic", t("vhTraffic"), true],
|
||||
visibleColumns.has("causes") && ["causes", t("backendColCauses")], visibleColumns.has("protocol") && ["protocol", t("backendColProtocol")], showEvent && ["event", t("backendLastEvent")],
|
||||
].filter(Boolean);
|
||||
const head = $("bo-head"); if (head) head.replaceChildren(...columns.map(([id, label, numeric]) => { const th = el("th", label, numeric ? "is-num" : ""); th.dataset.boColumn = id; if (id === "toggle") th.setAttribute("aria-label", t("backendDetailsToggle")); return th; }));
|
||||
const head = $("bo-head");
|
||||
if (head && (head.children.length !== columns.length || columns.some(([id, label], index) => head.children[index].dataset.boColumn !== id || head.children[index].textContent !== label))) {
|
||||
head.replaceChildren(...columns.map(([id, label, numeric]) => { const th = el("th", label, numeric ? "is-num" : ""); th.dataset.boColumn = id; if (id === "toggle") th.setAttribute("aria-label", t("backendDetailsToggle")); return th; }));
|
||||
}
|
||||
const columnSignature = columns.map(([id]) => id).join("|");
|
||||
const rows = [];
|
||||
for (const item of list) {
|
||||
const row = el("tr", undefined, `bo-row is-${item.tone}${item.disabled ? " is-disabled" : ""}`), open = expandable && boOpen.has(item.key);
|
||||
row.dataset.boRowKey = item.key; row.dataset.boColumns = columnSignature;
|
||||
for (const [id] of columns) {
|
||||
const cell = el("td"); cell.dataset.boColumn = id;
|
||||
if (id === "toggle") {
|
||||
@@ -550,17 +620,18 @@ function applyBackendOverviewView() {
|
||||
rows.push(row);
|
||||
if (open) {
|
||||
const detail = el("tr", undefined, "bo-detail-row"), cell = el("td"), grid = el("div", undefined, "bo-detail-grid"); cell.colSpan = Math.max(1, columns.length);
|
||||
detail.dataset.boDetailKey = item.key; detail.dataset.boColumns = columnSignature;
|
||||
const values = { generation: item.generation, generationRequests: item.generationRequests, generationAge: item.generationAgeText, rotations: item.rotations, lastFailure: item.lastFailureText, lastRecovery: item.lastRecoveryText };
|
||||
for (const column of detailColumns) { const entry = el("div", undefined, "bo-detail-item"), value = el("b", String(values[column] ?? "-")); if (column === "lastFailure" && item.lastFailureMs) { value.className = "is-failed"; value.title = item.lastFailureDetail || ""; } else if (column === "lastRecovery" && item.lastRecoveryMs) value.className = "is-recovered"; entry.append(el("span", t(BO_SORT_LABELS[column])), value); grid.append(entry); }
|
||||
cell.append(grid); detail.append(cell); rows.push(detail);
|
||||
}
|
||||
}
|
||||
const scroller = body.closest(".table-scroll"), scrollTop = scroller?.scrollTop ?? 0, scrollLeft = scroller?.scrollLeft ?? 0;
|
||||
body.replaceChildren(...rows);
|
||||
// Writing scroll offsets forces a synchronous layout; only restore a
|
||||
// position the user actually scrolled to.
|
||||
if (scroller && (scrollTop || scrollLeft)) { scroller.scrollTop = scrollTop; scroller.scrollLeft = scrollLeft; }
|
||||
if (hadFocus) [...body.querySelectorAll(".bo-expand")].find(button => button.dataset.boKey === focusKey)?.focus({ preventScroll: true });
|
||||
syncBackendOverviewRows(body, rows);
|
||||
// Sorting or filtering can change the table height; preserve the user's
|
||||
// scroll position, but avoid forced layout for an untouched scroll offset.
|
||||
if (scroller && (scrollTop || scrollLeft)) { if (scroller.scrollTop !== scrollTop) scroller.scrollTop = scrollTop; if (scroller.scrollLeft !== scrollLeft) scroller.scrollLeft = scrollLeft; }
|
||||
if (hadFocus && document.activeElement?.dataset?.boKey !== focusKey) [...body.querySelectorAll(".bo-expand")].find(button => button.dataset.boKey === focusKey)?.focus({ preventScroll: true });
|
||||
const empty = $("bo-empty");
|
||||
if (empty) { empty.textContent = boItems.length ? t("backendSearchEmpty") : t("vhHealthEmpty"); empty.hidden = list.length > 0 || !boHasProxy; }
|
||||
const toggleAll = document.querySelectorAll("#bo-column-options [data-pool-column-toggle]"); toggleAll.forEach(input => { input.checked = visibleColumns.has(input.dataset.poolColumnToggle); });
|
||||
@@ -807,6 +878,7 @@ function renderStatus(status) {
|
||||
const row = el("tr"); if (vhostDisabled) row.classList.add("pool-vhost-disabled"); const poolDomain = status.backend_pool_domains?.[pool.id]; const poolLabel = poolDomain ? `${pool.id} (${poolDomain})` : pool.id; const cells = [poolLabel, `${member.id}${member.backup ? " / " + t("vhBackup") : ""}`, label, activeLimit, member.requests, member.errors,
|
||||
member.ewma_latency_ms > 0 ? `${member.ewma_latency_ms.toFixed(1)} ms` : "-", `${rateBytes(memberTraffic)}/s`, extra.text.rate, extra.text.statuses, extra.text.p95, extra.text.cache, extra.text.probe, extra.text.causes, extra.text.protocol, member.upstream_client_generation ?? "-", member.upstream_client_generation_requests ?? "-", generationAgeText, member.upstream_client_rotations_total ?? "-", lastFailure, lastRecovery];
|
||||
const sortValues = { vhost: poolLabel.toLowerCase(), backend: String(member.id || "").toLowerCase(), status: label.toLowerCase(), active: Number(member.active) || 0, requests: Number(member.requests) || 0, errors: Number(member.errors) || 0, latency: Number(member.ewma_latency_ms) || 0, traffic: memberTraffic, ...extra.sort, generation: Number(member.upstream_client_generation) || 0, generationRequests: Number(member.upstream_client_generation_requests) || 0, generationAge: Number.isFinite(generationAge) ? generationAge : -1, rotations: Number(member.upstream_client_rotations_total) || 0, lastFailure: Number(member.last_failure_at_ms) || 0, lastRecovery: Number(member.last_recovered_ms) || 0 };
|
||||
row.dataset.poolKey = JSON.stringify([pool.id, member.id]);
|
||||
row.poolSort = sortValues; row.poolSearchValue = [poolLabel, member.id, label, member.status, member.last_failure_class, member.last_failure_detail].filter(Boolean).join(" ").toLowerCase();
|
||||
if (buildPoolRows) cells.forEach((value, index) => { const cell = el("td", String(value ?? "-")); const column = poolColumns[index]; cell.dataset.poolColumn = column; cell.title = column === "status" ? (vhostDisabled ? t("vhDisabled") : `${label} · ${healthDetail}`) : column === "lastFailure" ? (member.last_failure_detail || lastFailure) : String(value ?? "-"); if (column === "status" && !vhostDisabled) cell.className = member.status === "down" ? "status-error" : member.status === "up" ? "status-good" : ""; if (column === "lastFailure" && member.last_failure_at_ms) cell.classList.add("backend-last-failure"); row.append(cell); }); if (buildPoolRows) rows.push(row);
|
||||
const tone = vhostDisabled ? "muted" : member.health_mode === "off" && member.status === "up" ? "muted" : member.status === "up" ? "up" : member.status === "down" ? "down" : member.status === "checking" || member.status === "draining" ? "warn" : "muted";
|
||||
@@ -860,7 +932,28 @@ function renderStatus(status) {
|
||||
const hasConfiguredProxySource = [...configuredVhosts.values()].some(vhost =>
|
||||
vhostRequiresProxy(vhost)
|
||||
);
|
||||
if (buildPoolRows) $("pool-rows").replaceChildren(...rows); else overviewViewsPending = true;
|
||||
if (buildPoolRows) {
|
||||
const body = $("pool-rows"), existing = new Map([...body.rows].map(row => [row.dataset.poolKey, row]));
|
||||
const refreshed = rows.map(next => {
|
||||
const current = existing.get(next.dataset.poolKey);
|
||||
if (!current || current.cells.length !== next.cells.length) return next;
|
||||
current.className = next.className;
|
||||
current.poolSort = next.poolSort; current.poolSearchValue = next.poolSearchValue;
|
||||
for (let index = 0; index < current.cells.length; index++) {
|
||||
const cell = current.cells[index], changed = next.cells[index];
|
||||
if (cell.textContent !== changed.textContent) cell.textContent = changed.textContent;
|
||||
if (cell.title !== changed.title) cell.title = changed.title;
|
||||
if (cell.className !== changed.className) cell.className = changed.className;
|
||||
}
|
||||
return current;
|
||||
});
|
||||
let cursor = body.firstElementChild;
|
||||
for (const row of refreshed) {
|
||||
if (row === cursor) cursor = cursor.nextElementSibling;
|
||||
else body.insertBefore(row, cursor);
|
||||
}
|
||||
while (cursor) { const next = cursor.nextElementSibling; cursor.remove(); cursor = next; }
|
||||
} else overviewViewsPending = true;
|
||||
renderBackendOverview(overviewItems, hasConfiguredProxySource, status, false);
|
||||
const backendDiagnosticsCard = $("backend-diagnostics-card");
|
||||
backendDiagnosticsCard?.classList.toggle("is-no-proxy", !hasConfiguredProxySource);
|
||||
|
||||
Reference in new issue
Block a user