From 9c3a68a72b94a4741f0982953e81c06eaa6f064b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Mon, 23 May 2022 17:53:11 +0200 Subject: [PATCH 1/2] fix: make panel ids consistent for ingredients analysis knowledge panels #6810 --- html/js/product-search.js | 14 +++++++++++--- lib/ProductOpener/Attributes.pm | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/html/js/product-search.js b/html/js/product-search.js index ad4406514b968..bca4be928fd7b 100644 --- a/html/js/product-search.js +++ b/html/js/product-search.js @@ -379,9 +379,17 @@ function display_product_summary(target, product) { } // check if the product attribute has an associated knowledge panel that exists - if ((attribute.panel_id) && (document.getElementById("panel_" + attribute.panel_id))) { - // onclick : open the panel content + reflow to make sur all column content is shown - card_html = ''; + if (attribute.panel_id) { + // note: on the website, the id for the panel contains : instead of - (e.g. for the ingredients_analysis_en:vegan panel) + var panel_element_id = 'panel_' + attribute.panel_id.replace(':', '-'); + if (document.getElementById(panel_element_id)) { + // onclick : open the panel content + reflow to make sur all column content is shown + card_html = ''; + } + else { + card_html = '
'; + } } else { card_html = '
'; diff --git a/lib/ProductOpener/Attributes.pm b/lib/ProductOpener/Attributes.pm index d0c71e86d6f0c..c946935691e9f 100644 --- a/lib/ProductOpener/Attributes.pm +++ b/lib/ProductOpener/Attributes.pm @@ -312,7 +312,6 @@ sub initialize_attribute($$) { my $analysis_tag = $attribute_id; $analysis_tag =~ s/_/-/g; $attribute_ref->{icon_url} = "$static_subdomain/images/attributes/$analysis_tag.svg"; - $attribute_ref->{panel_id} = "ingredients_analysis_en-" . $analysis_tag; } elsif ($attribute_id =~ /^(labels)_(.*)$/) { my $tagtype = $1; @@ -1405,6 +1404,9 @@ sub compute_attribute_ingredients_analysis($$$) { # the ingredients_analysis taxonomy contains en:palm-oil and not en:contains-palm-oil $analysis_tag =~ s/contains-(.*)$/$1/; + # Link to the corresponding knowledge panel (the panel id depends on the value of the property) + $attribute_ref->{panel_id} = "ingredients_analysis_en:" . $analysis_tag; + if ($target_lc ne "data") { $attribute_ref->{title} = display_taxonomy_tag($target_lc, "ingredients_analysis", "en:$analysis_tag"); } From 46f5fd4eaecd3d75eaa8e00dfcccbb36442371d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Wed, 25 May 2022 16:09:54 +0200 Subject: [PATCH 2/2] update tests --- t/expected_test_results/attributes/en-attributes.json | 6 +++--- .../attributes/en-ecoscore-score-at-20-threshold.json | 6 +++--- t/expected_test_results/attributes/en-maybe-vegan.json | 6 +++--- .../attributes/en-nova-groups-markers.json | 6 +++--- t/expected_test_results/attributes/en-nutriscore.json | 6 +++--- t/expected_test_results/attributes/fr-palm-kernel-fat.json | 6 +++--- t/expected_test_results/attributes/fr-palm-oil-free.json | 6 +++--- t/expected_test_results/attributes/fr-palm-oil.json | 6 +++--- t/expected_test_results/attributes/fr-vegetable-oils.json | 6 +++--- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/t/expected_test_results/attributes/en-attributes.json b/t/expected_test_results/attributes/en-attributes.json index 32ed1c5af6766..e9ddc82cb1030 100644 --- a/t/expected_test_results/attributes/en-attributes.json +++ b/t/expected_test_results/attributes/en-attributes.json @@ -237,7 +237,7 @@ "id" : "vegan", "match" : 0, "name" : "Vegan", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:non-vegan", "status" : "known", "title" : "Non-vegan" }, @@ -247,7 +247,7 @@ "id" : "vegetarian", "match" : 0, "name" : "Vegetarian", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:non-vegetarian", "status" : "known", "title" : "Non-vegetarian" }, @@ -257,7 +257,7 @@ "id" : "palm_oil_free", "match" : 100, "name" : "Palm oil free", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil-free", "status" : "known", "title" : "Palm oil free" } diff --git a/t/expected_test_results/attributes/en-ecoscore-score-at-20-threshold.json b/t/expected_test_results/attributes/en-ecoscore-score-at-20-threshold.json index 0c8edbcaf8860..b9cb85a2b102d 100644 --- a/t/expected_test_results/attributes/en-ecoscore-score-at-20-threshold.json +++ b/t/expected_test_results/attributes/en-ecoscore-score-at-20-threshold.json @@ -203,7 +203,7 @@ "icon_url" : "https://server_domain/images/attributes/vegan-status-unknown.svg", "id" : "vegan", "name" : "Vegan", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:vegan-status-unknown", "status" : "unknown", "title" : "Vegan status unknown" }, @@ -212,7 +212,7 @@ "icon_url" : "https://server_domain/images/attributes/vegetarian-status-unknown.svg", "id" : "vegetarian", "name" : "Vegetarian", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian-status-unknown", "status" : "unknown", "title" : "Vegetarian status unknown" }, @@ -221,7 +221,7 @@ "icon_url" : "https://server_domain/images/attributes/palm-oil-content-unknown.svg", "id" : "palm_oil_free", "name" : "Palm oil free", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil-content-unknown", "status" : "unknown", "title" : "Palm oil content unknown" } diff --git a/t/expected_test_results/attributes/en-maybe-vegan.json b/t/expected_test_results/attributes/en-maybe-vegan.json index bc99d7c2ac2af..65ad9944d4919 100644 --- a/t/expected_test_results/attributes/en-maybe-vegan.json +++ b/t/expected_test_results/attributes/en-maybe-vegan.json @@ -220,7 +220,7 @@ "id" : "vegan", "match" : 50, "name" : "Vegan", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:maybe-vegan", "status" : "known", "title" : "Maybe vegan" }, @@ -230,7 +230,7 @@ "id" : "vegetarian", "match" : 50, "name" : "Vegetarian", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:maybe-vegetarian", "status" : "known", "title" : "Maybe vegetarian" }, @@ -240,7 +240,7 @@ "id" : "palm_oil_free", "match" : 0, "name" : "Palm oil free", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil", "status" : "known", "title" : "Palm oil" } diff --git a/t/expected_test_results/attributes/en-nova-groups-markers.json b/t/expected_test_results/attributes/en-nova-groups-markers.json index 75ab4c8fbb513..cdd44c6cd8bb3 100644 --- a/t/expected_test_results/attributes/en-nova-groups-markers.json +++ b/t/expected_test_results/attributes/en-nova-groups-markers.json @@ -230,7 +230,7 @@ "id" : "vegan", "match" : 0, "name" : "Vegan", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:non-vegan", "status" : "known", "title" : "Non-vegan" }, @@ -240,7 +240,7 @@ "id" : "vegetarian", "match" : 50, "name" : "Vegetarian", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:maybe-vegetarian", "status" : "known", "title" : "Maybe vegetarian" }, @@ -250,7 +250,7 @@ "id" : "palm_oil_free", "match" : 100, "name" : "Palm oil free", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil-free", "status" : "known", "title" : "Palm oil free" } diff --git a/t/expected_test_results/attributes/en-nutriscore.json b/t/expected_test_results/attributes/en-nutriscore.json index 8a8c6956ec182..934aa5d6f3717 100644 --- a/t/expected_test_results/attributes/en-nutriscore.json +++ b/t/expected_test_results/attributes/en-nutriscore.json @@ -224,7 +224,7 @@ "id" : "vegan", "match" : 100, "name" : "Vegan", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:vegan", "status" : "known", "title" : "Vegan" }, @@ -234,7 +234,7 @@ "id" : "vegetarian", "match" : 100, "name" : "Vegetarian", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian", "status" : "known", "title" : "Vegetarian" }, @@ -244,7 +244,7 @@ "id" : "palm_oil_free", "match" : 100, "name" : "Palm oil free", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil-free", "status" : "known", "title" : "Palm oil free" } diff --git a/t/expected_test_results/attributes/fr-palm-kernel-fat.json b/t/expected_test_results/attributes/fr-palm-kernel-fat.json index 065974914a302..e80624964ad98 100644 --- a/t/expected_test_results/attributes/fr-palm-kernel-fat.json +++ b/t/expected_test_results/attributes/fr-palm-kernel-fat.json @@ -220,7 +220,7 @@ "id" : "vegan", "match" : 100, "name" : "Végétalien", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:vegan", "status" : "known", "title" : "Végétalien" }, @@ -230,7 +230,7 @@ "id" : "vegetarian", "match" : 100, "name" : "Végétarien", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian", "status" : "known", "title" : "Végétarien" }, @@ -240,7 +240,7 @@ "id" : "palm_oil_free", "match" : 0, "name" : "Sans huile de palme", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil", "status" : "known", "title" : "Huile de palme" } diff --git a/t/expected_test_results/attributes/fr-palm-oil-free.json b/t/expected_test_results/attributes/fr-palm-oil-free.json index 1a2ec2f58dae4..ae872cf75b5f4 100644 --- a/t/expected_test_results/attributes/fr-palm-oil-free.json +++ b/t/expected_test_results/attributes/fr-palm-oil-free.json @@ -220,7 +220,7 @@ "id" : "vegan", "match" : 50, "name" : "Végétalien", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:maybe-vegan", "status" : "known", "title" : "Peut-être végétalien" }, @@ -230,7 +230,7 @@ "id" : "vegetarian", "match" : 100, "name" : "Végétarien", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian", "status" : "known", "title" : "Végétarien" }, @@ -240,7 +240,7 @@ "id" : "palm_oil_free", "match" : 100, "name" : "Sans huile de palme", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil-free", "status" : "known", "title" : "Sans huile de palme" } diff --git a/t/expected_test_results/attributes/fr-palm-oil.json b/t/expected_test_results/attributes/fr-palm-oil.json index c78f1472d9011..1fbff6c1af1a8 100644 --- a/t/expected_test_results/attributes/fr-palm-oil.json +++ b/t/expected_test_results/attributes/fr-palm-oil.json @@ -220,7 +220,7 @@ "id" : "vegan", "match" : 100, "name" : "Végétalien", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:vegan", "status" : "known", "title" : "Végétalien" }, @@ -230,7 +230,7 @@ "id" : "vegetarian", "match" : 100, "name" : "Végétarien", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian", "status" : "known", "title" : "Végétarien" }, @@ -240,7 +240,7 @@ "id" : "palm_oil_free", "match" : 0, "name" : "Sans huile de palme", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:palm-oil", "status" : "known", "title" : "Huile de palme" } diff --git a/t/expected_test_results/attributes/fr-vegetable-oils.json b/t/expected_test_results/attributes/fr-vegetable-oils.json index 051bf50d7257c..9dcd450a26e23 100644 --- a/t/expected_test_results/attributes/fr-vegetable-oils.json +++ b/t/expected_test_results/attributes/fr-vegetable-oils.json @@ -220,7 +220,7 @@ "id" : "vegan", "match" : 100, "name" : "Végétalien", - "panel_id" : "ingredients_analysis_en-vegan", + "panel_id" : "ingredients_analysis_en:vegan", "status" : "known", "title" : "Végétalien" }, @@ -230,7 +230,7 @@ "id" : "vegetarian", "match" : 100, "name" : "Végétarien", - "panel_id" : "ingredients_analysis_en-vegetarian", + "panel_id" : "ingredients_analysis_en:vegetarian", "status" : "known", "title" : "Végétarien" }, @@ -240,7 +240,7 @@ "id" : "palm_oil_free", "match" : 50, "name" : "Sans huile de palme", - "panel_id" : "ingredients_analysis_en-palm-oil-free", + "panel_id" : "ingredients_analysis_en:may-contain-palm-oil", "status" : "known", "title" : "Pourrait contenir de l'huile de palme" }