Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sidebars/menu.rb')
-rw-r--r--lib/sidebars/menu.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/sidebars/menu.rb b/lib/sidebars/menu.rb
index dfd88c99a0c..03995362ff0 100644
--- a/lib/sidebars/menu.rb
+++ b/lib/sidebars/menu.rb
@@ -66,6 +66,40 @@ module Sidebars
@renderable_items ||= @items.select(&:render?)
end
+ # Returns a tree-like representation of itself and all
+ # renderable menu entries, with additional information
+ # on whether the item(s) have an active route
+ def serialize_for_super_sidebar
+ items = serialize_items_for_super_sidebar
+ is_active = @context.route_is_active.call(active_routes) || items.any? { |item| item[:is_active] }
+
+ {
+ title: title,
+ icon: sprite_icon,
+ link: link,
+ is_active: is_active,
+ pill_count: has_pill? ? pill_count : nil,
+ items: items
+ }
+ end
+
+ # Returns an array of renderable menu entries,
+ # with additional information on whether the item
+ # has an active route
+ def serialize_items_for_super_sidebar
+ # All renderable menu entries
+ renderable_items.map do |entry|
+ entry.serialize_for_super_sidebar.tap do |item|
+ active_routes = item.delete(:active_routes)
+ item[:is_active] = active_routes ? @context.route_is_active.call(active_routes) : false
+ end
+ end
+ end
+
+ def pick_into_super_sidebar?
+ false
+ end
+
# Returns whether the menu has any renderable menu item
def has_renderable_items?
renderable_items.any?
@@ -93,6 +127,17 @@ module Sidebars
end
end
+ # Sometimes we want to convert a top-level Menu (e.g. Wiki/Snippets)
+ # to a MenuItem. This serializer is used in order to enable that conversion
+ def serialize_as_menu_item_args
+ {
+ title: title,
+ link: link,
+ active_routes: active_routes,
+ container_html_options: container_html_options
+ }
+ end
+
private
override :index_of