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 <noreply@anthropic.com>
This commit is contained in:
david kiania 2026-06-16 11:52:46 +03:00
parent e32ec92cbf
commit 6504328e58

View file

@ -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'],