2021-03-29 11:09:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SidebarsHelper
|
|
|
|
def sidebar_tracking_attributes_by_object(object)
|
2021-07-13 14:08:57 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
def project_sidebar_context(project, user, current_ref)
|
|
|
|
context_data = project_sidebar_context_data(project, user, current_ref)
|
|
|
|
|
|
|
|
Sidebars::Projects::Context.new(**context_data)
|
|
|
|
end
|
|
|
|
|
2021-07-15 08:09:01 -04:00
|
|
|
def group_sidebar_context(group, user)
|
|
|
|
context_data = group_sidebar_context_data(group, user)
|
|
|
|
|
|
|
|
Sidebars::Groups::Context.new(**context_data)
|
|
|
|
end
|
|
|
|
|
2021-07-13 14:08:57 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def sidebar_attributes_for_object(object)
|
2021-03-29 11:09:30 -04:00
|
|
|
case object
|
|
|
|
when Project
|
2021-07-13 14:08:57 -04:00
|
|
|
sidebar_project_attributes
|
2021-03-29 11:09:30 -04:00
|
|
|
when Group
|
2021-07-13 14:08:57 -04:00
|
|
|
sidebar_group_attributes
|
2021-03-29 11:09:30 -04:00
|
|
|
when User
|
2021-07-13 14:08:57 -04:00
|
|
|
sidebar_user_attributes
|
2021-03-29 11:09:30 -04:00
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-13 14:08:57 -04:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
end
|
2021-04-20 08:09:30 -04:00
|
|
|
|
2021-07-13 14:08:57 -04:00
|
|
|
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-04-12 08:09:15 -04:00
|
|
|
end
|
|
|
|
|
2021-07-13 14:08:57 -04:00
|
|
|
def sidebar_user_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_user_profile_tracking_attrs
|
|
|
|
}
|
|
|
|
end
|
2021-03-29 11:09:30 -04:00
|
|
|
|
|
|
|
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
|
2021-04-12 08:09:15 -04:00
|
|
|
|
2021-04-20 08:09:30 -04:00
|
|
|
def project_sidebar_context_data(project, user, current_ref)
|
2021-04-12 08:09:15 -04:00
|
|
|
{
|
|
|
|
current_user: user,
|
2021-04-15 14:09:01 -04:00
|
|
|
container: project,
|
2021-04-20 08:09:30 -04:00
|
|
|
learn_gitlab_experiment_enabled: learn_gitlab_experiment_enabled?(project),
|
2021-04-27 08:10:12 -04:00
|
|
|
current_ref: current_ref,
|
2021-04-29 05:10:11 -04:00
|
|
|
jira_issues_integration: project_jira_issues_integration?,
|
2021-04-30 11:09:50 -04:00
|
|
|
can_view_pipeline_editor: can_view_pipeline_editor?(project),
|
|
|
|
show_cluster_hint: show_gke_cluster_integration_callout?(project)
|
2021-04-12 08:09:15 -04:00
|
|
|
}
|
|
|
|
end
|
2021-07-15 08:09:01 -04:00
|
|
|
|
|
|
|
def group_sidebar_context_data(group, user)
|
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: group
|
|
|
|
}
|
|
|
|
end
|
2021-03-29 11:09:30 -04:00
|
|
|
end
|
2021-04-29 11:10:07 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
SidebarsHelper.prepend_mod_with('SidebarsHelper')
|