Commit 30b70918 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch 'fj-refactor-sidebar-menus-link-method' into 'master'

Refactor sidebar menus link method

See merge request gitlab-org/gitlab!68441
parents 8032627e 3be7be9a
......@@ -17,11 +17,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('Administration')
......
......@@ -25,7 +25,7 @@ module Sidebars
def link
return cycle_analytics_menu_item.link if cycle_analytics_menu_item.render?
renderable_items.first.link
super
end
override :extra_container_html_options
......
......@@ -17,11 +17,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('Epics')
......
......@@ -17,9 +17,9 @@ module Sidebars
override :link
def link
return renderable_items.first.link if renderable_items.any?
return group_security_discover_path(context.group) if renderable_items.empty?
group_security_discover_path(context.group)
super
end
override :title
......
......@@ -11,11 +11,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('CI/CD')
......
......@@ -13,11 +13,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
context.group.subgroup? ? _('Subgroup information') : _('Group information')
......
......@@ -17,11 +17,6 @@ module Sidebars
true
end
override :link
def link
issues_group_path(context.group)
end
override :title
def title
_('Issues')
......
......@@ -13,11 +13,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('Packages & Registries')
......
......@@ -19,11 +19,6 @@ module Sidebars
true
end
override :link
def link
edit_group_path(context.group)
end
override :title
def title
_('Settings')
......
......@@ -33,10 +33,9 @@ module Sidebars
has_renderable_items? || menu_with_partial?
end
# Menus might have or not a link
override :link
def link
nil
renderable_items.first&.link
end
# This method normalizes the information retrieved from the submenus and this menu
......
......@@ -21,7 +21,7 @@ module Sidebars
def link
return cycle_analytics_menu_item.link if cycle_analytics_menu_item.render?
renderable_items.first.link
super
end
override :extra_container_html_options
......
......@@ -15,11 +15,6 @@ module Sidebars
add_item(pipeline_schedules_menu_item)
end
override :link
def link
project_pipelines_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -13,11 +13,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -15,11 +15,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -18,11 +18,6 @@ module Sidebars
true
end
override :link
def link
project_issues_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -19,11 +19,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first&.link
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -13,11 +13,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('Packages & Registries')
......
......@@ -13,11 +13,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first.link
end
override :extra_container_html_options
def extra_container_html_options
{ class: 'shortcuts-project-information' }
......
......@@ -20,11 +20,6 @@ module Sidebars
true
end
override :link
def link
project_tree_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
......
......@@ -15,11 +15,6 @@ module Sidebars
true
end
override :link
def link
renderable_items.first&.link
end
override :title
def title
_('Security & Compliance')
......
......@@ -21,11 +21,6 @@ module Sidebars
true
end
override :link
def link
edit_project_path(context.project)
end
override :title
def title
_('Settings')
......
......@@ -198,4 +198,27 @@ RSpec.describe Sidebars::Menu do
end
end
end
describe '#link' do
let(:foo_path) { '/foo_path'}
let(:foo_menu) do
::Sidebars::MenuItem.new(
title: 'foo',
link: foo_path,
active_routes: {},
item_id: :foo
)
end
it 'returns first visible menu item link' do
menu.add_item(foo_menu)
expect(menu.link).to eq foo_path
end
it 'returns nil if there are no visible menu items' do
expect(menu.link).to be_nil
end
end
end
......@@ -49,25 +49,6 @@ RSpec.describe Sidebars::Projects::Menus::MonitorMenu do
end
end
describe '#link' do
let(:foo_path) { '/foo_path'}
let(:foo_menu) do
::Sidebars::MenuItem.new(
title: 'foo',
link: foo_path,
active_routes: {},
item_id: :foo
)
end
it 'returns first visible item link' do
subject.insert_element_before(subject.renderable_items, subject.renderable_items.first.item_id, foo_menu)
expect(subject.link).to eq foo_path
end
end
context 'Menu items' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment