fix(web): tolerate null drive-ledger dynamics on drive detail - #116
Conversation
JSON null / omitted nested ledgers made DriveLedgerCompactPanel read regen_wh on undefined and trip the energy-ledger error boundary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5b104204-65b7-4d04-90a4-e2d5897b8e2e
There was a problem hiding this comment.
🟡 Changes recommended
dynamics remains required even though omitted payloads are supported.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates drive-detail energy ledger rendering to tolerate missing or null physics dynamics.
Changes:
- Safely access regen and friction-brake values.
- Align nested ledger types with nullable API responses.
- Add regression tests for null, omitted, and populated dynamics.
File summaries
| File | Summary |
|---|---|
web/src/features/driving/components/drive-detail/DriveLedgerCompactPanel.tsx |
Safely renders missing dynamics values. |
web/src/features/driving/components/drive-detail/DriveLedgerCompactPanel.test.tsx |
Tests null, omitted, and populated dynamics. |
web/src/api/types.ts |
Updates nested ledger nullability. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| unknown_intervals: PhysicsUnknownInterval[] | ||
| // Nested ledgers are Go pointers; encoding/json emits null (or omits | ||
| // after camelCase transforms) when that domain has no samples. | ||
| dynamics: PhysicsLongitudinalDynamics | null |
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
There was a problem hiding this comment.
🔵 Needs a closer look
The TypeScript contract does not yet cover omitted dynamics and nullable points responses.
Review details
Suppressed comments (2)
web/src/api/types.ts:3798
- The new regression test explicitly deletes
dynamicsand the component now supports thatundefinedcase, but this interface still declares the property as always present. If omitted keys are an accepted payload shape, make this property optional (dynamics?: PhysicsLongitudinalDynamics | null) so consumers are forced to handle both null and missing values;camelCaseKeyspreserves present keys and does not make the required type accurate for an omitted source key.
dynamics: PhysicsLongitudinalDynamics | null
web/src/api/types.ts:3798
- This nullable-contract update misses the nested
pointsarray.internal/physics/ledger.godeclaresLongitudinalDynamics.Pointswithoutomitempty, anddynamicsLedgerpasses the nila.pointsslice when a window has no samples, so a non-nulldynamicscan still containpoints: null; the TypeScript field remainsPhysicsDynamicsPoint[]. ModelPhysicsLongitudinalDynamics.pointsasPhysicsDynamicsPoint[] | nulland add a null-points fixture so the contract matches the response thatDynamicsPanelalready normalizes withasList.
// Nested ledgers are Go pointers; encoding/json emits null (or omits
// after camelCase transforms) when that domain has no samples.
dynamics: PhysicsLongitudinalDynamics | null
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Summary
Drive detail pages (
/drives/:id) showed Energy ledger failed to load becauseDriveLedgerCompactPanelreadledger.dynamics.regen_whwhen Go encoded a missing nested ledger as JSONnull(or the client omitted the key). That threw inside thedrive-detail:energy-ledgererror boundary.Changes
DriveLedgerCompactPanelPhysicsLedgerdomains as| nullto match Go pointersnulland omitteddynamicsTest plan
npx vitest runDriveLedgerCompactPanel + PhysicsLedgerPagenpx tsc --noEmitdocker compose build(api, web, workers)How to verify
Open a drive like
/drives/393. The energy ledger panel should render (Unknown regen/friction if dynamics is missing) instead of the error banner.