2021-09-04 01:27:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Nav
|
|
|
|
module NewDropdownHelper
|
|
|
|
def new_dropdown_view_model(group:, project:)
|
|
|
|
return unless current_user
|
|
|
|
|
|
|
|
menu_sections = []
|
2023-05-27 22:25:52 +05:30
|
|
|
data = { title: _('Create new...') }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
if project&.persisted?
|
2021-09-04 01:27:46 +05:30
|
|
|
menu_sections.push(project_menu_section(project))
|
2023-05-27 22:25:52 +05:30
|
|
|
elsif group&.persisted?
|
|
|
|
menu_sections.push(group_menu_section(group))
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
menu_sections.push(general_menu_section)
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
data[:menu_sections] = menu_sections.select { |x| x.fetch(:menu_items).any? }
|
|
|
|
|
|
|
|
data
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_menu_section(group)
|
|
|
|
menu_items = []
|
|
|
|
|
|
|
|
if can?(current_user, :create_projects, group)
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'new_project',
|
2021-09-30 23:02:18 +05:30
|
|
|
title: _('New project/repository'),
|
2021-09-04 01:27:46 +05:30
|
|
|
href: new_project_path(namespace_id: group.id),
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_project_group', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if can?(current_user, :create_subgroup, group)
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'new_subgroup',
|
|
|
|
title: _('New subgroup'),
|
2022-08-27 11:52:29 +05:30
|
|
|
href: new_group_path(parent_id: group.id, anchor: 'create-group-pane'),
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_subgroup', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
menu_items.push(create_epic_menu_item(group))
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
if can?(current_user, :admin_group_member, group)
|
2023-05-27 22:25:52 +05:30
|
|
|
menu_items.push(invite_members_menu_item(partial: 'groups/invite_members_top_nav_link'))
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
{
|
2023-04-23 21:23:45 +05:30
|
|
|
title: _('In this group'),
|
2021-09-04 01:27:46 +05:30
|
|
|
menu_items: menu_items.compact
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_menu_section(project)
|
|
|
|
menu_items = []
|
|
|
|
merge_project = merge_request_source_project_for_project(project)
|
|
|
|
|
|
|
|
if show_new_issue_link?(project)
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'new_issue',
|
|
|
|
title: _('New issue'),
|
|
|
|
href: new_project_issue_path(project),
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_issue', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', qa_selector: 'new_issue_link' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if merge_project
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'new_mr',
|
|
|
|
title: _('New merge request'),
|
|
|
|
href: project_new_merge_request_path(merge_project),
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_mr', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if can?(current_user, :create_snippet, project)
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'new_snippet',
|
|
|
|
title: _('New snippet'),
|
|
|
|
href: new_project_snippet_path(project),
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_snippet_project', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
if can_admin_project_member?(project)
|
2023-05-27 22:25:52 +05:30
|
|
|
menu_items.push(invite_members_menu_item(partial: 'projects/invite_members_top_nav_link'))
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
{
|
2023-04-23 21:23:45 +05:30
|
|
|
title: _('In this project'),
|
2021-09-04 01:27:46 +05:30
|
|
|
menu_items: menu_items
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def general_menu_section
|
|
|
|
menu_items = []
|
|
|
|
|
|
|
|
if current_user.can_create_project?
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'general_new_project',
|
2021-09-30 23:02:18 +05:30
|
|
|
title: _('New project/repository'),
|
2021-09-04 01:27:46 +05:30
|
|
|
href: new_project_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_project', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', qa_selector: 'global_new_project_link' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if current_user.can_create_group?
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'general_new_group',
|
|
|
|
title: _('New group'),
|
|
|
|
href: new_group_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_group', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', qa_selector: 'global_new_group_link' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if current_user.can?(:create_snippet)
|
|
|
|
menu_items.push(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'general_new_snippet',
|
|
|
|
title: _('New snippet'),
|
|
|
|
href: new_snippet_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
data: { track_action: 'click_link_new_snippet_parent', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', qa_selector: 'global_new_snippet_link' }
|
2021-09-04 01:27:46 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
2023-04-23 21:23:45 +05:30
|
|
|
title: _('In GitLab'),
|
2021-09-04 01:27:46 +05:30
|
|
|
menu_items: menu_items
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def invite_members_menu_item(partial:)
|
2021-09-04 01:27:46 +05:30
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'invite',
|
|
|
|
title: s_('InviteMember|Invite members'),
|
2023-05-27 22:25:52 +05:30
|
|
|
icon: 'shaking_hands',
|
|
|
|
partial: partial,
|
|
|
|
component: 'invite_members',
|
2021-09-04 01:27:46 +05:30
|
|
|
data: {
|
2023-05-27 22:25:52 +05:30
|
|
|
trigger_source: 'top-nav',
|
|
|
|
trigger_element: 'text-emoji'
|
2021-09-04 01:27:46 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Overridden in EE
|
|
|
|
def create_epic_menu_item(group)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Nav::NewDropdownHelper.prepend_mod
|