Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat[#50499]: Replace custom breadcrumbs implementation with Primer Breadcrumbs in BreadcrumbHelper

Dominic Bräunlein0d57b5601327
diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb
index 24b7579673e..c739f80ea40 100644
--- a/app/helpers/breadcrumb_helper.rb
+++ b/app/helpers/breadcrumb_helper.rb
@@ -27,30 +27,19 @@
#++
module BreadcrumbHelper
- def full_breadcrumb
- breadcrumb_list(*breadcrumb_paths)
- end
-
- def breadcrumb(*args)
- elements = args.flatten
- elements.any? ? content_tag('p', (args.join(' » ') + ' » ').html_safe, class: 'op-breadcrumb') : nil
- end
-
- def breadcrumb_list(*args)
- elements = args.flatten
- breadcrumb_elements = [content_tag(:li,
- elements.shift.to_s,
- class: 'first-breadcrumb-element')]
+ def full_breadcrumbs
+ items = breadcrumb_paths.compact
+ render(Primer::Beta::Breadcrumbs.new) do |breadcrumbs|
+ items.each do |item|
+ item = anchor_string_to_object(item) if item.is_a?(String) && item.start_with?("\u003c")
- breadcrumb_elements += elements.map do |element|
- if element
- content_tag(:li,
- h(element.to_s),
- class: "icon4 icon-small icon-arrow-right5")
+ if item.is_a?(Hash)
+ breadcrumbs.with_item(href: item[:href]) { item[:text] }
+ else
+ breadcrumbs.with_item(href: "#") { item }
+ end
end
end
-
- content_tag(:ul, breadcrumb_elements.join.html_safe, class: 'op-breadcrumb', 'data-test-selector': 'op-breadcrumb')
end
def breadcrumb_paths(*args)
@@ -71,4 +60,16 @@ module BreadcrumbHelper
false
end
end
+
+ private
+
+ # 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
end
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 5b3be3007c8..c1b952649d6 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -118,7 +118,7 @@ See COPYRIGHT and LICENSE files for more details.
<% if show_decoration %>
<div id="breadcrumb" class="<%= initial_classes %><%= show_breadcrumb ? ' -show' : '' %>">
<%= you_are_here_info %>
- <%= full_breadcrumb %>
+ <%= full_breadcrumbs %>
<%= call_hook :view_layouts_base_breadcrumb %>
</div>
<% end %>