From 6504328e58b883e445ceb91ed7277db6f9611fee Mon Sep 17 00:00:00 2001 From: david kiania Date: Tue, 16 Jun 2026 11:52:46 +0300 Subject: [PATCH] fix(tickets): keep INC header KPIs from being clobbered by other tabs Late async loaders (notably the boot-time logistics loadAll) called their KPI renderer unconditionally, overwriting the shared header strip after the user had switched to another tab. Guard renderKpis / renderFuelKpis / renderIncKpis so each only updates the header when its own tab is active. Co-Authored-By: Claude Opus 4.8 --- src/index.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.html b/src/index.html index 23e89d2..fd0c63c 100644 --- a/src/index.html +++ b/src/index.html @@ -454,6 +454,10 @@ const API_BASE = (window.FLEETOPS_API_BASE && /^https?:\/\//.test(window.FLEETOP const $ = (id) => document.getElementById(id); const num = (v, d = 0) => (v == null || isNaN(v)) ? '—' : Number(v).toLocaleString('en', { minimumFractionDigits: d, maximumFractionDigits: d }); const intg = (v) => (v == null || isNaN(v)) ? '—' : Number(v).toLocaleString('en'); +// Which tab owns the shared header KPI strip right now — guards late async +// loaders (e.g. boot loadAll finishing after the user switched tabs) from +// clobbering another tab's header. +const activeTab = () => (document.querySelector('.tab.active')?.dataset.tab) || 'logistics'; async function api(path) { const r = await fetch(`${API_BASE}${path}`, { headers: { 'Accept': 'application/json' } }); @@ -525,6 +529,7 @@ $('refresh').addEventListener('click', loadAll); // RENDER — KPIs // ============================================================================ function renderKpis(totals, fuelL) { + if (activeTab() !== 'logistics') return; // don't clobber another tab's header totals = totals || {}; const kpis = [ ['accent', intg(totals.vehicles), 'Vehicles'], @@ -700,6 +705,7 @@ function fuelQs() { } function renderFuelKpis(t) { + if (activeTab() !== 'fuel') return; t = t || {}; const kpis = [ ['accent', intg(t.vehicles_fuelled), 'Vehicles'], @@ -1007,6 +1013,7 @@ function updateVehScale() { // ── render: header KPIs + metric strip + tables + closure chart ───────────── function renderIncKpis(m) { + if (activeTab() !== 'tickets') return; m = m || {}; const so = (m.sla && m.sla.open) || {}; const k = [ ['accent', intg(m.open_now), 'INC open'],