Skip to content

Commit

Permalink
Remove support for anchor strings in PageHeader breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Oct 7, 2024
1 parent 6d3953f commit a156e4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-pots-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openproject/primer-view-components': minor
---

Remove support for anchor strings in PageHeader breadcrumbs
22 changes: 2 additions & 20 deletions app/components/primer/open_project/page_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ class PageHeader < Primer::Component
if items.length > 1
link_arguments = {}
parent_item = items[items.length - 2]
parsed_parent_item = anchor_tag_string?(parent_item) ? anchor_string_to_object(parent_item) : parent_item

link_arguments[:icon] = fetch_or_fallback(BACK_BUTTON_ICON_OPTIONS, DEFAULT_BACK_BUTTON_ICON)
link_arguments[:href] = parsed_parent_item[:href]
link_arguments[:href] = parent_item[:href]
link_arguments[:target] = "_top"

link_arguments[:classes] = class_names(link_arguments[:classes], "PageHeader-parentLink")
Expand All @@ -203,14 +202,12 @@ class PageHeader < Primer::Component
render(Primer::Beta::Octicon.new(icon: "arrow-left",
"aria-label": I18n.t("button_back"),
mr: 2)
) + content_tag(:span, parsed_parent_item[:text])
) + content_tag(:span, parent_item[:text])
end
end

render(Primer::Beta::Breadcrumbs.new(**system_arguments)) do |breadcrumbs|
items.each do |item|
item = anchor_string_to_object(item) if anchor_tag_string?(item)

if item.is_a?(String)
breadcrumbs.with_item(href: "#", font_weight: selected_item_font_weight) { item }
else
Expand Down Expand Up @@ -331,21 +328,6 @@ def create_mobile_single_action(component, **system_arguments, &block)
@mobile_action_block = block
end
end

# transform anchor tag strings to {href, text} objects
# e.g "\u003ca href=\"/admin\"\u003eAdministration\u003c/a\u003e"
def anchor_string_to_object(html_string)
# Parse the HTML
doc = Nokogiri::HTML.fragment(html_string)
# Extract href and text
anchor = doc.at("a")
{ href: anchor["href"], text: anchor.text }
end

# Check if the item is an anchor tag string e.g "\u003ca href=\"/admin\"\u003eAdministration\u003c/a\u003e"
def anchor_tag_string?(item)
item.is_a?(String) && item.start_with?("\u003c")
end
end
end
end
4 changes: 2 additions & 2 deletions test/components/primer/open_project/page_header_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_renders_leading_action
def test_renders_breadcrumbs
breadcrumb_items = [
{ href: "/foo", text: "Foo" },
"\u003ca href=\"/foo/bar\"\u003eBar\u003c/a\u003e",
{ href: "/foo/bar", text: "Bar" },
{ href: "#", text: "test" },
"test"
]
Expand All @@ -195,7 +195,7 @@ def test_renders_breadcrumbs
def test_renders_non_bold_breadcrumbs
breadcrumb_items = [
{ href: "/foo", text: "Foo" },
"\u003ca href=\"/foo/bar\"\u003eBar\u003c/a\u003e",
{ href: "/foo/bar", text: "Bar" },
{ href: "#", text: "test" },
"test"
]
Expand Down

0 comments on commit a156e4a

Please sign in to comment.