Commit c656d167 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '301143-fix-shortcuts' into 'master'

Fix shortcuts for top nav redesign

See merge request gitlab-org/gitlab!62047
parents 8ea10016 47c1a779
...@@ -22,32 +22,26 @@ module Nav ...@@ -22,32 +22,26 @@ module Nav
def build_anonymous_view_model(builder:) def build_anonymous_view_model(builder:)
# These come from `app/views/layouts/nav/_explore.html.ham` # These come from `app/views/layouts/nav/_explore.html.ham`
if explore_nav_link?(:projects) if explore_nav_link?(:projects)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**projects_menu_item_attrs.merge( href: explore_root_path,
{ active: active_nav_link?(path: %w[dashboard#show root#show projects#trending projects#starred projects#index]),
active: active_nav_link?(path: %w[dashboard#show root#show projects#trending projects#starred projects#index]), **projects_menu_item_attrs
href: explore_root_path
})
) )
end end
if explore_nav_link?(:groups) if explore_nav_link?(:groups)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**groups_menu_item_attrs.merge( href: explore_groups_path,
{ active: active_nav_link?(controller: [:groups, 'groups/milestones', 'groups/group_members']),
active: active_nav_link?(controller: [:groups, 'groups/milestones', 'groups/group_members']), **groups_menu_item_attrs
href: explore_groups_path
})
) )
end end
if explore_nav_link?(:snippets) if explore_nav_link?(:snippets)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**snippets_menu_item_attrs.merge( active: active_nav_link?(controller: :snippets),
{ href: explore_snippets_path,
active: active_nav_link?(controller: :snippets), **snippets_menu_item_attrs
href: explore_snippets_path
})
) )
end end
end end
...@@ -57,13 +51,13 @@ module Nav ...@@ -57,13 +51,13 @@ module Nav
if dashboard_nav_link?(:projects) if dashboard_nav_link?(:projects)
current_item = project ? current_project(project: project) : {} current_item = project ? current_project(project: project) : {}
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**projects_menu_item_attrs.merge({ active: active_nav_link?(path: %w[root#index projects#trending projects#starred dashboard/projects#index]),
active: active_nav_link?(path: %w[root#index projects#trending projects#starred dashboard/projects#index]), css_class: 'qa-projects-dropdown',
css_class: 'qa-projects-dropdown', data: { track_label: "projects_dropdown", track_event: "click_dropdown", track_experiment: "new_repo" },
data: { track_label: "projects_dropdown", track_event: "click_dropdown", track_experiment: "new_repo" }, view: PROJECTS_VIEW,
view: PROJECTS_VIEW shortcut_href: dashboard_projects_path,
}) **projects_menu_item_attrs
) )
builder.add_view(PROJECTS_VIEW, container_view_props(namespace: 'projects', current_item: current_item, submenu: projects_submenu)) builder.add_view(PROJECTS_VIEW, container_view_props(namespace: 'projects', current_item: current_item, submenu: projects_submenu))
end end
...@@ -71,46 +65,47 @@ module Nav ...@@ -71,46 +65,47 @@ module Nav
if dashboard_nav_link?(:groups) if dashboard_nav_link?(:groups)
current_item = group ? current_group(group: group) : {} current_item = group ? current_group(group: group) : {}
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**groups_menu_item_attrs.merge({ active: active_nav_link?(path: %w[dashboard/groups explore/groups]),
active: active_nav_link?(path: %w[dashboard/groups explore/groups]), css_class: 'qa-groups-dropdown',
css_class: 'qa-groups-dropdown', data: { track_label: "groups_dropdown", track_event: "click_dropdown" },
data: { track_label: "groups_dropdown", track_event: "click_dropdown" }, view: GROUPS_VIEW,
view: GROUPS_VIEW shortcut_href: dashboard_groups_path,
}) **groups_menu_item_attrs
) )
builder.add_view(GROUPS_VIEW, container_view_props(namespace: 'groups', current_item: current_item, submenu: groups_submenu)) builder.add_view(GROUPS_VIEW, container_view_props(namespace: 'groups', current_item: current_item, submenu: groups_submenu))
end end
if dashboard_nav_link?(:milestones) if dashboard_nav_link?(:milestones)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
id: 'milestones', id: 'milestones',
title: 'Milestones', title: 'Milestones',
href: dashboard_milestones_path,
active: active_nav_link?(controller: 'dashboard/milestones'), active: active_nav_link?(controller: 'dashboard/milestones'),
icon: 'clock', icon: 'clock',
data: { qa_selector: 'milestones_link' }, data: { qa_selector: 'milestones_link' },
href: dashboard_milestones_path shortcut_class: 'dashboard-shortcuts-milestones'
) )
end end
if dashboard_nav_link?(:snippets) if dashboard_nav_link?(:snippets)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
**snippets_menu_item_attrs.merge({ active: active_nav_link?(controller: 'dashboard/snippets'),
active: active_nav_link?(controller: 'dashboard/snippets'), data: { qa_selector: 'snippets_link' },
data: { qa_selector: 'snippets_link' }, href: dashboard_snippets_path,
href: dashboard_snippets_path **snippets_menu_item_attrs
})
) )
end end
if dashboard_nav_link?(:activity) if dashboard_nav_link?(:activity)
builder.add_primary_menu_item( builder.add_primary_menu_item_with_shortcut(
id: 'activity', id: 'activity',
title: 'Activity', title: 'Activity',
href: activity_dashboard_path,
active: active_nav_link?(path: 'dashboard#activity'), active: active_nav_link?(path: 'dashboard#activity'),
icon: 'history', icon: 'history',
data: { qa_selector: 'activity_link' }, data: { qa_selector: 'activity_link' },
href: activity_dashboard_path shortcut_class: 'dashboard-shortcuts-activity'
) )
end end
...@@ -165,7 +160,8 @@ module Nav ...@@ -165,7 +160,8 @@ module Nav
{ {
id: 'project', id: 'project',
title: _('Projects'), title: _('Projects'),
icon: 'project' icon: 'project',
shortcut_class: 'dashboard-shortcuts-projects'
} }
end end
...@@ -173,7 +169,8 @@ module Nav ...@@ -173,7 +169,8 @@ module Nav
{ {
id: 'groups', id: 'groups',
title: 'Groups', title: 'Groups',
icon: 'group' icon: 'group',
shortcut_class: 'dashboard-shortcuts-groups'
} }
end end
...@@ -181,7 +178,8 @@ module Nav ...@@ -181,7 +178,8 @@ module Nav
{ {
id: 'snippets', id: 'snippets',
title: _('Snippets'), title: _('Snippets'),
icon: 'snippet' icon: 'snippet',
shortcut_class: 'dashboard-shortcuts-snippets'
} }
end end
......
...@@ -5,3 +5,8 @@ ...@@ -5,3 +5,8 @@
= sprite_icon('dot-grid', css_class: "dropdown-icon") = sprite_icon('dot-grid', css_class: "dropdown-icon")
= view_model[:activeTitle] = view_model[:activeTitle]
= sprite_icon('chevron-down') = sprite_icon('chevron-down')
.hidden
- view_model[:shortcuts].each do |shortcut|
= link_to shortcut[:href], class: shortcut[:css_class] do
= shortcut[:title]
...@@ -6,9 +6,34 @@ module Gitlab ...@@ -6,9 +6,34 @@ module Gitlab
def initialize def initialize
@menu_builder = ::Gitlab::Nav::TopNavMenuBuilder.new @menu_builder = ::Gitlab::Nav::TopNavMenuBuilder.new
@views = {} @views = {}
@shortcuts = []
end end
delegate :add_primary_menu_item, :add_secondary_menu_item, to: :@menu_builder # Using delegate hides the stacktrace for some errors, so we choose to be explicit.
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62047#note_579031091
def add_primary_menu_item(**args)
@menu_builder.add_primary_menu_item(**args)
end
def add_secondary_menu_item(**args)
@menu_builder.add_secondary_menu_item(**args)
end
def add_shortcut(**args)
item = ::Gitlab::Nav::TopNavMenuItem.build(**args)
@shortcuts.push(item)
end
def add_primary_menu_item_with_shortcut(shortcut_class:, shortcut_href: nil, **args)
add_primary_menu_item(**args)
add_shortcut(
id: "#{args.fetch(:id)}-shortcut",
title: args.fetch(:title),
href: shortcut_href || args.fetch(:href),
css_class: shortcut_class
)
end
def add_view(name, props) def add_view(name, props)
@views[name] = props @views[name] = props
...@@ -19,6 +44,7 @@ module Gitlab ...@@ -19,6 +44,7 @@ module Gitlab
menu.merge({ menu.merge({
views: @views, views: @views,
shortcuts: @shortcuts,
activeTitle: _('Menu') activeTitle: _('Menu')
}) })
end end
......
...@@ -15,8 +15,6 @@ RSpec.describe 'Dashboard shortcuts', :js do ...@@ -15,8 +15,6 @@ RSpec.describe 'Dashboard shortcuts', :js do
end end
it 'navigate to tabs' do it 'navigate to tabs' do
pending_on_combined_menu_flag
find('body').send_keys([:shift, 'I']) find('body').send_keys([:shift, 'I'])
check_page_title('Issues') check_page_title('Issues')
...@@ -49,8 +47,6 @@ RSpec.describe 'Dashboard shortcuts', :js do ...@@ -49,8 +47,6 @@ RSpec.describe 'Dashboard shortcuts', :js do
end end
it 'navigate to tabs' do it 'navigate to tabs' do
pending_on_combined_menu_flag
find('body').send_keys([:shift, 'G']) find('body').send_keys([:shift, 'G'])
find('.nothing-here-block') find('.nothing-here-block')
...@@ -74,8 +70,6 @@ RSpec.describe 'Dashboard shortcuts', :js do ...@@ -74,8 +70,6 @@ RSpec.describe 'Dashboard shortcuts', :js do
end end
context 'with combined_menu: feature flag on' do context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do before do
stub_feature_flags(combined_menu: true) stub_feature_flags(combined_menu: true)
end end
...@@ -84,16 +78,10 @@ RSpec.describe 'Dashboard shortcuts', :js do ...@@ -84,16 +78,10 @@ RSpec.describe 'Dashboard shortcuts', :js do
end end
context 'with combined_menu feature flag off' do context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do before do
stub_feature_flags(combined_menu: false) stub_feature_flags(combined_menu: false)
end end
it_behaves_like 'combined_menu: feature flag examples' it_behaves_like 'combined_menu: feature flag examples'
end end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end
end end
...@@ -48,30 +48,51 @@ RSpec.describe Nav::TopNavHelper do ...@@ -48,30 +48,51 @@ RSpec.describe Nav::TopNavHelper do
context 'when current_user is nil (anonymous)' do context 'when current_user is nil (anonymous)' do
it 'has expected :primary' do it 'has expected :primary' do
expected_projects_item = ::Gitlab::Nav::TopNavMenuItem.build( expected_primary = [
href: '/explore', ::Gitlab::Nav::TopNavMenuItem.build(
icon: 'project', href: '/explore',
id: 'project', icon: 'project',
title: 'Projects' id: 'project',
) title: 'Projects'
expected_groups_item = ::Gitlab::Nav::TopNavMenuItem.build( ),
href: '/explore/groups', ::Gitlab::Nav::TopNavMenuItem.build(
icon: 'group', href: '/explore/groups',
id: 'groups', icon: 'group',
title: 'Groups' id: 'groups',
) title: 'Groups'
expected_snippets_item = ::Gitlab::Nav::TopNavMenuItem.build( ),
href: '/explore/snippets', ::Gitlab::Nav::TopNavMenuItem.build(
icon: 'snippet', href: '/explore/snippets',
id: 'snippets', icon: 'snippet',
title: 'Snippets' id: 'snippets',
) title: 'Snippets'
expect(subject[:primary]) )
.to eq([ ]
expected_projects_item, expect(subject[:primary]).to eq(expected_primary)
expected_groups_item, end
expected_snippets_item
]) it 'has expected :shortcuts' do
expected_shortcuts = [
::Gitlab::Nav::TopNavMenuItem.build(
href: '/explore',
id: 'project-shortcut',
title: 'Projects',
css_class: 'dashboard-shortcuts-projects'
),
::Gitlab::Nav::TopNavMenuItem.build(
href: '/explore/groups',
id: 'groups-shortcut',
title: 'Groups',
css_class: 'dashboard-shortcuts-groups'
),
::Gitlab::Nav::TopNavMenuItem.build(
href: '/explore/snippets',
id: 'snippets-shortcut',
title: 'Snippets',
css_class: 'dashboard-shortcuts-snippets'
)
]
expect(subject[:shortcuts]).to eq(expected_shortcuts)
end end
end end
...@@ -82,6 +103,7 @@ RSpec.describe Nav::TopNavHelper do ...@@ -82,6 +103,7 @@ RSpec.describe Nav::TopNavHelper do
expect(subject).to eq({ activeTitle: active_title, expect(subject).to eq({ activeTitle: active_title,
primary: [], primary: [],
secondary: [], secondary: [],
shortcuts: [],
views: {} }) views: {} })
end end
...@@ -105,6 +127,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -105,6 +127,16 @@ RSpec.describe Nav::TopNavHelper do
expect(subject[:primary]).to eq([expected_primary]) expect(subject[:primary]).to eq([expected_primary])
end end
it 'has expected :shortcuts' do
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
id: 'project-shortcut',
title: 'Projects',
href: '/dashboard/projects',
css_class: 'dashboard-shortcuts-projects'
)
expect(subject[:shortcuts]).to eq([expected_shortcuts])
end
context 'projects' do context 'projects' do
it 'has expected :currentUserName' do it 'has expected :currentUserName' do
expect(projects_view[:currentUserName]).to eq(current_user.username) expect(projects_view[:currentUserName]).to eq(current_user.username)
...@@ -191,6 +223,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -191,6 +223,16 @@ RSpec.describe Nav::TopNavHelper do
expect(subject[:primary]).to eq([expected_primary]) expect(subject[:primary]).to eq([expected_primary])
end end
it 'has expected :shortcuts' do
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
id: 'groups-shortcut',
title: 'Groups',
href: '/dashboard/groups',
css_class: 'dashboard-shortcuts-groups'
)
expect(subject[:shortcuts]).to eq([expected_shortcuts])
end
context 'groups' do context 'groups' do
it 'has expected :currentUserName' do it 'has expected :currentUserName' do
expect(groups_view[:currentUserName]).to eq(current_user.username) expect(groups_view[:currentUserName]).to eq(current_user.username)
...@@ -268,6 +310,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -268,6 +310,16 @@ RSpec.describe Nav::TopNavHelper do
) )
expect(subject[:primary]).to eq([expected_primary]) expect(subject[:primary]).to eq([expected_primary])
end end
it 'has expected :shortcuts' do
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
id: 'milestones-shortcut',
title: 'Milestones',
href: '/dashboard/milestones',
css_class: 'dashboard-shortcuts-milestones'
)
expect(subject[:shortcuts]).to eq([expected_shortcuts])
end
end end
context 'with snippets' do context 'with snippets' do
...@@ -285,6 +337,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -285,6 +337,16 @@ RSpec.describe Nav::TopNavHelper do
) )
expect(subject[:primary]).to eq([expected_primary]) expect(subject[:primary]).to eq([expected_primary])
end end
it 'has expected :shortcuts' do
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
id: 'snippets-shortcut',
title: 'Snippets',
href: '/dashboard/snippets',
css_class: 'dashboard-shortcuts-snippets'
)
expect(subject[:shortcuts]).to eq([expected_shortcuts])
end
end end
context 'with activity' do context 'with activity' do
...@@ -302,6 +364,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -302,6 +364,16 @@ RSpec.describe Nav::TopNavHelper do
) )
expect(subject[:primary]).to eq([expected_primary]) expect(subject[:primary]).to eq([expected_primary])
end end
it 'has expected :shortcuts' do
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
id: 'activity-shortcut',
title: 'Activity',
href: '/dashboard/activity',
css_class: 'dashboard-shortcuts-activity'
)
expect(subject[:shortcuts]).to eq([expected_shortcuts])
end
end end
context 'when sherlock is enabled' do context 'when sherlock is enabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment