Refactoring Sidebar Project Panel

In this commit we start the refactor of the project sidebar.

Instead of the current approach with all the logic in views and helpers,
we're moving to a model based structure where each menu model contains
its logic, visibility access levels, and all the necessary info.

Nevertheless, the migration is tricky because we cannot just replace
the whole sidebar (that would be a 130 files MR). In order to
make it incremental we still render the old views. Then, when we
add a new menu to the new structure we'll remove that menu
from the menu, until we migrate all menus and we can remove the view
entirely.
parent be1a7cff
......@@ -14,6 +14,10 @@ module SidebarsHelper
end
end
def project_sidebar_context(project, user)
Sidebars::Context.new(**project_sidebar_context_data(project, user))
end
private
def sidebar_project_tracking_attrs
......@@ -27,4 +31,12 @@ module SidebarsHelper
def sidebar_user_profile_tracking_attrs
tracking_attrs('user_side_navigation', 'render', 'user_side_navigation')
end
def project_sidebar_context_data(project, user)
{
current_user: user,
container: project,
project: project
}
end
end
......@@ -51,5 +51,25 @@ module Sidebars
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
end
end
# frozen_string_literal: true
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'
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')
end
end
end
end
This diff is collapsed.
.context-header
= link_to project_path(@project), title: @project.name do
.avatar-container.rect-avatar.s40.project-avatar
= project_icon(@project, alt: @project.name, class: 'avatar s40 avatar-tile', width: 40, height: 40)
.sidebar-context-title
= @project.name
%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
= render sidebar.render_raw_scope_menu_partial
%ul.sidebar-top-level-items.qa-project-sidebar
- if sidebar.render_raw_menus_partial
= render sidebar.render_raw_menus_partial
= render 'shared/sidebar_toggle_button'
......@@ -13,7 +13,7 @@ module QA
include SubMenus::Settings
include SubMenus::Packages
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :activity_link
element :merge_requests_link
element :snippets_link
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :link_pipelines
end
end
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :issue_boards_link
element :issues_item
element :labels_link
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :operations_link
element :operations_environments_link
element :operations_metrics_link
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :project_link
end
end
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :repository_link
element :branches_link
element :tags_link
......
......@@ -13,7 +13,7 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/layouts/nav/sidebar/_project.html.haml' do
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :settings_item
element :general_settings_link
element :integrations_settings_link
......
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