-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
base: main
Are you sure you want to change the base?
Conversation
@RayanGoubet can you add a little preview screenshot ? |
❌ 10 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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/"; |
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.
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" |
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.
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 %] |
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.
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 %] |
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.
you can put the comma at the end of all entries, including the last one, it should be removed automatically after
@@ -0,0 +1,15 @@ | |||
[% FOREACH panel IN panel.taxonomy_panels %] | |||
{ |
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.
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"
}
},
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.
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");
Add option &raw_panel=1 to show the raw data in the product page |
|
/update_tests_results |
What
Milestone 3 - Introduce a raw data knowledge panel for core contributors