feat: Configurable decimals places for delta times - #532
Conversation
📝 WalkthroughWalkthroughThis PR introduces user-configurable decimal places for lap time delta display in standings and relative widgets. The feature adds a type field, default values, rendering logic, and UI controls across the settings and component layers, allowing users to select 1–3 decimal places for formatting. ChangesDecimal Places Configuration for Lap Time Deltas
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@toba-k do you still want this in? PR still in draft |
Yes ! I was waiting for the performance PR's to be merged first since we discussed about not having new features until then. This one is pretty small and should not cause any issues. I will rebase, re-test, then put it as ready |
6ba7c80 to
1a44466
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/types/widgetConfigs.ts (1)
154-154: ⚡ Quick winEncode the 1–3 range in
lapTimeDeltas.decimalPlacesThe settings UI only allows selecting
decimalPlacesvalues1,2, or3, butsrc/types/widgetConfigs.tscurrently types bothStandingsConfig.lapTimeDeltas.decimalPlacesandRelativeConfig.lapTimeDeltas.decimalPlacesas a plainnumber. Constraining this to a numeric-literal union keeps the config contract consistent across layers.♻️ Proposed refactor
+export type LapTimeDeltaDecimalPlaces = 1 | 2 | 3; + export interface StandingsConfig { ... - lapTimeDeltas: { enabled: boolean; numLaps: number; decimalPlaces: number }; + lapTimeDeltas: { + enabled: boolean; + numLaps: number; + decimalPlaces: LapTimeDeltaDecimalPlaces; + }; ... } export interface RelativeConfig { ... - lapTimeDeltas: { enabled: boolean; numLaps: number; decimalPlaces: number }; + lapTimeDeltas: { + enabled: boolean; + numLaps: number; + decimalPlaces: LapTimeDeltaDecimalPlaces; + }; ... }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/types/widgetConfigs.ts` at line 154, The lapTimeDeltas.decimalPlaces field is currently typed as a plain number but the UI only permits 1, 2, or 3; update the type to the numeric-literal union 1 | 2 | 3 to enforce that constraint. Locate the lapTimeDeltas property in the widget config types (the lapTimeDeltas declaration and both StandingsConfig.lapTimeDeltas.decimalPlaces and RelativeConfig.lapTimeDeltas.decimalPlaces) and replace the number type with 1 | 2 | 3; keep all other fields (enabled, numLaps) unchanged and run type checks to ensure no callers violate the narrower type.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/frontend/components/Standings/components/DriverInfoRow/cells/LapTimeDeltasCell.tsx`:
- Line 8: LapTimeDeltasCell currently calls
Math.abs(deltaValue).toFixed(decimalPlaces) without validating the optional
decimalPlaces; fix by validating and normalizing decimalPlaces in
LapTimeDeltasCell (the variable passed into the toFixed call) so it’s a safe
integer in the 0–100 range (e.g., fallback to 1 when undefined/NaN and clamp
using Math.min/Math.max), then use the normalized value in the toFixed call;
reference symbols: LapTimeDeltasCell, decimalPlaces, deltaValue, and the
Math.abs(...).toFixed(...) expression.
---
Nitpick comments:
In `@src/types/widgetConfigs.ts`:
- Line 154: The lapTimeDeltas.decimalPlaces field is currently typed as a plain
number but the UI only permits 1, 2, or 3; update the type to the
numeric-literal union 1 | 2 | 3 to enforce that constraint. Locate the
lapTimeDeltas property in the widget config types (the lapTimeDeltas declaration
and both StandingsConfig.lapTimeDeltas.decimalPlaces and
RelativeConfig.lapTimeDeltas.decimalPlaces) and replace the number type with 1 |
2 | 3; keep all other fields (enabled, numLaps) unchanged and run type checks to
ensure no callers violate the narrower type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c5ef3fb1-0c1f-4731-81a0-6441b89ba819
📒 Files selected for processing (7)
src/frontend/components/Settings/sections/RelativeSettings.tsxsrc/frontend/components/Settings/sections/StandingsSettings.tsxsrc/frontend/components/Standings/components/DriverInfoRow/DriverInfoRow.ReorderableConfig.stories.tsxsrc/frontend/components/Standings/components/DriverInfoRow/DriverInfoRow.tsxsrc/frontend/components/Standings/components/DriverInfoRow/cells/LapTimeDeltasCell.tsxsrc/types/defaultDashboard.tssrc/types/widgetConfigs.ts
Description
Adds the possibility to chose the decimal places for the delta times in the Standings and Relative widget. User can choose up to 3 decimals, with 1 being the default.
Screenshots
Menu

In-game (example with 2 decimals)

Type of Change
Checklist
npm testnpm run lintand fixed any issuesSummary by CodeRabbit
New Features