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

Move the selected menu item into submenu component

Oliver Günther1d5fb28aa4f1
diff --git a/app/components/projects/index_page_header_component.rb b/app/components/projects/index_page_header_component.rb
index d11e0064213..8ca4bc72499 100644
--- a/app/components/projects/index_page_header_component.rb
+++ b/app/components/projects/index_page_header_component.rb
@@ -130,9 +130,9 @@ class Projects::IndexPageHeaderComponent < ApplicationComponent
def current_section
return @current_section if defined?(@current_section)
- projects_menu = Projects::Menu.new(controller_path:, params:, current_user:)
-
- @current_section = projects_menu.menu_items.find { |section| section.children.any?(&:selected) }
+ @current_section = Projects::Menu
+ .new(controller_path:, params:, current_user:)
+ .selected_menu_group
end
def header_save_action(header:, message:, label:, href:, method: nil)
diff --git a/app/menus/submenu.rb b/app/menus/submenu.rb
index ef3a9a7ee24..57a93f773b3 100644
--- a/app/menus/submenu.rb
+++ b/app/menus/submenu.rb
@@ -44,6 +44,20 @@ class Submenu
]
end
+ def selected_menu_group
+ menu_items.detect do |group|
+ group.children.detect(&:selected)
+ end
+ end
+
+ def selected_menu_item
+ menu_items.each do |group|
+ group.children.each do |item|
+ return item if item.selected
+ end
+ end
+ end
+
def starred_queries
base_query
.where("starred" => "t")