Commit 9bceafeb authored by Denys Mishunov's avatar Denys Mishunov

Merge branch '326344-fj-add-scope-menu-to-sidebar-refactor' into 'master'

Add scope menu to project sidebar refactor

See merge request gitlab-org/gitlab!58761
parents 9e87ef28 c7810ef1
......@@ -15,7 +15,7 @@ module SidebarsHelper
end
def project_sidebar_context(project, user)
Sidebars::Context.new(**project_sidebar_context_data(project, user))
Sidebars::Projects::Context.new(**project_sidebar_context_data(project, user))
end
private
......@@ -35,8 +35,7 @@ module SidebarsHelper
def project_sidebar_context_data(project, user)
{
current_user: user,
container: project,
project: project
container: project
}
end
end
# frozen_string_literal: true
module Sidebars
module Projects
class Context < ::Sidebars::Context
def initialize(current_user:, container:, **args)
super(current_user: current_user, container: container, project: container, **args)
end
end
end
end
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
module Scope
class Menu < ::Sidebars::Menu
override :link
def link
project_path(context.project)
end
override :title
def title
context.project.name
end
end
end
end
end
end
......@@ -3,9 +3,9 @@
module Sidebars
module Projects
class Panel < ::Sidebars::Panel
override :render_raw_menus_partial
def render_raw_scope_menu_partial
'layouts/nav/sidebar/project_scope_menu'
override :configure_menus
def configure_menus
set_scope_menu(Sidebars::Projects::Menus::Scope::Menu.new(context))
end
override :render_raw_menus_partial
......
.context-header
= link_to project_path(@project), title: @project.name do
= link_to scope_menu.link, **scope_menu.container_html_options do
.avatar-container.rect-avatar.s40.project-avatar
= project_icon(@project, alt: @project.name, class: 'avatar s40 avatar-tile', width: 40, height: 40)
= source_icon(scope_menu.container, alt: scope_menu.title, class: 'avatar s40 avatar-tile', width: 40, height: 40)
.sidebar-context-title
= @project.name
= scope_menu.title
%aside.nav-sidebar{ class: ('sidebar-collapsed-desktop' if collapsed_sidebar?), **sidebar_tracking_attributes_by_object(sidebar.container), 'aria-label': sidebar.aria_label }
.nav-sidebar-inner-scroll
- if sidebar.render_raw_scope_menu_partial
- if sidebar.scope_menu
= render partial: 'shared/nav/scope_menu', object: sidebar.scope_menu
- elsif sidebar.render_raw_scope_menu_partial
= render sidebar.render_raw_scope_menu_partial
%ul.sidebar-top-level-items.qa-project-sidebar
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Context do
let(:project) { build(:project) }
subject { described_class.new(current_user: nil, container: project) }
it 'sets project attribute reader' do
expect(subject.project).to eq(project)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Panel do
let(:project) { build(:project) }
let(:context) { Sidebars::Projects::Context.new(current_user: nil, container: project) }
subject { described_class.new(context) }
it 'has a scope menu' do
expect(subject.scope_menu).to be_a(Sidebars::Projects::Menus::Scope::Menu)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'shared/nav/_sidebar.html.haml' do
let(:project) { build(:project, id: non_existing_record_id) }
let(:context) { Sidebars::Projects::Context.new(current_user: nil, container: project)}
let(:sidebar) { Sidebars::Projects::Panel.new(context) }
before do
assign(:project, project)
assign(:sidebar, sidebar)
allow(sidebar).to receive(:renderable_menus).and_return([])
end
context 'when sidebar has a scope menu' do
it 'renders the scope menu' do
render
expect(rendered).to render_template('shared/nav/_scope_menu')
end
end
context 'when sidebar does not have a scope menu' do
let(:scope_menu_view_path) { 'shared/nav/' }
let(:scope_menu_view_name) { 'scope_menu.html.haml' }
let(:scope_menu_view) { "#{scope_menu_view_path}#{scope_menu_view_name}" }
let(:scope_menu_partial) { "#{scope_menu_view_path}_#{scope_menu_view_name}" }
let(:content) { 'Custom test content' }
context 'when sidebar has a custom scope menu partial defined' do
it 'renders the custom partial' do
allow(sidebar).to receive(:render_raw_scope_menu_partial).and_return(scope_menu_view)
allow(sidebar).to receive(:scope_menu).and_return(nil)
stub_template(scope_menu_partial => content)
render
expect(rendered).to have_text(content)
end
end
end
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