Skip to content

Refactor: Standardize Measurement Precision and Improve UI Layout#915

Merged
CodeWithCJ merged 4 commits intomainfrom
dev
Mar 14, 2026
Merged

Refactor: Standardize Measurement Precision and Improve UI Layout#915
CodeWithCJ merged 4 commits intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

@CodeWithCJ CodeWithCJ commented Mar 14, 2026

Description

Provide a brief summary of your changes.

Related Issue

PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: # #898

Refactored application-wide measurement handling to ensure consistent 1-decimal precision for weight, body fat, and body measurements.

Key Changes:

  • Centralized Precision: Implemented global constants to enforce professional measurement standards across Diary, Charts, and Reports.
  • Accurate Storage: Refactored workout logging to store weights in Metric (kg), preventing precision loss from repeated pound-to-kilogram conversions.
  • UI Improvements: Optimized UnitInput padding and layout in exercise forms to ensure decimal values (e.g., 10.5 kg) are fully visible.
  • Service Updates: Standardized bodyCompositionService.ts and numberFormatting.ts to reflect the new precision rules.

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the application's measurement handling to ensure consistent precision and improve data integrity. By centralizing precision rules and storing weights in a single metric unit, the system avoids common floating-point issues and provides a more reliable user experience. Additionally, UI adjustments to input fields enhance usability for entering precise decimal values.

Highlights

  • Standardized Measurement Precision: Implemented a centralized MEASUREMENT_PRECISION constant to enforce consistent 1-decimal precision for weight, body fat, and body measurements across the application, including Diary, Charts, and Reports.
  • Improved Weight Storage Logic: Refactored workout logging to store weights internally in Metric (kg) only, eliminating repeated pound-to-kilogram conversions and preventing potential precision loss.
  • Enhanced UI for Unit Inputs: Optimized the UnitInput component by dynamically setting the step attribute based on the defined precision and adjusting padding to ensure decimal values are fully visible.
  • Updated Services and Utilities: Modified bodyCompositionService.ts to output body fat percentages with 1-decimal precision and updated numberFormatting.ts and unitConversions.ts to leverage the new centralized precision settings.
Changelog
  • SparkyFitnessFrontend/package.json
    • Updated the frontend package version from 0.16.5.2 to 0.16.5.3.
  • SparkyFitnessFrontend/src/components/ui/UnitInput.tsx
    • Imported getPrecision from @workspace/shared.
    • Added a type prop to UnitInputProps to specify the measurement type.
    • Modified setVal2 and setVal1 logic to use getPrecision for toFixed when displaying values.
    • Dynamically calculated the step attribute for input fields based on getPrecision to allow correct decimal increments.
    • Adjusted className padding for the input field from pr-12 to pr-9 and the unit span from right-3 to right-2 for better layout.
  • SparkyFitnessFrontend/src/pages/Diary/EditExerciseEntryDialog.tsx
    • Removed convertWeight from usePreferences destructuring.
    • Modified initial sets state to store weight as Number(set.weight) (metric kg) directly, removing convertWeight and toFixed.
    • Updated the onSave logic to pass set.weight directly, as it is now already in metric (kg).
  • SparkyFitnessFrontend/src/pages/Diary/ExerciseEntryDisplay.tsx
    • Removed convertWeight from usePreferences destructuring.
    • Imported formatWeight from numberFormatting.
    • Replaced direct convertWeight().toFixed(1) with formatWeight for displaying set weights.
  • SparkyFitnessFrontend/src/pages/Diary/ExerciseSortableItems.tsx
    • Imported UnitInput component.
    • Replaced the standard Input component with UnitInput for weight input, passing type='weight', unit, and value props, and handling onChange with the metric value.
  • SparkyFitnessFrontend/src/pages/Diary/LogExerciseEntryDialog.tsx
    • Removed convertWeight from usePreferences destructuring.
    • Modified initial sets state to store weight as Number(set.weight) (metric kg) directly, removing convertWeight and toFixed.
    • Updated the onSubmit logic to pass set.weight directly, as it is now already in metric (kg).
  • SparkyFitnessFrontend/src/pages/Exercises/WorkoutPresetForm.tsx
    • Imported UnitInput component.
    • Removed convertWeight from usePreferences destructuring.
    • Modified initial sets state to store weight as Number(set.weight) (metric kg) directly, removing convertWeight and toFixed.
    • Replaced the standard Input component with UnitInput for weight input, passing type='weight', unit, and value props, and handling onChange with the metric value.
    • Updated the onSubmit logic to pass set.weight directly, as it is now already in metric (kg).
  • SparkyFitnessFrontend/src/pages/Reports/MeasurementChartsGrid.tsx
    • Imported formatMeasurement and getPrecision.
    • Updated tickFormatter for weight charts to use getPrecision('weight', weightUnit).
    • Updated tickFormatter for neck, waist, and hips charts to use getPrecision('measurement', measurementUnit).
    • Replaced formatHeight with formatMeasurement in tooltip formatters for neck, waist, and hips.
  • SparkyFitnessFrontend/src/pages/Reports/ReportsTables.tsx
    • Imported formatMeasurement.
    • Replaced formatHeight with formatMeasurement for displaying neck, waist, and hips measurements in tables.
    • Adjusted generic numeric value formatting from toFixed(2) to toFixed(1).
  • SparkyFitnessFrontend/src/services/bodyCompositionService.ts
    • Changed body fat percentage calculations (bfp.toFixed(2)) to bfp.toFixed(1) for all methods (Navy and BMI).
  • SparkyFitnessFrontend/src/utils/numberFormatting.ts
    • Imported formatMeasurement as formatMeasurementInternal.
    • Exported a new formatMeasurement function that uses formatMeasurementInternal.
  • SparkyFitnessFrontend/src/utils/unitConversions.ts
    • Imported getPrecision from @workspace/shared.
    • Modified formatWeight to use getPrecision('weight', unit) for toFixed calculations.
    • Modified formatHeight to use getPrecision('height', unit) for toFixed calculations.
    • Added a new formatMeasurement function that uses getPrecision('measurement', unit) for toFixed calculations.
  • shared/src/constants/measurements.ts
    • Added a new file defining MEASUREMENT_PRECISION constants for weight, height, and general measurements.
    • Implemented getPrecision function to retrieve the defined precision for a given measurement type and unit.
  • shared/src/index.ts
    • Exported the new constants/measurements module.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively standardizes measurement precision across the application by introducing a centralized configuration in the shared workspace. The refactoring to use a new UnitInput component for weight inputs is well-executed, simplifying various forms and dialogs and ensuring that weight is consistently handled in metric units (kg) in the state, which is a great improvement for data integrity. The changes in services and utility functions to adopt the new precision rules are consistent and complete. My feedback includes a suggestion to improve type safety in the new getPrecision function by avoiding @ts-ignore.

@CodeWithCJ CodeWithCJ merged commit be5a479 into main Mar 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant