Phase 5: Supervisor and Stall screens, weld map, heat table, clock and CO verification
ci / frontend (push) Successful in 34s
ci / server (push) Successful in 7m15s
ci / image (push) Successful in 39s
ci / e2e (push) Successful in 2m4s

The shop at parity with the old build. Supervisor screen (department chips, CO headline, numbers, Change orders
on hold, station grid with clocks and CO tags, boards) and Stall screen (station picker, hero, My packets,
Submitted). Shop steps on the packet page: assign with station, welder picker and stamp; pull back; Start, Pause,
Resume; Submit with a PIN signature and the missing steps as links; review with Send to Q.C., Return to station
and Skip Q.C. route; a lead's read-only review. Weld map (pdf.js viewer with pan, pinch, zoom, full screen; marks
with leader lines; weld sheet; weld record with field CAS; carried marks). Heat map (heat table placed, dragged,
sized, removed; legacy amber tags; borrowed heat map read-only). Checklist tab with templates from settings.
VOID stamps on voided pages. Change orders: CO-n labels, supervisor verify with signature, approval copies the
heat table to the new sheet and the BOM merge keeps the shop's values. Server clock of record with VISUAL ticket
hours beside it. Presence per packet over SSE. Migration 0006 (bfx, bfy, carried_from, checklist_templates).
New endpoints /api/shop/board, /api/shop/stations, /api/shop/stall, /api/departments/{code}/people.

Tests: policy oracle for every shop action, role and status; clock arithmetic; concurrent inserts; CO apply;
frontend geometry, heat table, clock, checklist, weld sheet, screens; seven Playwright scenarios. Docs updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-16 22:46:56 -06:00
co-authored by Claude Fable 5.1
parent 39a4eb5213
commit 5a4174e0c2
81 changed files with 11532 additions and 352 deletions
+67 -4
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "react";
import { useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
import { AuthCtx } from "./context";
import type { PresenceUser } from "./types";
interface EventHandlers {
@@ -8,6 +9,11 @@ interface EventHandlers {
onChanged?: (payload: unknown) => void;
}
/** Phase 5: presence carries the packet each user has open. */
export interface PacketPresenceUser extends PresenceUser {
packet_id?: number | string | null;
}
function parse(data: unknown): unknown {
if (typeof data !== "string") return null;
try {
@@ -17,13 +23,41 @@ function parse(data: unknown): unknown {
}
}
/*
* The packet this browser is looking at. The packet page sets it (usePacketPresence) and the one EventSource
* reopens with ?packet_id= so the server's presence knows it. A module store keeps AuthProvider unchanged.
*/
let focusPacket: number | null = null;
const focusListeners = new Set<() => void>();
export function setPresencePacket(id: number | null): void {
if (focusPacket === id) return;
focusPacket = id;
for (const fn of focusListeners) fn();
}
function subscribeFocus(fn: () => void): () => void {
focusListeners.add(fn);
return () => {
focusListeners.delete(fn);
};
}
const getFocus = () => focusPacket;
/** The stream URL for the packet in view. */
export function eventsUrl(packetId: number | null): string {
return packetId ? `/api/events?packet_id=${encodeURIComponent(String(packetId))}` : "/api/events";
}
/**
* Opens /api/events with EventSource while `sessionId` is set.
* A `session` event with this session id and action "revoked" calls onRevoked.
* `presence` is kept in state for later phases.
* `presence` is kept in state. The stream reopens when the packet in view changes.
*/
export function useEvents(sessionId: string | null, handlers: EventHandlers): PresenceUser[] {
const [presence, setPresence] = useState<PresenceUser[]>([]);
const packetId = useSyncExternalStore(subscribeFocus, getFocus, getFocus);
const ref = useRef(handlers);
useEffect(() => {
ref.current = handlers;
@@ -31,7 +65,7 @@ export function useEvents(sessionId: string | null, handlers: EventHandlers): Pr
useEffect(() => {
if (!sessionId || typeof EventSource === "undefined") return;
const es = new EventSource("/api/events", { withCredentials: true });
const es = new EventSource(eventsUrl(packetId), { withCredentials: true });
es.addEventListener("session", (ev) => {
const p = parse((ev as MessageEvent).data);
@@ -59,7 +93,36 @@ export function useEvents(sessionId: string | null, handlers: EventHandlers): Pr
es.close();
setPresence([]);
};
}, [sessionId]);
}, [sessionId, packetId]);
return presence;
}
/** The other people on `packetId`, from the presence list. One entry per user, sorted by name. */
export function othersOn(users: readonly PacketPresenceUser[], packetId: number, myId: string | null | undefined): PacketPresenceUser[] {
const seen = new Set<string>();
const out: PacketPresenceUser[] = [];
for (const u of users) {
if (u.packet_id === null || u.packet_id === undefined || Number(u.packet_id) !== packetId) continue;
if (myId && u.user_id === myId) continue;
if (seen.has(u.user_id)) continue;
seen.add(u.user_id);
out.push(u);
}
return out.sort((a, b) => a.display_name.localeCompare(b.display_name));
}
/**
* Marks `packetId` as the packet in view while mounted, and returns the other people looking at it.
* Works under AuthProvider; outside it (a bare test render) it returns an empty list.
*/
export function usePacketPresence(packetId: number | null): PacketPresenceUser[] {
const ctx = useContext(AuthCtx);
useEffect(() => {
if (!packetId) return;
setPresencePacket(packetId);
return () => setPresencePacket(null);
}, [packetId]);
if (!ctx || !packetId) return [];
return othersOn(ctx.presence as PacketPresenceUser[], packetId, ctx.me?.user.id);
}