Move Labels menu item to project information menu

In this commit we move the menu item "Labels" from the Issues
menu and its own menu when the issues are disabled, to the
project information menu.

That way, we'll show always the labels menu no matter the status
of the issues feature.
parent 6330a060
......@@ -7,17 +7,26 @@ RSpec.describe 'Project navbar' do
include_context 'project navbar structure'
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:user) { project.owner }
before do
sign_in(user)
end
context 'when sidebar refactor feature flag is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav
stub_config(registry: { enabled: false })
project.add_maintainer(user)
sign_in(user)
insert_after_sub_nav_item(
_('Boards'),
within: _('Issues'),
new_sub_nav_item_name: _('Labels')
)
end
context 'when issue analytics is available' do
......@@ -62,7 +71,6 @@ RSpec.describe 'Project navbar' do
context 'when packages are available' do
before do
stub_config(packages: { enabled: true }, registry: { enabled: false })
stub_feature_flags(sidebar_refactor: false)
visit project_path(project)
end
......@@ -83,10 +91,6 @@ RSpec.describe 'Project navbar' do
context 'when requirements is available' do
before do
stub_licensed_features(requirements: true)
end
context 'with flag disabled' do
before do
insert_after_nav_item(
_('Merge requests'),
new_nav_item: {
......@@ -100,8 +104,9 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar'
end
end
context 'with flag enabled' do
context 'when sidebar refactor feature flag is enabled' do
let(:operations_menu_items) do
[
_('Metrics'),
......@@ -121,21 +126,16 @@ RSpec.describe 'Project navbar' do
nav_item: _('Project information'),
nav_sub_items: [
_('Activity'),
_('Releases')
_('Releases'),
_('Labels')
]
}
end
before do
stub_feature_flags(sidebar_refactor: true)
insert_after_nav_item(
_('Merge requests'),
new_nav_item: {
nav_item: _('Requirements'),
nav_sub_items: []
}
)
insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav
insert_after_nav_item(
_('Operations'),
......@@ -153,6 +153,23 @@ RSpec.describe 'Project navbar' do
end
it_behaves_like 'verified navigation bar'
context 'when requirements is available' do
before do
stub_licensed_features(requirements: true)
insert_after_nav_item(
_('Merge requests'),
new_nav_item: {
nav_item: _('Requirements'),
nav_sub_items: []
}
)
visit project_path(project)
end
it_behaves_like 'verified navigation bar'
end
end
end
......@@ -98,6 +98,10 @@ module Sidebars
end
def labels_menu_item
if Feature.enabled?(:sidebar_refactor, context.current_user)
return ::Sidebars::NilMenuItem.new(item_id: :labels)
end
::Sidebars::MenuItem.new(
title: _('Labels'),
link: project_labels_path(context.project),
......
......@@ -40,6 +40,8 @@ module Sidebars
override :render?
def render?
return false if Feature.enabled?(:sidebar_refactor, context.current_user)
can?(context.current_user, :read_label, context.project) && !context.project.issues_enabled?
end
end
......
......@@ -9,6 +9,7 @@ module Sidebars
add_item(details_menu_item)
add_item(activity_menu_item)
add_item(releases_menu_item)
add_item(labels_menu_item)
true
end
......@@ -95,6 +96,19 @@ module Sidebars
container_html_options: { class: 'shortcuts-project-releases' }
)
end
def labels_menu_item
if Feature.disabled?(:sidebar_refactor, context.current_user)
return ::Sidebars::NilMenuItem.new(item_id: :labels)
end
::Sidebars::MenuItem.new(
title: _('Labels'),
link: project_labels_path(context.project),
active_routes: { controller: :labels },
item_id: :labels
)
end
end
end
end
......
......@@ -69,12 +69,28 @@ RSpec.describe 'Project active tab' do
end
context 'on project Issues' do
let(:feature_flag_value) { true }
before do
stub_feature_flags(sidebar_refactor: feature_flag_value)
visit project_issues_path(project)
end
it_behaves_like 'page has active tab', 'Issues'
context "on project Issues/Milestones" do
before do
click_tab('Milestones')
end
it_behaves_like 'page has active tab', 'Issues'
it_behaves_like 'page has active sub tab', 'Milestones'
end
context 'when feature flag is disabled' do
let(:feature_flag_value) { false }
%w(Milestones Labels).each do |sub_menu|
context "on project Issues/#{sub_menu}" do
before do
......@@ -86,6 +102,7 @@ RSpec.describe 'Project active tab' do
end
end
end
end
context 'on project Merge Requests' do
before do
......
......@@ -54,12 +54,24 @@ RSpec.describe 'Edit Project Settings' do
end
context 'When external issue tracker is enabled and issues disabled on project settings' do
it 'hides issues tab and show labels tab' do
before do
project.issues_enabled = false
project.save!
allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new)
end
end
it 'hides issues tab' do
visit project_path(project)
expect(page).not_to have_selector('.shortcuts-issues')
expect(page).not_to have_selector('.shortcuts-labels')
end
context 'when feature flag :sidebar_refactor is disabled' do
it 'hides issues tab and show labels tab' do
stub_feature_flags(sidebar_refactor: false)
visit project_path(project)
......@@ -67,6 +79,7 @@ RSpec.describe 'Edit Project Settings' do
expect(page).to have_selector('.shortcuts-labels')
end
end
end
context "pipelines subtabs" do
it "shows builds when enabled" do
......
......@@ -8,17 +8,27 @@ RSpec.describe 'Project navbar' do
include_context 'project navbar structure'
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:user) { project.owner }
before do
sign_in(user)
end
context 'when sidebar refactor feature flag is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav
stub_config(registry: { enabled: false })
project.add_maintainer(user)
sign_in(user)
insert_after_sub_nav_item(
_('Boards'),
within: _('Issues'),
new_sub_nav_item_name: _('Labels')
)
stub_config(registry: { enabled: false })
end
it_behaves_like 'verified navigation bar' do
......@@ -70,8 +80,9 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar'
end
end
context 'when sidebar refactor feature flag is on' do
context 'when sidebar refactor feature flag is enabled' do
let(:operations_menu_items) do
[
_('Metrics'),
......@@ -91,7 +102,8 @@ RSpec.describe 'Project navbar' do
nav_item: _('Project information'),
nav_sub_items: [
_('Activity'),
_('Releases')
_('Releases'),
_('Labels')
]
}
end
......@@ -99,7 +111,8 @@ RSpec.describe 'Project navbar' do
before do
stub_feature_flags(sidebar_refactor: true)
stub_config(registry: { enabled: true })
insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav
insert_container_nav
insert_after_sub_nav_item(
......
......@@ -65,4 +65,22 @@ RSpec.describe Sidebars::Projects::Menus::IssuesMenu do
end
end
end
describe 'Menu Items' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }
describe 'Labels' do
let(:item_id) { :labels }
specify { is_expected.to be_nil }
context 'when feature flag :sidebar_refactor is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
end
specify { is_expected.not_to be_nil }
end
end
end
end
......@@ -20,6 +20,19 @@ RSpec.describe Sidebars::Projects::Menus::LabelsMenu do
allow(project).to receive(:issues_enabled?).and_return(issues_enabled)
end
context 'when feature flag :sidebar_refactor is enabled' do
let(:issues_enabled) { false }
it 'returns false' do
expect(subject.render?).to be_falsey
end
end
context 'when feature flag :sidebar_refactor is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
end
context 'when user can read labels' do
context 'when issues feature is enabled' do
it 'returns false' do
......@@ -44,4 +57,5 @@ RSpec.describe Sidebars::Projects::Menus::LabelsMenu do
end
end
end
end
end
......@@ -8,8 +8,11 @@ RSpec.describe Sidebars::Projects::Menus::ProjectInformationMenu do
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
describe 'Menu Items' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }
describe 'Releases' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == :releases } }
let(:item_id) { :releases }
context 'when project repository is empty' do
it 'does not include releases menu item' do
......@@ -35,4 +38,19 @@ RSpec.describe Sidebars::Projects::Menus::ProjectInformationMenu do
end
end
end
describe 'Labels' do
let(:item_id) { :labels }
specify { is_expected.not_to be_nil }
context 'when feature flag :sidebar_refactor is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
end
specify { is_expected.to be_nil }
end
end
end
end
......@@ -73,7 +73,6 @@ RSpec.shared_context 'project navbar structure' do
nav_sub_items: [
_('List'),
_('Boards'),
_('Labels'),
_('Service Desk'),
_('Milestones'),
(_('Iterations') if Gitlab.ee?)
......
......@@ -72,6 +72,27 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
expect(rendered).to have_link('Releases', href: project_releases_path(project), class: 'shortcuts-project-releases')
end
end
describe 'Labels' do
let(:page) { Nokogiri::HTML.parse(rendered) }
it 'has a link to the labels path' do
render
expect(page.at_css('.shortcuts-project').parent.css('[aria-label="Labels"]')).not_to be_empty
expect(rendered).to have_link('Labels', href: project_labels_path(project))
end
context 'when feature flag :sidebar_refactor is disabled' do
it 'does not have the labels menu item' do
stub_feature_flags(sidebar_refactor: false)
render
expect(page.at_css('.shortcuts-project').parent.css('[aria-label="Labels"]')).to be_empty
end
end
end
end
describe 'Learn GitLab' do
......@@ -181,12 +202,25 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
describe 'Labels' do
it 'has a link to the labels path' do
let(:page) { Nokogiri::HTML.parse(rendered) }
it 'does not have a link to the labels page' do
render
expect(page.at_css('.shortcuts-issues').parent.css('[aria-label="Labels"]')).to be_empty
end
context 'when feature flag :sidebar_refactor is disabled' do
it 'has a link to the labels page' do
stub_feature_flags(sidebar_refactor: false)
render
expect(page.at_css('.shortcuts-issues').parent.css('[aria-label="Labels"]')).not_to be_empty
expect(rendered).to have_link('Labels', href: project_labels_path(project))
end
end
end
describe 'Service Desk' do
it 'has a link to the service desk path' do
......@@ -248,6 +282,19 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
describe 'Labels' do
it 'does not show the labels menu' do
project.project_feature.update!(issues_access_level: ProjectFeature::DISABLED)
render
expect(rendered).not_to have_link('Labels', href: project_labels_path(project), class: 'shortcuts-labels')
end
context 'when feature flag :sidebar_refactor is disabled' do
before do
stub_feature_flags(sidebar_refactor: false)
end
context 'when issues are not enabled' do
it 'has a link to the labels path' do
project.project_feature.update!(issues_access_level: ProjectFeature::DISABLED)
......@@ -266,6 +313,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
end
end
end
describe 'Merge Requests' do
it 'has a link to the merge request list path' 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