Skip to content

feat: M3 raw data knowledge panel #12116

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Conversation

RayanGoubet
Copy link
Collaborator

@RayanGoubet RayanGoubet commented Jul 3, 2025

What

Milestone 3 - Introduce a raw data knowledge panel for core contributors

Capture d’écran du 2025-07-03 13-44-39

Capture d’écran du 2025-07-03 13-44-59

Capture d’écran du 2025-07-03 13-45-22

@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 Jul 3, 2025
@github-project-automation github-project-automation bot moved this to To discuss and validate in 🍊 Open Food Facts Server issues Jul 3, 2025
@teolemon
Copy link
Member

teolemon commented Jul 3, 2025

@RayanGoubet can you add a little preview screenshot ?

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2025

❌ 10 Tests Failed:

Tests completed Failed Passed Skipped
7484 10 7474 0
View the top 3 failed test(s) by shortest run time
tests_integration_api_v3_product_read_t::0083 - get-fields-knowledge-panels-knowledge-panels_excluded-environment_card
Stack Traces | 0.047s run time
not ok 0083 - get-fields-knowledge-panels-knowledge-panels_excluded-environment_card
tests_integration_api_v2_product_read_t::0047 - get-fields-knowledge-panels-knowledge-panels_excluded-environment_card
Stack Traces | 0.0545s run time
not ok 0047 - get-fields-knowledge-panels-knowledge-panels_excluded-environment_card
tests_integration_api_v3_product_read_t::0056 - get-knowledge-panels
Stack Traces | 0.0712s run time
not ok 0056 - get-knowledge-panels

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@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 Jul 3, 2025
sub create_product_card_panel ($product_ref, $target_lc, $target_cc, $options_ref, $request_ref) {
$log->debug("create product card panel", {code => $product_ref->{code}}) if $log->is_debug();

my $base_url = "/world.openfoodfacts.org/facets/brands/";
Copy link
Contributor

Choose a reason for hiding this comment

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

To get the link and the display name, just use this function:

# get_taxonomy_tag_and_link_for_lang computes the display text and link
# in a target language for a canonical tagid
# It returns a hash ref with:
# - display : text of the link in the target language, or English
# - display_lc : language code of the language returned in display
# - known : 0 or 1, indicates if the input tagid exists in the taxonomy
# - tagurl : escaped link to the tag, without the tag type path component

sub get_taxonomy_tag_and_link_for_lang ($target_lc, $tagtype, $tagid) {

@@ -7547,3 +7547,17 @@ msgstr "Report this image to our moderators"
msgctxt "robots_not_served_here"
msgid "Due to heavy abuse from robots, we are unable to serve this page to unidentified users. Please create a free Open Food Facts account to access all of Open Food Facts."
msgstr ""

msgctxt "origin_of_ingredients"
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have translated strings for those, as they are displayed in the product page already.

Check the code for the display_field() function in Web.pm

			my $name = lang($field);
			if ($name eq '') {
				$name = ucfirst(lang($field . "_p"));
			}

[% INCLUDE "api/knowledge-panels/product/product_brands.tt.json" %]
[% END %]

[% IF product.origins_tags %]
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a generic template that works for all field types, instead of having one template per type.

Or maybe simpler, just have one template that loops and displays all the fields.

{
"type": "panel",
"title": "[% display_taxonomy_tag('countries_tags', country) %]"
}[% IF !loop.last %],[% END %]
Copy link
Contributor

Choose a reason for hiding this comment

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

you can put the comma at the end of all entries, including the last one, it should be removed automatically after

@teolemon teolemon moved this from In progress to Needs review in 📖 Knowledge panels Jul 7, 2025
@teolemon teolemon moved this from Needs review to In progress in 📖 Knowledge panels Jul 7, 2025
@@ -0,0 +1,15 @@
[% FOREACH panel IN panel.taxonomy_panels %]
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Each panel contains elements, and those elements can be themselves panels, but when an element is a panel, it just lists the panel id.

You can look at the generated panels for a product to see how the panel elements are defined:
https://fr.openfoodfacts.org/api/v3/produit/7622210449283/prince-gout-chocolat-lu?fields=knowledge_panels

e.g.

{
elements: [
{
element_type: "panel",
panel_element: {
panel_id: "environmental_score"
}
},

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

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

To verify that the knowledge panels are correct, you should definitely try to display them.

If you look in Display.pm, you can see how to render the knowledge panels in HTML, then you can pass the generated HTML to the product page template and display it:

	$template_data_ref->{environment_card_panel}
		= display_knowledge_panel($product_ref, $product_ref->{"knowledge_panels_" . $lc}, "environment_card");

@teolemon teolemon moved this from To discuss and validate to PRs in 🍊 Open Food Facts Server issues Jul 16, 2025
@RayanGoubet
Copy link
Collaborator Author

Add option &raw_panel=1 to show the raw data in the product page

Copy link

@RayanGoubet
Copy link
Collaborator Author

/update_tests_results

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…) Display 🧪 integration tests 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Product Page Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests 🌐 Translations
Development

Successfully merging this pull request may close these issues.

4 participants