Module: SidebarsHelper

Includes:
MergeRequestsHelper, Nav::NewDropdownHelper
Defined in:
app/helpers/sidebars_helper.rb

Instance Method Summary collapse

Methods included from Nav::NewDropdownHelper

#new_dropdown_view_model

Methods included from MergeRequestsHelper

#allow_collaboration_unavailable_reason, #award_emoji_merge_request_api_path, #create_mr_button_from_event?, #create_mr_path_from_push_event, #diffs_tab_pane_data, #format_mr_branch_names, #how_merge_modal_data, #merge_params, #merge_path_description, #merge_request_button_hidden?, #merge_request_source_project_for_project, #merge_request_version_path, #moved_mr_sidebar_enabled?, #mr_change_branches_path, #mr_compare_form_data, #mr_css_classes, #reviewers_label, #tab_link_for, #target_projects, #user_merge_requests_counts

Methods included from CompareHelper

#create_mr_button?, #create_mr_path, #project_compare_selector_data, #target_projects

Instance Method Details

#command_palette_data(project: nil) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'app/helpers/sidebars_helper.rb', line 159

def command_palette_data(project: nil)
  return {} unless project&.repo_exists?
  return {} if project.empty_repo?

  {
    project_files_url: project_files_path(project, project.default_branch, format: :json),
    project_blob_url: project_blob_path(project, project.default_branch)
  }
end

#group_sidebar_context(group, user, **args) ⇒ Object



35
36
37
38
39
# File 'app/helpers/sidebars_helper.rb', line 35

def group_sidebar_context(group, user, **args)
  context_data = group_sidebar_context_data(group, user)

  Sidebars::Groups::Context.new(**context_data, **args)
end

#organization_sidebar_context(organization, user, **args) ⇒ Object



26
27
28
# File 'app/helpers/sidebars_helper.rb', line 26

def organization_sidebar_context(organization, user, **args)
  Sidebars::Context.new(container: organization, current_user: user, **args)
end

#project_sidebar_context(project, user, current_ref, ref_type: nil, **args) ⇒ Object



30
31
32
33
# File 'app/helpers/sidebars_helper.rb', line 30

def project_sidebar_context(project, user, current_ref, ref_type: nil, **args)
  context_data = project_sidebar_context_data(project, user, current_ref, ref_type: ref_type)
  Sidebars::Projects::Context.new(**context_data, **args)
end

#scope_avatar_classes(object) ⇒ Object



19
20
21
22
23
24
# File 'app/helpers/sidebars_helper.rb', line 19

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

#scope_qa_menu_item(object) ⇒ Object



15
16
17
# File 'app/helpers/sidebars_helper.rb', line 15

def scope_qa_menu_item(object)
  sidebar_attributes_for_object(object).fetch(:scope_qa_menu_item, nil)
end


11
12
13
# File 'app/helpers/sidebars_helper.rb', line 11

def sidebar_qa_selector(object)
  sidebar_attributes_for_object(object).fetch(:sidebar_qa_selector, nil)
end


7
8
9
# File 'app/helpers/sidebars_helper.rb', line 7

def sidebar_tracking_attributes_by_object(object)
  sidebar_attributes_for_object(object).fetch(:tracking_attrs, {})
end

#super_sidebar_context(user, group:, project:, panel:, panel_type:) ⇒ Object

rubocop:disable Metrics/AbcSize



47
48
49
50
51
# File 'app/helpers/sidebars_helper.rb', line 47

def super_sidebar_context(user, group:, project:, panel:, panel_type:) # rubocop:disable Metrics/AbcSize
  return super_sidebar_logged_out_context(panel: panel, panel_type: panel_type) unless user

  super_sidebar_logged_in_context(user, group: group, project: project, panel: panel, panel_type: panel_type)
end

#super_sidebar_logged_in_context(user, group:, project:, panel:, panel_type:) ⇒ Object

rubocop:disable Metrics/AbcSize



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/sidebars_helper.rb', line 72

def super_sidebar_logged_in_context(user, group:, project:, panel:, panel_type:) # rubocop:disable Metrics/AbcSize
  super_sidebar_logged_out_context(panel: panel, panel_type: panel_type).merge({
    is_logged_in: true,
    name: user.name,
    username: user.username,
    avatar_url: user.avatar_url,
    has_link_to_profile: current_user_menu?(:profile),
    link_to_profile: user_path(user),
    logo_url: current_appearance&.header_logo_path,
    status: user_status_menu_data(user),
    settings: {
      has_settings: current_user_menu?(:settings),
      profile_path: profile_path,
      profile_preferences_path: profile_preferences_path
    },
    user_counts: {
      assigned_issues: user.assigned_open_issues_count,
      assigned_merge_requests: user.assigned_open_merge_requests_count,
      review_requested_merge_requests: user.review_requested_open_merge_requests_count,
      todos: user.todos_pending_count,
      last_update: time_in_milliseconds
    },
    can_sign_out: current_user_menu?(:sign_out),
    sign_out_link: destroy_user_session_path,
    issues_dashboard_path: issues_dashboard_path(assignee_username: user.username),
    todos_dashboard_path: dashboard_todos_path,
    create_new_menu_groups: create_new_menu_groups(group: group, project: project),
    merge_request_menu: create_merge_request_menu(user),
    projects_path: dashboard_projects_path,
    groups_path: dashboard_groups_path,
    gitlab_com_but_not_canary: Gitlab.com_but_not_canary?,
    gitlab_com_and_canary: Gitlab.com_and_canary?,
    canary_toggle_com_url: Gitlab::Saas.canary_toggle_com_url,
    current_context: super_sidebar_current_context(project: project, group: group),
    pinned_items: user.pinned_nav_items[panel_type] || super_sidebar_default_pins(panel_type),
    update_pins_url: pins_path,
    is_impersonating: impersonating?,
    stop_impersonation_path: admin_impersonation_path,
    shortcut_links: shortcut_links(user: user, project: project),
    track_visits_path: track_namespace_visits_path
  })
end

#super_sidebar_logged_out_context(panel:, panel_type:) ⇒ Object

rubocop:disable Metrics/AbcSize



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/sidebars_helper.rb', line 53

def super_sidebar_logged_out_context(panel:, panel_type:) # rubocop:disable Metrics/AbcSize
  {
    is_logged_in: false,
    context_switcher_links: context_switcher_links,
    current_menu_items: panel.super_sidebar_menu_items,
    current_context_header: panel.super_sidebar_context_header,
    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,
    search: search_data,
    panel_type: panel_type,
    shortcut_links: shortcut_links
  }
end

#super_sidebar_nav_panel(nav: nil, project: nil, user: nil, group: nil, current_ref: nil, ref_type: nil, viewed_user: nil, organization: nil) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/helpers/sidebars_helper.rb', line 115

def super_sidebar_nav_panel(
  nav: nil, project: nil, user: nil, group: nil, current_ref: nil, ref_type: nil,
  viewed_user: nil, organization: nil)
  context_adds = { route_is_active: method(:active_nav_link?), is_super_sidebar: true }
  panel = case nav
          when 'project'
            context = project_sidebar_context(project, user, current_ref, ref_type: ref_type, **context_adds)
            Sidebars::Projects::SuperSidebarPanel.new(context)
          when 'group'
            context = group_sidebar_context(group, user, **context_adds)
            Sidebars::Groups::SuperSidebarPanel.new(context)
          when 'profile'
            context = Sidebars::Context.new(current_user: user, container: user, **context_adds)
            Sidebars::UserSettings::Panel.new(context)
          when 'user_profile'
            context = Sidebars::Context.new(current_user: user, container: viewed_user, **context_adds)
            Sidebars::UserProfile::Panel.new(context)
          when 'explore'
            Sidebars::Explore::Panel.new(Sidebars::Context.new(current_user: user, container: nil, **context_adds))
          when 'search'
            context = Sidebars::Context.new(current_user: user, container: nil, **context_adds)
            Sidebars::Search::Panel.new(context)
          when 'admin'
            Sidebars::Admin::Panel.new(Sidebars::Context.new(current_user: user, container: nil, **context_adds))
          when 'organization'
            context = organization_sidebar_context(organization, user, **context_adds)
            Sidebars::Organizations::SuperSidebarPanel.new(context)
          when 'your_work'
            context = your_work_sidebar_context(user, **context_adds)
            Sidebars::YourWork::Panel.new(context)
          end

  # We only return the panel if any menu item is rendered, otherwise fallback
  return panel if panel&.render?

  # Fallback menu "Your work" for logged-in users, "Explore" for logged-out
  if user
    context = your_work_sidebar_context(user, **context_adds)
    Sidebars::YourWork::Panel.new(context)
  else
    Sidebars::Explore::Panel.new(Sidebars::Context.new(current_user: nil, container: nil, **context_adds))
  end
end

#your_work_sidebar_context(user, **args) ⇒ Object



41
42
43
44
45
# File 'app/helpers/sidebars_helper.rb', line 41

def your_work_sidebar_context(user, **args)
  context_data = your_work_context_data(user)

  Sidebars::Context.new(**context_data, **args)
end