summaryrefslogtreecommitdiff
path: root/lib/sidebars/panel.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-17 15:09:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-17 15:09:22 +0000
commit99f4b14cb0546a905d8f14f938d679d17e569005 (patch)
treed0520a58f46c8b5ceb018ca4d404e9a682f4af3c /lib/sidebars/panel.rb
parent4f8983ade80c0d71d4c8e6cc0d686c9cecf5e7d4 (diff)
downloadgitlab-ce-99f4b14cb0546a905d8f14f938d679d17e569005.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/sidebars/panel.rb')
-rw-r--r--lib/sidebars/panel.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sidebars/panel.rb b/lib/sidebars/panel.rb
index 2a172cfffe3..9428085a5e7 100644
--- a/lib/sidebars/panel.rb
+++ b/lib/sidebars/panel.rb
@@ -61,6 +61,32 @@ module Sidebars
@renderable_menus ||= @menus.select(&:render?)
end
+ # Serializes every renderable sub-menu and menu-item for the super sidebar
+ # A flattened list of menu items is grouped into the appropriate parent
+ def super_sidebar_menu_items
+ @super_sidebar_menu_items ||= renderable_menus
+ .flat_map(&:serialize_for_super_sidebar)
+ .each_with_object([]) do |item, acc|
+ # Finding the parent of an entry
+ parent_id = item.delete(:parent_id)
+ parent_idx = acc.find_index { |i| i[:id] == parent_id }
+
+ # Entries without a matching parent entry are top level
+ if parent_idx.nil?
+ acc.push(item)
+ else
+ acc[parent_idx][:items] ||= []
+ acc[parent_idx][:items].push(item)
+ # If any sub-item of a navigation item is active, its parent should be as well
+ acc[parent_idx][:is_active] ||= item[:is_active]
+ end
+ end
+ end
+
+ def super_sidebar_context_header
+ raise NotImplementedError
+ end
+
def container
context.container
end