Commit b82a46b9 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '329768-fj-add-hidden-menus-to-project-sidebar' into 'master'

Add hidden menu to project sidebar refactor

See merge request gitlab-org/gitlab!60813
parents 82b3fcf6 1b40062f
-# Shortcut to Project > Activity
%li.hidden
= link_to activity_project_path(@project), title: _('Activity'), class: 'shortcuts-project-activity' do
%span
= _('Activity')
-# Shortcut to Repository > Graph (formerly, Network)
- if project_nav_tab? :network
%li.hidden
= link_to project_network_path(@project, current_ref), title: _('Network'), class: 'shortcuts-network' do
= _('Graph')
-# Shortcut to Issues > New Issue
- if project_nav_tab?(:issues)
%li.hidden
= link_to new_project_issue_path(@project), class: 'shortcuts-new-issue' do
= _('Create a new issue')
-# Shortcut to Pipelines > Jobs
- if project_nav_tab? :builds
%li.hidden
= link_to project_jobs_path(@project), title: _('Jobs'), class: 'shortcuts-builds' do
= _('Jobs')
-# Shortcut to commits page
- if project_nav_tab? :commits
%li.hidden
= link_to project_commits_path(@project), title: _('Commits'), class: 'shortcuts-commits' do
= _('Commits')
-# Shortcut to issue boards
- if project_nav_tab?(:issues)
%li.hidden
= link_to _('Issue Boards'), project_boards_path(@project), title: _('Issue Boards'), class: 'shortcuts-issue-boards'
......@@ -11,4 +11,5 @@
- if sidebar.render_raw_menus_partial
= render sidebar.render_raw_menus_partial
= render partial: 'shared/nav/sidebar_hidden_menu_item', collection: sidebar.hidden_menu&.items
= render 'shared/sidebar_toggle_button'
%li.hidden
= link_to sidebar_hidden_menu_item.link, **sidebar_hidden_menu_item.container_html_options do
= sidebar_hidden_menu_item.title
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class HiddenMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
add_item(activity_menu_item)
add_item(graph_menu_item)
add_item(new_issue_menu_item)
add_item(jobs_menu_item)
add_item(commits_menu_item)
add_item(issue_boards_menu_item)
true
end
private
def activity_menu_item
::Sidebars::MenuItem.new(
title: _('Activity'),
link: activity_project_path(context.project),
active_routes: {},
container_html_options: { class: 'shortcuts-project-activity' },
item_id: :activity
)
end
def graph_menu_item
return unless can?(context.current_user, :download_code, context.project)
return if context.project.empty_repo?
::Sidebars::MenuItem.new(
title: _('Graph'),
link: project_network_path(context.project, context.current_ref),
active_routes: {},
container_html_options: { class: 'shortcuts-network' },
item_id: :graph
)
end
def new_issue_menu_item
return unless can?(context.current_user, :read_issue, context.project)
::Sidebars::MenuItem.new(
title: _('Create a new issue'),
link: new_project_issue_path(context.project),
active_routes: {},
container_html_options: { class: 'shortcuts-new-issue' },
item_id: :new_issue
)
end
def jobs_menu_item
return unless can?(context.current_user, :read_build, context.project)
::Sidebars::MenuItem.new(
title: _('Jobs'),
link: project_jobs_path(context.project),
active_routes: {},
container_html_options: { class: 'shortcuts-builds' },
item_id: :jobs
)
end
def commits_menu_item
return unless can?(context.current_user, :download_code, context.project)
return if context.project.empty_repo?
::Sidebars::MenuItem.new(
title: _('Commits'),
link: project_commits_path(context.project),
active_routes: {},
container_html_options: { class: 'shortcuts-commits' },
item_id: :commits
)
end
def issue_boards_menu_item
return unless can?(context.current_user, :read_issue, context.project)
::Sidebars::MenuItem.new(
title: _('Issue Boards'),
link: project_boards_path(context.project),
active_routes: {},
container_html_options: { class: 'shortcuts-issue-boards' },
item_id: :issue_boards
)
end
end
end
end
end
......@@ -6,6 +6,7 @@ module Sidebars
override :configure_menus
def configure_menus
set_scope_menu(Sidebars::Projects::Menus::ScopeMenu.new(context))
set_hidden_menu(Sidebars::Projects::Menus::HiddenMenu.new(context))
add_menu(Sidebars::Projects::Menus::ProjectInformationMenu.new(context))
add_menu(Sidebars::Projects::Menus::LearnGitlabMenu.new(context))
......@@ -27,11 +28,6 @@ module Sidebars
add_menu(Sidebars::Projects::Menus::SettingsMenu.new(context))
end
override :render_raw_menus_partial
def render_raw_menus_partial
'layouts/nav/sidebar/project_menus'
end
override :aria_label
def aria_label
_('Project navigation')
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::HiddenMenu do
let_it_be(:project) { create(:project, :repository) }
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project, current_ref: project.repository.root_ref) }
describe '#render?' do
subject { described_class.new(context) }
context 'when menu does not have any menu items' do
it 'returns false' do
allow(subject).to receive(:has_items?).and_return(false)
expect(subject.render?).to be false
end
end
context 'when menu has menu items' do
it 'returns true' do
expect(subject.render?).to be true
end
end
end
describe 'Menu items' do
subject { described_class.new(context).items.index { |e| e.item_id == item_id } }
shared_examples 'access rights checks' do
specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
describe 'Activity' do
let(:item_id) { :activity }
context 'when user has access to the project' do
specify { is_expected.not_to be_nil }
describe 'when the user is not present' do
let(:user) { nil }
specify { is_expected.not_to be_nil }
end
end
end
describe 'Graph' do
let(:item_id) { :graph }
context 'when project repository is empty' do
before do
allow(project).to receive(:empty_repo?).and_return(true)
end
specify { is_expected.to be_nil }
end
it_behaves_like 'access rights checks'
end
describe 'New Issue' do
let(:item_id) { :new_issue }
it_behaves_like 'access rights checks'
end
describe 'Jobs' do
let(:item_id) { :jobs }
it_behaves_like 'access rights checks'
end
describe 'Commits' do
let(:item_id) { :commits }
context 'when project repository is empty' do
before do
allow(project).to receive(:empty_repo?).and_return(true)
end
specify { is_expected.to be_nil }
end
it_behaves_like 'access rights checks'
end
describe 'Issue Boards' do
let(:item_id) { :issue_boards }
it_behaves_like 'access rights checks'
end
end
end
......@@ -1090,5 +1090,43 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
end
describe 'Hidden menus' do
it 'has a link to the Activity page' do
render
expect(rendered).to have_link('Activity', href: activity_project_path(project), class: 'shortcuts-project-activity', visible: false)
end
it 'has a link to the Graph page' do
render
expect(rendered).to have_link('Graph', href: project_network_path(project, current_ref), class: 'shortcuts-network', visible: false)
end
it 'has a link to the New Issue page' do
render
expect(rendered).to have_link('Create a new issue', href: new_project_issue_path(project), class: 'shortcuts-new-issue', visible: false)
end
it 'has a link to the Jobs page' do
render
expect(rendered).to have_link('Jobs', href: project_jobs_path(project), class: 'shortcuts-builds', visible: false)
end
it 'has a link to the Commits page' do
render
expect(rendered).to have_link('Commits', href: project_commits_path(project), class: 'shortcuts-commits', visible: false)
end
it 'has a link to the Issue Boards page' do
render
expect(rendered).to have_link('Issue Boards', href: project_boards_path(project), class: 'shortcuts-issue-boards', visible: false)
end
end
it_behaves_like 'sidebar includes snowplow attributes', 'render', 'projects_side_navigation', 'projects_side_navigation'
end
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