2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Sidebars
|
|
|
|
class MenuItem
|
2022-01-26 12:08:38 +05:30
|
|
|
include ::Sidebars::Concerns::LinkWithHtmlOptions
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
attr_reader :title, :link, :active_routes, :item_id, :container_html_options, :sprite_icon, :sprite_icon_html_options, :hint_html_options, :has_pill, :pill_count, :super_sidebar_parent, :super_sidebar_before
|
2023-04-23 21:23:45 +05:30
|
|
|
alias_method :has_pill?, :has_pill
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
# rubocop: disable Metrics/ParameterLists
|
2023-05-27 22:25:52 +05:30
|
|
|
def initialize(title:, link:, active_routes:, item_id: nil, container_html_options: {}, sprite_icon: nil, sprite_icon_html_options: {}, hint_html_options: {}, has_pill: false, pill_count: nil, super_sidebar_parent: nil, super_sidebar_before: nil)
|
2021-06-08 01:23:25 +05:30
|
|
|
@title = title
|
|
|
|
@link = link
|
|
|
|
@active_routes = active_routes
|
|
|
|
@item_id = item_id
|
|
|
|
@container_html_options = { aria: { label: title } }.merge(container_html_options)
|
|
|
|
@sprite_icon = sprite_icon
|
|
|
|
@sprite_icon_html_options = sprite_icon_html_options
|
|
|
|
@hint_html_options = hint_html_options
|
2023-04-23 21:23:45 +05:30
|
|
|
@has_pill = has_pill
|
|
|
|
@pill_count = pill_count
|
2023-05-27 22:25:52 +05:30
|
|
|
@super_sidebar_before = super_sidebar_before
|
|
|
|
@super_sidebar_parent = super_sidebar_parent
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
# rubocop: enable Metrics/ParameterLists
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
def show_hint?
|
|
|
|
hint_html_options.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
|
|
|
true
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def serialize_for_super_sidebar
|
|
|
|
{
|
|
|
|
title: title,
|
|
|
|
icon: sprite_icon,
|
|
|
|
link: link,
|
|
|
|
active_routes: active_routes,
|
|
|
|
pill_count: has_pill ? pill_count : nil
|
|
|
|
# Check whether support is needed for the following properties,
|
|
|
|
# in order to get feature parity with the HAML renderer
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/391864
|
|
|
|
#
|
|
|
|
# container_html_options
|
|
|
|
# hint_html_options
|
|
|
|
# nav_link_html_options
|
|
|
|
#
|
|
|
|
# item_id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
def nav_link_html_options
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
track_label: item_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|