-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
feat: Prevention - On the fly quality checks in the product edit form #8258
Conversation
You have successfully added a new SonarCloud configuration ``. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab. |
@@ -34,3 +34,21 @@ | |||
\$('#nutrition_data_div').show(); | |||
} | |||
}); | |||
|
|||
\$('#nutriment_sugars').on('input', function() { | |||
var inputValue = $(this).val(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @stephanegigandet @yuktea
I jQuery is blocking this from working
its like the .val()
is not a function. Uncaught TypeError: this.val is not a function
think i have called the element correctly so it must be working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jnsereko , it's because this file is a template file, so anything starting with $ is interpreted as a variable in the template. If you want the $ to be output in the JS code, you need to escape it like this: \$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @stephanegigandet
this @stephanegigandet somewhat messes up the table. i thought of creating a warning div, just like https://github.com/jnsereko/openfoodfacts-server/blob/d9631fdd0e73ac311a9512ebf156533369f775ae/templates/web/pages/product_edit/product_edit_form_display.tt.html#L78-L82 but since the table is somewhat long, covering almost the whole screen users might not see it |
One option could be to have an extra table row with the warning, just below the value that is problematic. This way you could use the whole row width (the 3 columns). |
@@ -227,6 +227,11 @@ <h1>[% title %]</h1> | |||
|
|||
<td class="nutriment_col" [% column_display_style_nutrition_data %]> | |||
<input class="nutriment_value nutriment_value_as_sold" id="nutriment_[% nutriment.enid %]" name="nutriment_[% nutriment.enid %]" value="[% nutriment.value %]" [% nutriment.disabled %] autocomplete="off"/> | |||
[% IF nutriment.nid == 'saturated-fat' %] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was not specific enough, but the warnings we have in mind are more things like the warnings we have in https://github.com/openfoodfacts/openfoodfacts-server/blob/main/lib/ProductOpener/DataQualityFood.pm#L631
e.g. if the nutrients are per 100g, then we should not have any value greater than 100.
same for sub values: sugars should not be higher than carbohydrates, and saturated fats should not be higher than fat.
Maybe we could start with only those 2 checks, and then gradually add more.
Thanks a lot @jnsereko. The video is nice to clearly understand how it works. About the user interface: I'm afraid that the way it is displayed will have bad side effects:
I suggest two points:
Here is an example I use in Power User Script (but the background color here is too flashy): I'm not sure if the color should be displayed while typing or when the user is leaving the field for another one. |
ea935b4
to
4ff4132
Compare
hello @stephanegigandet @CharlesNepote @yuktea @alexgarel The current push has some changes attending to some of @stephanegigandet and @CharlesNepote suggestions.
The current video in the PR description shows a visual result. |
f08256e
to
085445f
Compare
Hi @jnsereko , this looks quite good, in terms of functionality and how to display the warning, it's great I think. |
var saturated_fats_value; | ||
var fat_value; | ||
|
||
[% FOREACH nutriment IN nutriments %] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but it will generate a huge JS file, with the code repeated for all nutrients.
It would be better to create a javascript array that contains all nutrients, and then have a for loop in Javascript, instead of a foreach loop in the template language.
Well done @jnsereko! The video looks really cool. Last point: I would choose a lighter color to highlight errors, not to frighten people. The yellow is a bit flashy... @stephanegigandet would it be possible to test it on openfoodfacts.net? |
hey @CharlesNepote |
|
||
var required_nutrients_id = ['energy-kj', 'energy-kcal', 'fat', 'saturated-fat', 'sugars', 'carbohydrates', 'fiber', 'proteins', 'salt', 'sodium', 'alcohol']; | ||
|
||
required_nutrients_id.forEach(nutirent_id => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephanegigandet, using the ordinary for loop is tricky. Only the last nutrient, "alcohol" is accessed the colour but the on-input
event exists on other elements
Is this okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good this way, thank you! :)
Could you just replace all the "nutirent" by "nutrient" ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @stephanegigandet
That slipped my eyes
hey @stephanegigandet @alexgarel |
@jnsereko Thank you! |
\$('#nutriment_' + nutrient_id).on('input', function() { | ||
var nutrient_value = \$(this).val(); | ||
var is_above_or_below_100 = isNaN(nutrient_value) || nutrient_value < 0 || nutrient_value > 100; | ||
show_warning(is_above_or_below_100, nutrient_id, "Please enter a value between 0 and 100"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warnings should be added to po/common/common.pot and po/common/en.po so they can be translated, but we can also do that later in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephanegigandet can we do the translations in another PR
i have tried them locally but it might take me some time to make the logic work.
# product_non_normalized_code moved | ||
"Moved 0000012345678 to 12345678", | ||
# removed product with existing id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug that is not related to your PR, could you remove this change?
The bug is fixed in this PR: #8384
Kudos, SonarCloud Quality Gate passed!
|
What
Created an invisible span having a warning on saturated fats and sugars values. inputing an element above the range displays the span.
Screenshot
onfly.mov
Related issue(s) and discussion