2021-04-29 21:17:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Sidebars
|
|
|
|
class Panel
|
|
|
|
extend ::Gitlab::Utils::Override
|
2021-06-08 01:23:25 +05:30
|
|
|
include ::Sidebars::Concerns::PositionableList
|
2021-12-11 22:18:48 +05:30
|
|
|
include Gitlab::Experiment::Dsl
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
attr_reader :context, :scope_menu, :hidden_menu
|
|
|
|
|
|
|
|
def initialize(context)
|
|
|
|
@context = context
|
|
|
|
@scope_menu = nil
|
|
|
|
@hidden_menu = nil
|
|
|
|
@menus = []
|
|
|
|
|
|
|
|
configure_menus
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure_menus
|
|
|
|
# No-op
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_menu(menu)
|
|
|
|
add_element(@menus, menu)
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert_menu_before(before_menu, new_menu)
|
|
|
|
insert_element_before(@menus, before_menu, new_menu)
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert_menu_after(after_menu, new_menu)
|
|
|
|
insert_element_after(@menus, after_menu, new_menu)
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def replace_menu(menu_to_replace, new_menu)
|
|
|
|
replace_element(@menus, menu_to_replace, new_menu)
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
def remove_menu(menu_to_remove)
|
|
|
|
remove_element(@menus, menu_to_remove)
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def set_scope_menu(scope_menu)
|
|
|
|
@scope_menu = scope_menu
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_hidden_menu(hidden_menu)
|
|
|
|
@hidden_menu = hidden_menu
|
|
|
|
end
|
|
|
|
|
|
|
|
def aria_label
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_renderable_menus?
|
|
|
|
renderable_menus.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def renderable_menus
|
|
|
|
@renderable_menus ||= @menus.select(&:render?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def container
|
|
|
|
context.container
|
|
|
|
end
|
|
|
|
|
|
|
|
# Auxiliar method that helps with the migration from
|
|
|
|
# regular views to the new logic
|
|
|
|
def render_raw_scope_menu_partial
|
|
|
|
# No-op
|
|
|
|
end
|
|
|
|
|
|
|
|
# Auxiliar method that helps with the migration from
|
|
|
|
# regular views to the new logic.
|
|
|
|
#
|
|
|
|
# Any menu inside this partial will be added after
|
|
|
|
# all the menus added in the `configure_menus`
|
|
|
|
# method.
|
|
|
|
def render_raw_menus_partial
|
|
|
|
# No-op
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
override :index_of
|
|
|
|
def index_of(list, element)
|
|
|
|
list.index { |e| e.is_a?(element) }
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
end
|