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:
parent
e32ec92cbf
commit
6504328e58
1 changed files with 7 additions and 0 deletions
|
|
@ -454,6 +454,10 @@ const API_BASE = (window.FLEETOPS_API_BASE && /^https?:\/\//.test(window.FLEETOP
|
||||||
const $ = (id) => document.getElementById(id);
|
const $ = (id) => document.getElementById(id);
|
||||||
const num = (v, d = 0) => (v == null || isNaN(v)) ? '—' : Number(v).toLocaleString('en', { minimumFractionDigits: d, maximumFractionDigits: d });
|
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');
|
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) {
|
async function api(path) {
|
||||||
const r = await fetch(`${API_BASE}${path}`, { headers: { 'Accept': 'application/json' } });
|
const r = await fetch(`${API_BASE}${path}`, { headers: { 'Accept': 'application/json' } });
|
||||||
|
|
@ -525,6 +529,7 @@ $('refresh').addEventListener('click', loadAll);
|
||||||
// RENDER — KPIs
|
// RENDER — KPIs
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
function renderKpis(totals, fuelL) {
|
function renderKpis(totals, fuelL) {
|
||||||
|
if (activeTab() !== 'logistics') return; // don't clobber another tab's header
|
||||||
totals = totals || {};
|
totals = totals || {};
|
||||||
const kpis = [
|
const kpis = [
|
||||||
['accent', intg(totals.vehicles), 'Vehicles'],
|
['accent', intg(totals.vehicles), 'Vehicles'],
|
||||||
|
|
@ -700,6 +705,7 @@ function fuelQs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderFuelKpis(t) {
|
function renderFuelKpis(t) {
|
||||||
|
if (activeTab() !== 'fuel') return;
|
||||||
t = t || {};
|
t = t || {};
|
||||||
const kpis = [
|
const kpis = [
|
||||||
['accent', intg(t.vehicles_fuelled), 'Vehicles'],
|
['accent', intg(t.vehicles_fuelled), 'Vehicles'],
|
||||||
|
|
@ -1007,6 +1013,7 @@ function updateVehScale() {
|
||||||
|
|
||||||
// ── render: header KPIs + metric strip + tables + closure chart ─────────────
|
// ── render: header KPIs + metric strip + tables + closure chart ─────────────
|
||||||
function renderIncKpis(m) {
|
function renderIncKpis(m) {
|
||||||
|
if (activeTab() !== 'tickets') return;
|
||||||
m = m || {}; const so = (m.sla && m.sla.open) || {};
|
m = m || {}; const so = (m.sla && m.sla.open) || {};
|
||||||
const k = [
|
const k = [
|
||||||
['accent', intg(m.open_now), 'INC open'],
|
['accent', intg(m.open_now), 'INC open'],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue