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

feat: ingredients knowledge panels #10904

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

stephanegigandet
Copy link
Contributor

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.

image

@stephanegigandet stephanegigandet requested a review from a team as a code owner October 15, 2024 15:51
@github-actions github-actions bot added 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🌐 Translations labels Oct 15, 2024
@alexgarel
Copy link
Member

/update_tests_results

Copy link
Member

@alexgarel alexgarel left a 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 ?

Comment on lines 7 to 10
[% IF panel.ingredient_description OR panel.wikipedia_abstract %]
"expanded": false,
[% ELSE %]
"expanded": false,
Copy link
Member

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 ?

Copy link
Contributor Author

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...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 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 !

Copy link
Contributor Author

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 %] `,
Copy link
Member

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 ?

Copy link
Contributor Author

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.

{
"element_type": "text",
"text_element": {
"html": `[% panel.ingredient_description %]`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"html": `[% panel.ingredient_description %]`
"html": `[% edq(panel.ingredient_description) %]`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The backticks already take care of escaping quotes, so edq() is not needed:
see https://github.com/openfoodfacts/openfoodfacts-server/blob/main/lib/ProductOpener/KnowledgePanels.pm#L298

Copy link
Member

Choose a reason for hiding this comment

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

ok cool, that's what I though first, but down in the same file you put edq inside backtick !

@@ -55,6 +55,15 @@
`,
},
},
[% END %]
[% END %]
[% IF 1 %]
Copy link
Member

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 ?

Copy link
Contributor Author

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.

@github-actions github-actions bot added API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) 🧪 tests 🧪 integration tests labels Oct 16, 2024
@stephanegigandet
Copy link
Contributor Author

/update_tests_results

@teolemon
Copy link
Member

@stephanegigandet some feedback from this morning's battle testing.

  • Putting the percentage estimate in the title is too proeminent (it should be in the card with a disclaimer) + it wasn't localized (eg: "6% estimation")
  • Mixing English and French is confusing (on products with multiple languages)
  • Sometimes there are hyphen before some ingredients (sub-ingredients ?)

@stephanegigandet
Copy link
Contributor Author

Thanks for the feedback @teolemon

Putting the percentage estimate in the title is too proeminent (it should be in the card with a disclaimer) + it wasn't localized (eg: "6% estimation")

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:

image

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.

Mixing English and French is confusing (on products with multiple languages)

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?

Sometimes there are hyphen before some ingredients (sub-ingredients ?)

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.

@stephanegigandet
Copy link
Contributor Author

I changed a bit the display:

image

@stephanegigandet
Copy link
Contributor Author

Related issue on the mobile app: openfoodfacts/smooth-app#5700

@github-actions github-actions bot added the CSS label Oct 16, 2024
@teolemon
Copy link
Member

"it should be in the card", (....) That's one of the added value compared to the original list of ingredients from the package:

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%)

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.

"estimation 6%" or "estimé à 6%" or "6% estimé" sounds more French than "6% estimation". or at least with an hyphen "6% - Estimation"

Mixing English and French is confusing (on products with multiple languages)

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

Sometimes there are hyphen before some ingredients (sub-ingredients ?)

Quick n Dirty fix: ↳
17:45
https://www.alt-codes.net/arrow_alt_codes.php

@stephanegigandet
Copy link
Contributor Author

Probably we should have vegan, vegetarian, icons next to them, plus whether the ingredient is an agribalyse/ecobalyse match.

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.

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

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:

image

@teolemon
Copy link
Member

@stephanegigandet
Copy link
Contributor Author

/update_tests_results

Copy link

sonarcloud bot commented Oct 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) CSS Ingredients knowledge panel 🧪 integration tests 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests 🌐 Translations
Projects
Status: Reviewer approved
Development

Successfully merging this pull request may close these issues.

3 participants