-
-
Notifications
You must be signed in to change notification settings - Fork 392
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: ingredients knowledge panels #10904
base: main
Are you sure you want to change the base?
Conversation
/update_tests_results |
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.
LGTM but some comments and maybe a mistake ?
[% IF panel.ingredient_description OR panel.wikipedia_abstract %] | ||
"expanded": false, | ||
[% ELSE %] | ||
"expanded": false, |
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 strange !
Shouldn't the second expanded be true ?
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's temporary, in fact what we really want is to make the first one (no description) not expandable. But currently the non expandable panels are displayed in a very different way (at least on the web, I haven't checked mobile). So we will need a better way.
"expanded": false, | ||
[% END %] | ||
"title_element": { | ||
// Note: the app displays line feeds as line feeds... |
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.
// Note: the app displays line feeds as line feeds... | |
// Note: the app displays line feeds as line feeds... | |
// so we have to keep whole title expression on one line ! |
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.
I just added a double backtick function so that we can have things on multiple lines that are then converted to one line without linebreaks.
[% END %] | ||
"title_element": { | ||
// Note: the app displays line feeds as line feeds... | ||
"title": ` [% dash = "-" %] [% dash.repeat(panel.level) %] [% display_taxonomy_tag_name("ingredients", panel.ingredient_id) %] [% IF panel.ingredient.percent.defined %] ([% round(panel.ingredient.percent) %]%) [% ELSIF panel.ingredient.percent_estimate.defined %] ([% round(panel.ingredient.percent_estimate) %]% [% lang("estimate") %]) [% END %] `, |
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.
Can't we eventually deport this computation in the ingredient panel creation ?
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.
Well the idea of using Template::Toolkit was that people could change the layout / design decisions from the panels, without having to change the Perl code. So that's why I try to put things that are more design things in the template. Here I tried to show the sub-ingredients, and I'm just pushing dashes in front, which is not very clear (but it's something..). There may be other better ways to do that.
@@ -55,6 +55,15 @@ | |||
`, | |||
}, | |||
}, | |||
[% END %] | |||
[% END %] | |||
[% IF 1 %] |
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 should be if we have feature ingredient right ?
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.
ah it should be if we have an ingredients_list panel, but the condition I put before didn't work, so I just put 1. I'll change that.
Co-authored-by: Alex Garel <alex@openfoodfacts.org>
Co-authored-by: Alex Garel <alex@openfoodfacts.org>
/update_tests_results |
@stephanegigandet some feedback from this morning's battle testing.
|
Thanks for the feedback @teolemon
I'm not sure what you mean by "it should be in the card", if we only see the % of the ingredient when we click on it, it's less useful than being able to see the % for all ingredients. That's one of the added value compared to the original list of ingredients from the package: Not sure either about the localization, today we display "Potato (6% estimate)" in English and "Pomme de terre (6% estimation)" in French, so it is localized. Maybe "estimate" takes too much room? We could do ~6%, but it's less explicit.
We display the text ingredient list in the user's language if we do have it, and we display the ingredients panels in the user language in all cases. I would think it's more useful that way?
Yes, this is to convey that there sub ingredients (or sub sub sub ingredients). Not ideal, but better than a completely flat list I guess. We could try to indent more instead of using hyphens, but we would need to extend a bit the knowledge panels grammar. |
Related issue on the mobile app: openfoodfacts/smooth-app#5700 |
Probably we should have vegan, vegetarian, icons next to them, plus whether the ingredient is an agribalyse/ecobalyse match. Your proposal regarding rounding might solve my concerns (it was looking ridiculous to have 10 ingredients+ including glucose syrup at 0%)
"estimation 6%" or "estimé à 6%" or "6% estimé" sounds more French than "6% estimation". or at least with an hyphen "6% - Estimation"
I had the case of a product with a German ingredient list which included glucose syrup. In the app we showed the French list, but the German normalized ingredients were shown
Quick n Dirty fix: ↳ |
So at this point, we are showing each ingredient in a knowledge panel title. In the current version of knowledge panels, we can display 1 icon at the left, but that's it. We can add more text, but adding icons would require changes to the knowledge panel API + its implementation on web and mobile.
We analyze ingredients only in 1 language, and we use the ingredient analysis to display the list of ingredients, so that's the current "normal" behaviour. For the sub-ingredients, I'm not sure if the down + right arrow is more clear. It works well with 1 level, but multiple levels is less obvious: |
|
/update_tests_results |
Quality Gate passedIssues Measures |
=head2 convert_multiline_string_to_singleline_without_line_breaks_and_extra_spaces($line) | ||
|
||
Helper function to allow to enter multiline strings in JSON templates. | ||
The function converts the multiline string into a single line string. | ||
|
||
Line breaks are converted to spaces, and multiple spaces are converted to a single space. | ||
|
||
This function is useful in templates where we use IF statements etc. to generate a single value like a title. | ||
|
||
=cut | ||
|
||
sub convert_multiline_string_to_singleline_without_line_breaks_and_extra_spaces ($line) { |
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.
Good idea :-)
"title_element": { | ||
// Note: the app displays line feeds as line feeds... | ||
"title": ` [% dash = "-" %] [% dash.repeat(panel.level) %] [% display_taxonomy_tag_name("ingredients", panel.ingredient_id) %] [% IF panel.ingredient.percent.defined %] ([% round(panel.ingredient.percent) %]%) [% ELSIF panel.ingredient.percent_estimate.defined %] ([% round(panel.ingredient.percent_estimate) %]% [% lang("estimate") %]) [% END %] `, | ||
// double backticks: convert to a single line without newlines and extra spaces |
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.
😲 cool !
…dfacts-server into ingredients-panels
/update_tests_results |
Quality Gate passedIssues Measures |
This PR adds knowledge panels for ingredients, to list each ingredient below the ingredient list.
Each ingredient panel can be opened to get a description from: https://github.com/openfoodfacts/openfoodfacts-web/tree/main/knowledge_panels
Known issue: most ingredients do not currently have a description, they contain an empty panel.