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: "No nutrition facts" switch not working as intended #4583

Merged

Conversation

g123k
Copy link
Contributor

@g123k g123k commented Mar 22, 2022

PR that fixes two issues:

  • If Nutrition data is set to OFF, the table beneath shouldn't be displayed
  • If Nutrition data is set to OFF, no nutritional data is sent to the API

#4582

@g123k g123k requested a review from a team as a code owner March 22, 2022 09:57
@g123k g123k changed the title fix: No nutrition facts switch not working as intended fix: "No nutrition facts" switch not working as intended Mar 22, 2022
@g123k g123k linked an issue Mar 22, 2022 that may be closed by this pull request
@@ -551,10 +555,11 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
// Add no nutrition data entry to map
if (binding.checkboxNoNutritionData.isChecked) {
targetMap[ApiFields.Keys.NO_NUTRITION_DATA] = "on"
Copy link
Member

Choose a reason for hiding this comment

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

So we send the boolean to deactivate, but do we send the boolean to reactivate, along or before nutrients ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, this is not the case right now.

Currently in the code, the app checks if the field is null (= no nutrition data) or == "ON"
So I will just send a null in the other cases. Otherwise I am afraid of generating some bugs

Copy link
Contributor Author

@g123k g123k Mar 22, 2022

Choose a reason for hiding this comment

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

That should be OK right now, with the new commit #9ce02dd

@g123k g123k force-pushed the nutrional_facts_edition_no_nutrition branch from b36c782 to 9ce02dd Compare March 22, 2022 13:19
@@ -575,6 +575,10 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
targetMap += getNutrientMapIfUpdated(view)
}

// We force a null value here for "no nutrition", instead of an "off" String,
// to be sure to do not break other apps
targetMap[ApiFields.Keys.NO_NUTRITION_DATA] = null
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@g123k g123k Mar 22, 2022

Choose a reason for hiding this comment

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

Look at line 335, on Android the check is if != null -> true

I have improved the checks to ensure, "on" is true and everything else is false

@g123k
Copy link
Contributor Author

g123k commented Mar 23, 2022

The code should now be OK with comments from openfoodfacts/api-documentation#70

@sonarcloud
Copy link

sonarcloud bot commented Mar 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@teolemon
Copy link
Member

thank you @g123k , merging and releasing to internal 👍

@teolemon teolemon merged commit 0c26ad1 into openfoodfacts:develop Mar 23, 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.

The "No Nutrition facts" toggle does not work correctly
2 participants