Skip to content

Commit

Permalink
fix: avoid reference to missing panel in root card (#8297)
Browse files Browse the repository at this point in the history
Do not reference contribution_card in root card if not present.

Fixes: #8295
  • Loading branch information
alexgarel authored Apr 7, 2023
1 parent a15bb75 commit acfb092
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 64 deletions.
10 changes: 7 additions & 3 deletions lib/ProductOpener/KnowledgePanels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ sub create_knowledge_panels ($product_ref, $target_lc, $target_cc, $options_ref)

create_health_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
create_environment_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
create_contribution_card_panel($product_ref, $target_lc, $target_cc, $options_ref);
my $has_contribution_card = create_contribution_card_panel($product_ref, $target_lc, $target_cc, $options_ref);

# Create the root panel that contains the panels we want to show directly on the product page
create_panel_from_json_template("root", "api/knowledge-panels/root.tt.json",
{}, $product_ref, $target_lc, $target_cc, $options_ref);
create_panel_from_json_template(
"root",
"api/knowledge-panels/root.tt.json",
{has_contribution_card => $has_contribution_card},
$product_ref, $target_lc, $target_cc, $options_ref
);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ProductOpener/KnowledgePanelsContribution.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sub create_contribution_card_panel ($product_ref, $target_lc, $target_cc, $optio
"api/knowledge-panels/contribution/contribution_card.tt.json",
$panel_data_ref, $product_ref, $target_lc, $target_cc, $options_ref);
}
return;
return !!@panels;
}

# private sub to add tag names to data_quality_tags_by_actions: we just iterate to add tag name
Expand Down
14 changes: 8 additions & 6 deletions templates/api/knowledge-panels/root.tt.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"panel_element": {
"panel_id": "environment_card",
},
},
{
"element_type": "panel",
"panel_element": {
"panel_id": "contribution_card",
},
},
[% IF panel.has_contribution_card %]
{
"element_type": "panel",
"panel_element": {
"panel_id": "contribution_card",
},
},
[% END %]
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -1818,12 +1818,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2142,12 +2142,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,12 +1819,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2143,12 +2143,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,6 @@
"panel_element" : {
"panel_id" : "environment_card"
}
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "contribution_card"
}
}
],
"expanded" : true,
Expand Down

0 comments on commit acfb092

Please sign in to comment.