fix: staffMonitor pill visibility — robust parsing, error logging, fuzzy flight matching#41
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Agent-Logs-Url: https://github.com/TargetMisser/FlightWorkApp/sessions/f12eb588-f82f-49de-b605-0c9ff5f127fe Co-authored-by: TargetMisser <52361977+TargetMisser@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR restores visibility of the staffMonitor-derived stand/gate/check-in/belt “pills” by making the staffMonitor fetch/parsing more resilient and improving flight-number matching in FlightScreen.
Changes:
- Add HTTP error logging + exception logging and dev-only parse diagnostics to
fetchStaffMonitorData. - Make the HTML row filter more permissive for detecting
clsFlightrows. - Add a fuzzy fallback flight-number match when exact matching fails.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/utils/staffMonitor.ts |
Adds logging, relaxes row detection regex, and adds dev-only parse summary logging to improve reliability/diagnostics. |
src/screens/FlightScreen.tsx |
Adds fallback matching logic (stripped/uppercased) and dev-only “no match” logging to improve pill hit-rate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!resp.ok) { | ||
| console.warn(`[staffMonitor] HTTP error for nature=${nature}: ${resp.status} ${resp.statusText}`); | ||
| return []; | ||
| } |
There was a problem hiding this comment.
fetchStaffMonitorData is polled every 60s (see FlightScreen effect), so logging on every non-2xx response can spam production device logs when the endpoint is down. Consider gating this warning behind __DEV__, or rate-limiting/deduping (e.g., log only on status change / first failure within a window).
| } catch (e) { | ||
| console.error(`[staffMonitor] fetch/parse error for nature=${nature}:`, e); | ||
| return []; |
There was a problem hiding this comment.
Because this function runs on a 60s interval, emitting console.error on every exception can produce a large volume of logs in production during outages/parsing changes. Consider __DEV__-gating, rate-limiting, or tracking last-error time/message to avoid repeated identical logs.
| const normalizeForMatching = (s: string) => s.replace(/[\s\-_]/g, '').toUpperCase(); | ||
| const normFnStripped = normalizeForMatching(normFn); | ||
| const smPool = activeTab === 'departures' ? staffMonitorDeps : staffMonitorArrs; | ||
| const smFlight = | ||
| smPool.find(sm => sm.flightNumber === normFn) ?? | ||
| smPool.find(sm => normalizeForMatching(sm.flightNumber) === normFnStripped); |
There was a problem hiding this comment.
renderFlight now does up to two linear scans of smPool per rendered item. With a non-trivial number of flights this becomes O(renderedFlights × staffMonitorFlights) work during renders. Consider precomputing a lookup map (exact and stripped keys) with useMemo when staffMonitorDeps/Arrs changes, and then doing O(1) lookups inside renderFlight.
Stand/gate/checkin/belt pills introduced in v1.3.4 were never visible due to silent fetch failures, an overly strict HTML row filter, and fragile exact-string flight number matching.
What Changed
src/utils/staffMonitor.tsconsole.warnon non-2xx HTTP response;console.errorincatch(previously swallowed silently)clsFlightas a substring of the class attribute, tolerating extra classes, attribute spacing, and either quote style:__DEV__log: parsed count + first 5 flight numbers after each fetchsrc/screens/FlightScreen.tsxnormalizeForMatching: strips spaces/hyphens/underscores, uppercases) when the exact normalised flight number has no hit in the staffMonitor pool__DEV__log when a flight card finds no match despite a non-empty pool, showing both the normalised and stripped forms for easy comparisonChecklist
Screenshot or Video
No UI changes — pills already existed, this restores their data source.
Review Notes
normalizeForMatchingis defined inline inside the render callback; could be extracted tostaffMonitor.tsif reuse is needed later.__DEV__logs are stripped from production builds.Original prompt
Problema
In
FlightScreen.tsx, le pill arancioni con stand, gate, check-in e belt (provenienti dastaffMonitor.ts) non vengono mai visualizzate nonostante il commit v1.3.4 le abbia introdotte.Le cause identificate sono:
1. Errori silenziosi nella
fetchIn
src/utils/staffMonitor.ts, il bloccocatchritorna semplicemente[]senza loggare nulla:Se la chiamata HTTP fallisce (CORS, rete, URL errato), non si sa perché.
2. Match del numero di volo fragile
Il match in
FlightScreen.tsxè un'uguaglianza esatta:Se il formato del numero di volo dello staffMonitor differisce minimamente da quello di FR24 (es. spazi, maiuscole/minuscole, prefissi diversi), il match fallisce silenziosamente e la pill non viene mostrata.
3. Parsing HTML fragile
Il filtro delle righe cerca
class="clsFlight"con virgolette doppie o singole, ma potrebbe non catturare varianti con attributi extra, spazi o formati leggermente diversi.4. Nessun fallback visivo
Se lo staffMonitor non restituisce dati, l'utente non ha alcun feedback visivo che indichi "dati non ancora disponibili" o "caricamento in corso".
Interventi richiesti
src/utils/staffMonitor.tsconsole.warn/console.errornei blocchicatche quando la risposta HTTP non è OK, per facilitare il debug.clsFlight(es.clsFlightcome sottostringa dell'attributo class, non solo match esatto con virgolette doppie/singole).__DEV__il numero di risultati parsati e un campione dei numeri di volo trovati.src/screens/FlightScreen.tsxnormalizeFlightNumber) ma aggiungere anche un fallback che confronta ignorando spazi e caratteri speciali.__DEV__quando un volo non trova corrispondenza nello staffMonitor, per aiutare il debug.Note
if (__DEV__)per i log di debug in modo che non appaiano in produzione.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Ciao, mi controlli come mai non vedo il numero di gate, stand e checkin nonostante l'aggiornamento?
Assistant: Il repository rilevante sembra essere FlightWorkApp. Ora cerco le issue o i commit recenti legati a gate, stand e check-in.
User: Che succ
Assistant: Sembra che il repository più rilevante per la tua domanda sia FlightWorkApp (
TargetMisser/FlightWorkApp), che gestisce operazioni aeroportuali. Posso dare un'occhiata alle issue aperte o al codice recente per capire perché gate, stand e check-in non vengono visualizzati nonostante l'aggiornamento.Vuoi che controlli:
Dimmi come preferisci procedere! 🙂
User: Commit e codice
Assistant: Procedo a controllare entrambi contemporaneamente!
Assistant: Ora leggo i file chiave:
staffMonitor.ts(il fetcher) eFlightScreen(dove vengono mostrate le pill).Assistant: Ottimo, ho tutti i dettagli. Ecco l'analisi completa:
🔍 Analisi: perché stand/gate/check-in non vengono visualizzati
Cosa fa il codice (v1.3.4)
Il commit più recente (
a6462e3) ha introdotto proprio questa funzionalità. Il flusso è:staffMonitor.tsfa unafetchogni 60 secondi verso:<tr>con celleclass="clsFlight".FlightScreen.tsxcome pill arancioni sotto ogni card, solo se il match per numero di volo riesce.🐛 Le cause probabili per cui non vedi nulla
1.⚠️ Il match del numero di volo fallisce silenziosamente
Il codice normalizza il numero di volo (es.
FR07146 → FR7146) e poi cerca una corrispondenza esatta:Se il formato del numero di volo restituito dallo staffMonitor non corrisponde esattamente a quello di FR24, la pill non appare. Non c'è nessun log di errore visibile.
2.⚠️ La
fetchdello staffMonitor fallisce silenziosamenteIn
staffMonitor.tsil bloccocatchritorna semplicemente[]:Se la chiamata HTTP fallisce (CORS, rete, URL errato, ecc.) non viene registrato nessun errore, e
staffMonitorDeps/staffMonitorArrsrim...This pull request was created from Copilot chat.