summaryrefslogtreecommitdiff
path: root/app/helpers/sidebars_helper.rb
blob: 31dfe21671a72b9ac41fdee85c35ac8805f369bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module SidebarsHelper
  def sidebar_tracking_attributes_by_object(object)
    case object
    when Project
      sidebar_project_tracking_attrs
    when Group
      sidebar_group_tracking_attrs
    when User
      sidebar_user_profile_tracking_attrs
    else
      {}
    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

  private

  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

  def project_sidebar_context_data(project, user, current_ref)
    {
      current_user: user,
      container: project,
      learn_gitlab_experiment_enabled: learn_gitlab_experiment_enabled?(project),
      current_ref: current_ref
    }
  end
end