Skip to content

fix(web): tolerate null drive-ledger dynamics on drive detail - #116

Merged
atulmgupta merged 2 commits into
mainfrom
fix/drive-detail-energy-ledger
Sep 18, 2026
Merged

atulmgupta merged 2 commits into
mainfrom
fix/drive-detail-energy-ledger

Conversation

@atulmgupta

Copy link
Copy Markdown
Contributor

Summary

Drive detail pages (/drives/:id) showed Energy ledger failed to load because DriveLedgerCompactPanel read ledger.dynamics.regen_wh when Go encoded a missing nested ledger as JSON null (or the client omitted the key). That threw inside the drive-detail:energy-ledger error boundary.

Changes

  • Optional-chain regen / friction-brake energy on DriveLedgerCompactPanel
  • Type nested PhysicsLedger domains as | null to match Go pointers
  • Regression test for JSON null and omitted dynamics

Test plan

  • npx vitest run DriveLedgerCompactPanel + PhysicsLedgerPage
  • npx tsc --noEmit
  • docker 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.

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
Copilot AI lite review requested due to automatic review settings September 18, 2026 02:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread web/src/api/types.ts
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

Copilot AI commented Sep 18, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Verify TypeScript build

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 copilot-code-review.yml file. Read the docs for details.

Copilot AI review requested due to automatic review settings September 18, 2026 04:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 dynamics and the component now supports that undefined case, 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; camelCaseKeys preserves 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 points array. internal/physics/ledger.go declares LongitudinalDynamics.Points without omitempty, and dynamicsLedger passes the nil a.points slice when a window has no samples, so a non-null dynamics can still contain points: null; the TypeScript field remains PhysicsDynamicsPoint[]. Model PhysicsLongitudinalDynamics.points as PhysicsDynamicsPoint[] | null and add a null-points fixture so the contract matches the response that DynamicsPanel already normalizes with asList.
  // 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

Copilot AI commented Sep 18, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Verify TypeScript build

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 copilot-code-review.yml file. Read the docs for details.

@atulmgupta
atulmgupta merged commit 7fe491b into main Sep 18, 2026
18 of 19 checks passed
@atulmgupta
atulmgupta deleted the fix/drive-detail-energy-ledger branch September 18, 2026 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants