Skip to content

fix for auto scale issue in food variants#815

Merged
CodeWithCJ merged 1 commit intomainfrom
dev
Mar 1, 2026
Merged

fix for auto scale issue in food variants#815
CodeWithCJ merged 1 commit intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!

Description

Provide a brief summary of your changes.

Related Issue

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

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 addresses an issue where custom food variant nutrients were not correctly auto-scaling when the serving size was adjusted. The changes ensure that both standard and custom nutrient fields are properly identified and scaled proportionally, and that manual edits to any nutrient field or serving size correctly update the baseline for future calculations, leading to more accurate food tracking.

Highlights

  • Custom Nutrient Scaling: Implemented logic to correctly scale custom nutrient values when the serving size of a food variant is changed and locked.
  • Nutrient Field Identification: Refactored the identification of nutrient fields to properly include custom nutrients, ensuring they are handled consistently with standard nutrients.
  • Original Variant Update Logic: Improved the mechanism for updating the 'original' variant data when manual edits are made, ensuring that subsequent scaling operations use the most current baseline values.
Changelog
  • SparkyFitnessFrontend/src/components/FoodSearch/CustomFoodForm.tsx
    • Refactored isNutrientField check to include custom nutrients.
    • Removed a duplicate nutrientFields array definition.
    • Added a new block to scale custom_nutrients based on serving_size ratio.
    • Modified the else block to universally update originalVariants for any manual change, including nutrient edits or serving size changes when not locked.
Activity
  • No specific review comments or activities have been recorded yet for this pull request.
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 addresses an issue with auto-scaling food variants, specifically for custom nutrients. The changes introduce logic to correctly scale custom nutrients when the serving size is adjusted on a locked variant. Additionally, the code has been refactored to improve readability by extracting the check for custom nutrients into a variable, and a redundant declaration of nutrientFields has been removed. The logic for updating the baseline values for scaling after a manual edit has also been improved to be more robust, using a deep copy of the entire variant. The implementation appears correct and effectively resolves the reported issue.

@CodeWithCJ CodeWithCJ merged commit d12ca66 into main Mar 1, 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