From a156e4a063adca81086c7659e3049571c945708e Mon Sep 17 00:00:00 2001 From: Henriette Darge Date: Mon, 7 Oct 2024 09:46:49 +0200 Subject: [PATCH] Remove support for anchor strings in PageHeader breadcrumbs --- .changeset/light-pots-occur.md | 5 +++++ .../primer/open_project/page_header.rb | 22 ++----------------- .../primer/open_project/page_header_test.rb | 4 ++-- 3 files changed, 9 insertions(+), 22 deletions(-) create mode 100644 .changeset/light-pots-occur.md diff --git a/.changeset/light-pots-occur.md b/.changeset/light-pots-occur.md new file mode 100644 index 0000000000..28ba026661 --- /dev/null +++ b/.changeset/light-pots-occur.md @@ -0,0 +1,5 @@ +--- +'@openproject/primer-view-components': minor +--- + +Remove support for anchor strings in PageHeader breadcrumbs diff --git a/app/components/primer/open_project/page_header.rb b/app/components/primer/open_project/page_header.rb index ab5332258d..9eaf7754d1 100644 --- a/app/components/primer/open_project/page_header.rb +++ b/app/components/primer/open_project/page_header.rb @@ -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") @@ -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 @@ -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 diff --git a/test/components/primer/open_project/page_header_test.rb b/test/components/primer/open_project/page_header_test.rb index ed0708a655..b64146ab79 100644 --- a/test/components/primer/open_project/page_header_test.rb +++ b/test/components/primer/open_project/page_header_test.rb @@ -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" ] @@ -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" ]