← back to Desktop Dotbar

ticket-states.js

36 lines

'use strict';
// The ticket-state row the bar ALWAYS renders (Steve 2026-09-25: "nav bar should be including all
// from orig nav bar... blocked, parked, doing, idle etc."). The original Swift TicketBar showed its
// OPEN/BLOCKED/DOING/PARKED tiles permanently ("…" placeholder when it had no data); the Electron
// port hid zero states AND hid the whole row whenever the board was unreachable — which is how a
// dead ticket-board after a reboot erased every ticket chip with no signal at all.
//
// Three states per chip, never two: measured-nonzero, measured-zero (dimmed), NOT-measured
// (board unreachable / never fetched: count null, rendered as "–" + offline). A missing board
// must never look like "0 blocked".
const TICKET_STATES = [
  { key: 'blocked', section: 'blocked', label: 'blocked', css: '#f87171' },
  { key: 'open',    section: 'open',    label: 'open',    css: '#e5e7eb' },
  { key: 'idle',    section: 'stopped', label: 'idle',    css: '#9ca3af' },
  { key: 'doing',   section: 'doing',   label: 'doing',   css: '#60a5fa' },
  { key: 'parked',  section: 'parked',  label: 'parked',  css: '#f9a8d4' },
  // Steve 2026-09-25 "add dw and non dw here": the same active population, cut the OTHER way —
  // by business, not by state. dw + non-dw always equals the five state counts above, so the two
  // halves of the row cross-check each other at a glance. Segmentation is the board's own
  // (dw-segment.js), and each chip drills into the matching board section.
  { key: 'dw',      section: 'dw',      label: 'dw',      css: '#34d399', divider: true },
  { key: 'nondw',   section: 'nondw',   label: 'non-dw',  css: '#c084fc' },
];

// snap = the server's tickets snapshot ({updated, ok, blocked, open, ...}).
function ticketStates(snap) {
  const s = snap || {};
  const measured = !!s.updated && s.ok !== false;
  return TICKET_STATES.map(t => {
    const n = measured && Number.isFinite(s[t.key]) ? s[t.key] : null;
    return { ...t, n, measured: n !== null, zero: n === 0 };
  });
}

module.exports = { TICKET_STATES, ticketStates };