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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
114
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# frozen_string_literal: true
module Nav
module NewDropdownHelper
def new_dropdown_view_model(group:, project:)
return unless current_user
menu_sections = []
data = { title: _('Create new...') }
if project&.persisted?
menu_sections.push(project_menu_section(project))
elsif group&.persisted?
menu_sections.push(group_menu_section(group))
end
menu_sections.push(general_menu_section)
data[:menu_sections] = menu_sections.select { |x| x.fetch(:menu_items).any? }
data
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',
title: _('New project/repository'),
href: new_project_path(namespace_id: group.id),
data: { track_action: 'click_link_new_project_group', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
)
)
end
if can?(current_user, :create_subgroup, group)
menu_items.push(
::Gitlab::Nav::TopNavMenuItem.build(
id: 'new_subgroup',
title: _('New subgroup'),
href: new_group_path(parent_id: group.id, anchor: 'create-group-pane'),
data: { track_action: 'click_link_new_subgroup', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
)
)
end
menu_items.push(create_epic_menu_item(group))
if can?(current_user, :admin_group_member, group)
menu_items.push(invite_members_menu_item(partial: 'groups/invite_members_top_nav_link'))
end
{
title: _('In this group'),
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),
data: { track_action: 'click_link_new_issue', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', testid: 'new_issue_link' }
)
)
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),
data: { track_action: 'click_link_new_mr', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
)
)
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),
data: { track_action: 'click_link_new_snippet_project', track_label: 'plus_menu_dropdown', track_property: 'navigation_top' }
)
)
end
if can_admin_project_member?(project)
menu_items.push(invite_members_menu_item(partial: 'projects/invite_members_top_nav_link'))
end
{
title: _('In this project'),
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',
title: _('New project/repository'),
href: new_project_path,
data: { track_action: 'click_link_new_project', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', testid: 'global_new_project_link' }
)
)
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,
data: { track_action: 'click_link_new_group', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', testid: 'global_new_group_link' }
)
)
end
if Feature.enabled?(:ui_for_organizations, current_user) && current_user.can?(:create_organization)
menu_items.push(
::Gitlab::Nav::TopNavMenuItem.build(
id: 'general_new_organization',
title: s_('Organization|New organization'),
href: new_organization_path,
data: { track_action: 'click_link_new_organization_parent', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', testid: 'global_new_organization_link' }
)
)
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,
data: { track_action: 'click_link_new_snippet_parent', track_label: 'plus_menu_dropdown', track_property: 'navigation_top', testid: 'global_new_snippet_link' }
)
)
end
{
title: _('In GitLab'),
menu_items: menu_items
}
end
def invite_members_menu_item(partial:)
::Gitlab::Nav::TopNavMenuItem.build(
id: 'invite',
title: s_('InviteMember|Invite members'),
icon: 'shaking_hands',
partial: partial,
component: 'invite_members',
data: {
trigger_source: 'top_nav',
trigger_element: 'text-emoji'
}
)
end
# Overridden in EE
def create_epic_menu_item(group)
nil
end
end
end
Nav::NewDropdownHelper.prepend_mod
|