Commit 76080438 authored by Kerri Miller's avatar Kerri Miller

Merge branch '329923-top-nav-active-project-and-group' into 'master'

Handle top nav active for project/group

See merge request gitlab-org/gitlab!63333
parents 6b6350ca 4cb7f2e5
...@@ -24,7 +24,7 @@ module Nav ...@@ -24,7 +24,7 @@ module Nav
if explore_nav_link?(:projects) if explore_nav_link?(:projects)
builder.add_primary_menu_item_with_shortcut( builder.add_primary_menu_item_with_shortcut(
href: explore_root_path, href: explore_root_path,
active: active_nav_link?(path: %w[dashboard#show root#show projects#trending projects#starred projects#index]), active: nav == 'project' || active_nav_link?(path: %w[dashboard#show root#show projects#trending projects#starred projects#index]),
**projects_menu_item_attrs **projects_menu_item_attrs
) )
end end
...@@ -32,7 +32,7 @@ module Nav ...@@ -32,7 +32,7 @@ module Nav
if explore_nav_link?(:groups) if explore_nav_link?(:groups)
builder.add_primary_menu_item_with_shortcut( builder.add_primary_menu_item_with_shortcut(
href: explore_groups_path, href: explore_groups_path,
active: active_nav_link?(controller: [:groups, 'groups/milestones', 'groups/group_members']), active: nav == 'group' || active_nav_link?(controller: [:groups, 'groups/milestones', 'groups/group_members']),
**groups_menu_item_attrs **groups_menu_item_attrs
) )
end end
...@@ -59,7 +59,7 @@ module Nav ...@@ -59,7 +59,7 @@ module Nav
current_item = project ? current_project(project: project) : {} current_item = project ? current_project(project: project) : {}
builder.add_primary_menu_item_with_shortcut( builder.add_primary_menu_item_with_shortcut(
active: active_nav_link?(path: %w[root#index projects#trending projects#starred dashboard/projects#index]), active: nav == 'project' || 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,
...@@ -73,7 +73,7 @@ module Nav ...@@ -73,7 +73,7 @@ module Nav
current_item = group ? current_group(group: group) : {} current_item = group ? current_group(group: group) : {}
builder.add_primary_menu_item_with_shortcut( builder.add_primary_menu_item_with_shortcut(
active: active_nav_link?(path: %w[dashboard/groups explore/groups]), active: nav == 'group' || 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,
......
...@@ -106,6 +106,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -106,6 +106,16 @@ RSpec.describe Nav::TopNavHelper do
] ]
expect(subject[:secondary]).to eq(expected_secondary) expect(subject[:secondary]).to eq(expected_secondary)
end end
context 'with current nav as project' do
before do
helper.nav('project')
end
it 'has expected :active' do
expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true)
end
end
end end
context 'when current_user is non-admin' do context 'when current_user is non-admin' do
...@@ -190,6 +200,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -190,6 +200,16 @@ RSpec.describe Nav::TopNavHelper do
expect(projects_view[:linksSecondary]).to eq(expected_links_secondary) expect(projects_view[:linksSecondary]).to eq(expected_links_secondary)
end end
context 'with current nav as project' do
before do
helper.nav('project')
end
it 'has expected :active' do
expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true)
end
end
context 'with persisted project' do context 'with persisted project' do
let_it_be(:project) { build_stubbed(:project) } let_it_be(:project) { build_stubbed(:project) }
...@@ -281,6 +301,16 @@ RSpec.describe Nav::TopNavHelper do ...@@ -281,6 +301,16 @@ RSpec.describe Nav::TopNavHelper do
expect(groups_view[:linksSecondary]).to eq(expected_links_secondary) expect(groups_view[:linksSecondary]).to eq(expected_links_secondary)
end end
context 'with current nav as group' do
before do
helper.nav('group')
end
it 'has expected :active' do
expect(subject[:primary].detect { |entry| entry[:id] == 'groups' }[:active]).to eq(true)
end
end
context 'with persisted group' do context 'with persisted group' do
let_it_be(:group) { build_stubbed(:group) } let_it_be(:group) { build_stubbed(:group) }
......
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