2021-04-29 21:17:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SidebarsHelper
|
2023-04-23 21:23:45 +05:30
|
|
|
include MergeRequestsHelper
|
|
|
|
include Nav::NewDropdownHelper
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def sidebar_tracking_attributes_by_object(object)
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_attributes_for_object(object).fetch(:tracking_attrs, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_qa_selector(object)
|
|
|
|
sidebar_attributes_for_object(object).fetch(:sidebar_qa_selector, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def scope_qa_menu_item(object)
|
|
|
|
sidebar_attributes_for_object(object).fetch(:scope_qa_menu_item, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def scope_avatar_classes(object)
|
|
|
|
%w[avatar-container rect-avatar s32].tap do |klasses|
|
|
|
|
klass = sidebar_attributes_for_object(object).fetch(:scope_avatar_class, nil)
|
|
|
|
klasses << klass if klass
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
def project_sidebar_context(project, user, current_ref, ref_type: nil)
|
|
|
|
context_data = project_sidebar_context_data(project, user, current_ref, ref_type: ref_type)
|
2021-09-30 23:02:18 +05:30
|
|
|
Sidebars::Projects::Context.new(**context_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_sidebar_context(group, user)
|
|
|
|
context_data = group_sidebar_context_data(group, user)
|
|
|
|
|
|
|
|
Sidebars::Groups::Context.new(**context_data)
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def super_sidebar_context(user, group:, project:)
|
2023-03-17 16:20:25 +05:30
|
|
|
{
|
|
|
|
name: user.name,
|
|
|
|
username: user.username,
|
|
|
|
avatar_url: user.avatar_url,
|
|
|
|
assigned_open_issues_count: user.assigned_open_issues_count,
|
|
|
|
todos_pending_count: user.todos_pending_count,
|
2023-04-23 21:23:45 +05:30
|
|
|
issues_dashboard_path: issues_dashboard_path(assignee_username: user.username),
|
|
|
|
total_merge_requests_count: user_merge_requests_counts[:total],
|
|
|
|
create_new_menu_groups: create_new_menu_groups(group: group, project: project),
|
|
|
|
merge_request_menu: create_merge_request_menu(user),
|
|
|
|
support_path: support_url,
|
|
|
|
display_whats_new: display_whats_new?,
|
|
|
|
whats_new_most_recent_release_items_count: whats_new_most_recent_release_items_count,
|
|
|
|
whats_new_version_digest: whats_new_version_digest,
|
|
|
|
show_version_check: show_version_check?,
|
|
|
|
gitlab_version: Gitlab.version_info,
|
|
|
|
gitlab_version_check: gitlab_version_check
|
2023-03-17 16:20:25 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
private
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def create_new_menu_groups(group:, project:)
|
|
|
|
new_dropdown_sections = new_dropdown_view_model(group: group, project: project)[:menu_sections]
|
|
|
|
show_headers = new_dropdown_sections.length > 1
|
|
|
|
new_dropdown_sections.map do |section|
|
|
|
|
{
|
|
|
|
name: show_headers ? section[:title] : '',
|
|
|
|
items: section[:menu_items].map do |item|
|
|
|
|
{
|
|
|
|
text: item[:title],
|
|
|
|
href: item[:href]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_merge_request_menu(user)
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: _('Merge requests'),
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
text: _('Assigned'),
|
|
|
|
href: merge_requests_dashboard_path(assignee_username: user.username),
|
|
|
|
count: user_merge_requests_counts[:assigned]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: _('Review requests'),
|
|
|
|
href: merge_requests_dashboard_path(reviewer_username: user.username),
|
|
|
|
count: user_merge_requests_counts[:review_requested]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_attributes_for_object(object)
|
2021-04-29 21:17:54 +05:30
|
|
|
case object
|
|
|
|
when Project
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_project_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
when Group
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_group_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
when User
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_user_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_project_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_project_tracking_attrs,
|
|
|
|
sidebar_qa_selector: 'project_sidebar',
|
|
|
|
scope_qa_menu_item: 'Project scope',
|
|
|
|
scope_avatar_class: 'project_avatar'
|
|
|
|
}
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_group_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_group_tracking_attrs,
|
|
|
|
sidebar_qa_selector: 'group_sidebar',
|
|
|
|
scope_qa_menu_item: 'Group scope',
|
|
|
|
scope_avatar_class: 'group_avatar'
|
|
|
|
}
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_user_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_user_profile_tracking_attrs
|
|
|
|
}
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def sidebar_project_tracking_attrs
|
|
|
|
tracking_attrs('projects_side_navigation', 'render', 'projects_side_navigation')
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_group_tracking_attrs
|
|
|
|
tracking_attrs('groups_side_navigation', 'render', 'groups_side_navigation')
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_user_profile_tracking_attrs
|
|
|
|
tracking_attrs('user_side_navigation', 'render', 'user_side_navigation')
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
def project_sidebar_context_data(project, user, current_ref, ref_type: nil)
|
2021-04-29 21:17:54 +05:30
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: project,
|
2021-06-08 01:23:25 +05:30
|
|
|
current_ref: current_ref,
|
2023-03-04 22:38:38 +05:30
|
|
|
ref_type: ref_type,
|
2021-06-08 01:23:25 +05:30
|
|
|
jira_issues_integration: project_jira_issues_integration?,
|
|
|
|
can_view_pipeline_editor: can_view_pipeline_editor?(project),
|
|
|
|
show_cluster_hint: show_gke_cluster_integration_callout?(project)
|
2021-04-29 21:17:54 +05:30
|
|
|
}
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
def group_sidebar_context_data(group, user)
|
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: group
|
|
|
|
}
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
SidebarsHelper.prepend_mod_with('SidebarsHelper')
|