Stats: Include archived shipments and use source-backed event counts #35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Two data correctness issues on the Stats page:
Archived shipments excluded:
fetchShipments()without arguments returns only active+delivered. The Stats page calls this and gets 16 shipments, but Dashboard shows "10 active · 6 delivered · 4 archived" = 20. Stats undercounts by 4 and the description says "Overview of your Trackbox data" — but it's not all the data.Events = 0:
fetchShipments()returns the list endpoint which does not include event arrays.shipments.reduce((acc, s) => acc + (s.events?.length ?? 0), 0)always returns 0 becauses.eventsis undefined on list items. The Events StatCard shows "0 across all shipments" which is wrong — individual shipments have events.Implementation
File:
frontend/src/pages/Stats.tsxFix 1 — Include archived shipments
Change the fetch to include archived:
Or add an
"all"option tofetchShipmentsinfrontend/src/lib/api.tsthat calls/api/shipments?include_archived=trueif the backend supports it.Fix 2 — Events count
Either:
a) Add a
/api/statsendpoint on the backend that returns pre-computed counts including total events (query:SELECT COUNT(*) FROM shipment_events)b) Remove the Events StatCard since it cannot be computed from the list endpoint without N+1 fetches
Option (a) is cleaner. If the backend route does not exist, remove the Events card for now and add a
// TODO: needs /api/stats endpointcomment.Acceptance criteria
Brand identity alignment
Stats should be useful operational signals, not generic KPI decoration. Totals must reflect the user's owned dataset, including archived shipments, and event counts must be source-backed.
Brand-compliant implementation notes
Operational overview of shipments, sources, and parser activity.Additional acceptance criteria
Migrated from GitHub issue #14: https://github.com/bullitt186/trackbox/issues/14
Original author: @bullitt186
Original created: 2026-06-27T13:24:10Z
Original labels: ux
Stats: Include archived shipments in totals and fix Events count (shows 0)to Stats: Include archived shipments and use source-backed event countsImplemented in commit
bd6b0e7. Stats now fetches active, delivered, and archived shipments separately and combines them intoallShipmentsfor the total count and distribution charts. The Events StatCard was removed since event arrays are not included in the list endpoint response (events are per-shipment detail only). Total, Active, and Delivered counts now match Dashboard totals including archived records.