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

fix: make panel ids consistent for ingredients analysis knowledge panels #6815

Merged
merged 2 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions html/js/product-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<a href="#panel_' + attribute.panel_id + '" onclick="document.getElementById(\'panel_' + attribute.panel_id + '_content\').classList.add(\'active\'); $(document).foundation(\'equalizer\', \'reflow\');"' + card_html + '</a>';
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 = '<a href="#' + panel_element_id
+ '" onclick="document.getElementById(\'' + panel_element_id + '_content\').classList.add(\'active\'); $(document).foundation(\'equalizer\', \'reflow\');"' + card_html + '</a>';
alexgarel marked this conversation as resolved.
Show resolved Hide resolved
}
else {
card_html = '<div ' + card_html + '</div>';
}
}
else {
card_html = '<div ' + card_html + '</div>';
Expand Down
4 changes: 3 additions & 1 deletion lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
alexgarel marked this conversation as resolved.
Show resolved Hide resolved

if ($target_lc ne "data") {
$attribute_ref->{title} = display_taxonomy_tag($target_lc, "ingredients_analysis", "en:$analysis_tag");
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/en-attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/en-maybe-vegan.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/en-nutriscore.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/fr-palm-kernel-fat.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/fr-palm-oil-free.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/fr-palm-oil.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions t/expected_test_results/attributes/fr-vegetable-oils.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -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"
}
Expand Down