Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #3046 - refactored NutritionPage around Nutrient #3194

Merged
merged 4 commits into from
Oct 25, 2022

Conversation

monsieurtanuki
Copy link
Contributor

New file:

  • nutrition_add_nutrient_button.dart: Button that opens an "add nutrient" dialog.

Impacted files:

  • nutrition_container.dart: heavy refactoring using Nutrient instead of String ids
  • nutrition_page_loaded.dart: now using Nutrient instead of String ids
  • portion_helper.dart: now using new nutriments.getValue instead of json map trick
  • product_query.dart: added fields NUTRIMENT_DATA_PER and NUTRITION_DATA
  • app/pubspec.lock: wtf
  • smooth_app/pubspec.lock: wtf
  • pubspec.yaml: upgraded to openfoodfacts: 1.26.2

What

  • In Smoothie we used to be able to edit nutrition values for both 100g and serving.
  • But that's not the way things work in the end: the end-user inputs only one of them (one "column"), and the other is computed on the server side using the "serving size" factor (cf. the website interface).
  • Therefore, now we only display one column, with a <Nutrient, double?> map behind, and only when the user clicks on "Save!" will we say if it's for 100g or for serving - depending on the "per serving?" switch. That fixes the referenced issue.
  • We also used to deconstruct the nutrient json map in order to get/set values. We now have a clean approach with the new Nutrient class and the related methods in Nutriments.

Fixes bug(s)

New file:
* `nutrition_add_nutrient_button.dart`: Button that opens an "add nutrient" dialog.

Impacted files:
* `nutrition_container.dart`: heavy refactoring using `Nutrient` instead of `String` ids
* `nutrition_page_loaded.dart`: now using `Nutrient` instead of `String` ids
* `portion_helper.dart`: now using new `nutriments.getValue` instead of json map trick
* `product_query.dart`: added fields `NUTRIMENT_DATA_PER` and `NUTRITION_DATA`
* `app/pubspec.lock`: wtf
* `smooth_app/pubspec.lock`: wtf
* `pubspec.yaml`: upgraded to `openfoodfacts: 1.26.2`
url: "https://pub.dartlang.org"
source: hosted
version: "1.26.0"
path: "../../../openfoodfacts-dart"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incoherence with smooth_app/pubspec.yaml.

Impacted file:
* `registration_login_test.dart`: unrelated test fix after off-dart upgrade
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Merging #3194 (468768b) into develop (a3066e7) will increase coverage by 0.03%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           develop   #3194      +/-   ##
==========================================
+ Coverage     6.19%   6.22%   +0.03%     
==========================================
  Files          252     253       +1     
  Lines        12519   12458      -61     
==========================================
  Hits           776     776              
+ Misses       11743   11682      -61     
Impacted Files Coverage Δ
...b/pages/product/nutrition_add_nutrient_button.dart 0.00% <0.00%> (ø)
...oth_app/lib/pages/product/nutrition_container.dart 0.00% <0.00%> (ø)
...h_app/lib/pages/product/nutrition_page_loaded.dart 0.00% <0.00%> (ø)
...s/smooth_app/lib/pages/product/portion_helper.dart 0.00% <0.00%> (ø)
packages/smooth_app/lib/query/product_query.dart 0.00% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

Heyy @monsieurtanuki looks all good to me, although you are probably the only one who really knows about the nutrition management in smoothie 😆

Just the pubspec.lock should be fixed

Comment on lines 755 to 758
name: openfoodfacts
url: "https://pub.dartlang.org"
source: hosted
version: "1.26.0"
path: "../../../openfoodfacts-dart"
relative: true
source: path
version: "1.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

Yeah this will very likely break deployment, can you run pub get again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/// Button that opens an "add nutrient" dialog.
///
/// The code was moved here in order to declutter [NutritionPageLoaded].
Copy link
Member

Choose a reason for hiding this comment

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

I like that but I don't think this comment is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I've removed the comment.
I guess next time I'll put it in a "TODO: remove - just for the review!" comment

Impacted files:
* `nutrition_add_nutrient_button.dart`: removed unnecessary comment
* `pubspec.lock`: refreshed
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

@monsieurtanuki monsieurtanuki merged commit c608459 into openfoodfacts:develop Oct 25, 2022
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev!

@M123-dev M123-dev added this to the v4 milestone Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nutrition edit - If i switch to serving, it removes all values, except the energy in kcal
4 participants