Commit 024ebc76 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '246813-fj-add-kubernetes-menu-fixing-error' into 'master'

Add Infrastucture menu to project sidebar

See merge request gitlab-org/gitlab!61033
parents 0b2d6f3f 460b4539
...@@ -11,6 +11,7 @@ RSpec.describe 'Project navbar' do ...@@ -11,6 +11,7 @@ RSpec.describe 'Project navbar' do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
before do before do
stub_feature_flags(sidebar_refactor: false)
insert_package_nav(_('Operations')) insert_package_nav(_('Operations'))
insert_infrastructure_registry_nav insert_infrastructure_registry_nav
stub_config(registry: { enabled: false }) stub_config(registry: { enabled: false })
...@@ -84,15 +85,13 @@ RSpec.describe 'Project navbar' do ...@@ -84,15 +85,13 @@ RSpec.describe 'Project navbar' do
stub_licensed_features(requirements: true) stub_licensed_features(requirements: true)
end end
context 'with flag enabled' do context 'with flag disabled' do
before do before do
stub_feature_flags(sidebar_refactor: true)
insert_after_nav_item( insert_after_nav_item(
_('Merge requests'), _('Merge requests'),
new_nav_item: { new_nav_item: {
nav_item: _('Requirements'), nav_item: _('Requirements'),
nav_sub_items: [] nav_sub_items: [_('List')]
} }
) )
...@@ -102,15 +101,41 @@ RSpec.describe 'Project navbar' do ...@@ -102,15 +101,41 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar' it_behaves_like 'verified navigation bar'
end end
context 'with flag disabled' do context 'with flag enabled' do
let(:operations_menu_items) do
[
_('Metrics'),
_('Logs'),
_('Tracing'),
_('Error Tracking'),
_('Alerts'),
_('Incidents'),
_('Environments'),
_('Feature Flags'),
_('Product Analytics')
]
end
before do before do
stub_feature_flags(sidebar_refactor: false) stub_feature_flags(sidebar_refactor: true)
insert_after_nav_item( insert_after_nav_item(
_('Merge requests'), _('Merge requests'),
new_nav_item: { new_nav_item: {
nav_item: _('Requirements'), nav_item: _('Requirements'),
nav_sub_items: [_('List')] nav_sub_items: []
}
)
insert_after_nav_item(
_('Operations'),
new_nav_item: {
nav_item: _('Infrastructure'),
nav_sub_items: [
_('Kubernetes clusters'),
_('Serverless platform'),
_('Terraform')
]
} }
) )
......
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class InfrastructureMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
return false if Feature.disabled?(:sidebar_refactor, context.current_user)
return false unless context.project.feature_available?(:operations, context.current_user)
add_item(kubernetes_menu_item)
add_item(serverless_menu_item)
add_item(terraform_menu_item)
true
end
override :link
def link
project_clusters_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-infrastructure'
}
end
override :title
def title
_('Infrastructure')
end
override :sprite_icon
def sprite_icon
'cloud-gear'
end
private
def kubernetes_menu_item
return unless can?(context.current_user, :read_cluster, context.project)
::Sidebars::MenuItem.new(
title: _('Kubernetes clusters'),
link: project_clusters_path(context.project),
active_routes: { controller: [:cluster_agents, :clusters] },
container_html_options: { class: 'shortcuts-kubernetes' },
hint_html_options: kubernetes_hint_html_options,
item_id: :kubernetes
)
end
def kubernetes_hint_html_options
return {} unless context.show_cluster_hint
{ disabled: true,
data: { trigger: 'manual',
container: 'body',
placement: 'right',
highlight: UserCalloutsHelper::GKE_CLUSTER_INTEGRATION,
highlight_priority: UserCallout.feature_names[:GKE_CLUSTER_INTEGRATION],
dismiss_endpoint: user_callouts_path,
auto_devops_help_path: help_page_path('topics/autodevops/index.md') } }
end
def serverless_menu_item
return unless can?(context.current_user, :read_cluster, context.project)
::Sidebars::MenuItem.new(
title: _('Serverless platform'),
link: project_serverless_functions_path(context.project),
active_routes: { controller: :functions },
item_id: :serverless
)
end
def terraform_menu_item
return unless can?(context.current_user, :read_terraform_state, context.project)
::Sidebars::MenuItem.new(
title: _('Terraform'),
link: project_terraform_index_path(context.project),
active_routes: { controller: :terraform },
item_id: :terraform
)
end
end
end
end
end
...@@ -47,7 +47,7 @@ module Sidebars ...@@ -47,7 +47,7 @@ module Sidebars
override :sprite_icon override :sprite_icon
def sprite_icon def sprite_icon
'cloud-gear' Feature.enabled?(:sidebar_refactor, context.current_user) ? 'monitor' : 'cloud-gear'
end end
override :active_routes override :active_routes
...@@ -127,6 +127,7 @@ module Sidebars ...@@ -127,6 +127,7 @@ module Sidebars
end end
def serverless_menu_item def serverless_menu_item
return if Feature.enabled?(:sidebar_refactor, context.current_user)
return unless can?(context.current_user, :read_cluster, context.project) return unless can?(context.current_user, :read_cluster, context.project)
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -138,6 +139,7 @@ module Sidebars ...@@ -138,6 +139,7 @@ module Sidebars
end end
def terraform_menu_item def terraform_menu_item
return if Feature.enabled?(:sidebar_refactor, context.current_user)
return unless can?(context.current_user, :read_terraform_state, context.project) return unless can?(context.current_user, :read_terraform_state, context.project)
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
...@@ -149,6 +151,7 @@ module Sidebars ...@@ -149,6 +151,7 @@ module Sidebars
end end
def kubernetes_menu_item def kubernetes_menu_item
return if Feature.enabled?(:sidebar_refactor, context.current_user)
return unless can?(context.current_user, :read_cluster, context.project) return unless can?(context.current_user, :read_cluster, context.project)
::Sidebars::MenuItem.new( ::Sidebars::MenuItem.new(
......
...@@ -17,6 +17,7 @@ module Sidebars ...@@ -17,6 +17,7 @@ module Sidebars
add_menu(Sidebars::Projects::Menus::CiCdMenu.new(context)) add_menu(Sidebars::Projects::Menus::CiCdMenu.new(context))
add_menu(Sidebars::Projects::Menus::SecurityComplianceMenu.new(context)) add_menu(Sidebars::Projects::Menus::SecurityComplianceMenu.new(context))
add_menu(Sidebars::Projects::Menus::OperationsMenu.new(context)) add_menu(Sidebars::Projects::Menus::OperationsMenu.new(context))
add_menu(Sidebars::Projects::Menus::InfrastructureMenu.new(context))
add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context)) add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context))
add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context)) add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context))
end end
......
...@@ -17341,6 +17341,9 @@ msgstr "" ...@@ -17341,6 +17341,9 @@ msgstr ""
msgid "Information about additional Pages templates and how to install them can be found in our %{pages_getting_started_guide}." msgid "Information about additional Pages templates and how to install them can be found in our %{pages_getting_started_guide}."
msgstr "" msgstr ""
msgid "Infrastructure"
msgstr ""
msgid "Infrastructure Registry" msgid "Infrastructure Registry"
msgstr "" msgstr ""
...@@ -18792,6 +18795,9 @@ msgstr "" ...@@ -18792,6 +18795,9 @@ msgstr ""
msgid "Kubernetes cluster was successfully updated." msgid "Kubernetes cluster was successfully updated."
msgstr "" msgstr ""
msgid "Kubernetes clusters"
msgstr ""
msgid "Kubernetes deployment not found" msgid "Kubernetes deployment not found"
msgstr "" msgstr ""
...@@ -29119,6 +29125,9 @@ msgstr "" ...@@ -29119,6 +29125,9 @@ msgstr ""
msgid "Serverless domain" msgid "Serverless domain"
msgstr "" msgstr ""
msgid "Serverless platform"
msgstr ""
msgid "ServerlessDetails|Function invocation metrics require Prometheus to be installed first." msgid "ServerlessDetails|Function invocation metrics require Prometheus to be installed first."
msgstr "" msgstr ""
......
...@@ -72,6 +72,20 @@ RSpec.describe 'Project navbar' do ...@@ -72,6 +72,20 @@ RSpec.describe 'Project navbar' do
end end
context 'when sidebar refactor feature flag is on' do context 'when sidebar refactor feature flag is on' do
let(:operations_menu_items) do
[
_('Metrics'),
_('Logs'),
_('Tracing'),
_('Error Tracking'),
_('Alerts'),
_('Incidents'),
_('Environments'),
_('Feature Flags'),
_('Product Analytics')
]
end
before do before do
stub_feature_flags(sidebar_refactor: true) stub_feature_flags(sidebar_refactor: true)
stub_config(registry: { enabled: true }) stub_config(registry: { enabled: true })
...@@ -84,6 +98,18 @@ RSpec.describe 'Project navbar' do ...@@ -84,6 +98,18 @@ RSpec.describe 'Project navbar' do
new_sub_nav_item_name: _('Packages & Registries') new_sub_nav_item_name: _('Packages & Registries')
) )
insert_after_nav_item(
_('Operations'),
new_nav_item: {
nav_item: _('Infrastructure'),
nav_sub_items: [
_('Kubernetes clusters'),
_('Serverless platform'),
_('Terraform')
]
}
)
visit project_path(project) visit project_path(project)
end end
......
...@@ -182,11 +182,25 @@ RSpec.describe 'User uses shortcuts', :js do ...@@ -182,11 +182,25 @@ RSpec.describe 'User uses shortcuts', :js do
expect(page).to have_active_sub_navigation('Environments') expect(page).to have_active_sub_navigation('Environments')
end end
context 'when feature flag :sidebar_refactor is disabled' do
it 'redirects to the Kubernetes page with active Operations' do
stub_feature_flags(sidebar_refactor: false)
find('body').native.send_key('g')
find('body').native.send_key('k')
expect(page).to have_active_navigation('Operations')
expect(page).to have_active_sub_navigation('Kubernetes')
end
end
end
context 'when navigating to the Infrastructure pages' do
it 'redirects to the Kubernetes page' do it 'redirects to the Kubernetes page' do
find('body').native.send_key('g') find('body').native.send_key('g')
find('body').native.send_key('k') find('body').native.send_key('k')
expect(page).to have_active_navigation('Operations') expect(page).to have_active_navigation('Infrastructure')
expect(page).to have_active_sub_navigation('Kubernetes') expect(page).to have_active_sub_navigation('Kubernetes')
end end
end end
......
...@@ -131,36 +131,66 @@ RSpec.describe Sidebars::Projects::Menus::OperationsMenu do ...@@ -131,36 +131,66 @@ RSpec.describe Sidebars::Projects::Menus::OperationsMenu do
describe 'Serverless' do describe 'Serverless' do
let(:item_id) { :serverless } let(:item_id) { :serverless }
specify { is_expected.not_to be_nil } context 'when feature flag :sidebar_refactor is enabled' do
specify { is_expected.to be_nil }
end
describe 'when the user does not have access' do context 'when feature flag :sidebar_refactor is disabled' do
let(:user) { nil } before do
stub_feature_flags(sidebar_refactor: false)
end
specify { is_expected.to be_nil } specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end end
end end
describe 'Terraform' do describe 'Terraform' do
let(:item_id) { :terraform } let(:item_id) { :terraform }
specify { is_expected.not_to be_nil } context 'when feature flag :sidebar_refactor is enabled' do
specify { is_expected.to be_nil }
end
describe 'when the user does not have access' do context 'when feature flag :sidebar_refactor is disabled' do
let(:user) { nil } before do
stub_feature_flags(sidebar_refactor: false)
end
specify { is_expected.to be_nil } specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end end
end end
describe 'Kubernetes' do describe 'Kubernetes' do
let(:item_id) { :kubernetes } let(:item_id) { :kubernetes }
specify { is_expected.not_to be_nil } context 'when feature flag :sidebar_refactor is enabled' do
specify { is_expected.to be_nil }
end
describe 'when the user does not have access' do context 'when feature flag :sidebar_refactor is disabled' do
let(:user) { nil } before do
stub_feature_flags(sidebar_refactor: false)
end
specify { is_expected.to be_nil } specify { is_expected.not_to be_nil }
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end end
end end
......
...@@ -24,6 +24,23 @@ RSpec.shared_context 'project navbar structure' do ...@@ -24,6 +24,23 @@ RSpec.shared_context 'project navbar structure' do
} }
end end
let(:operations_menu_items) do
[
_('Metrics'),
_('Logs'),
_('Tracing'),
_('Error Tracking'),
_('Alerts'),
_('Incidents'),
_('Serverless'),
_('Terraform'),
_('Kubernetes'),
_('Environments'),
_('Feature Flags'),
_('Product Analytics')
]
end
let(:structure) do let(:structure) do
[ [
{ {
...@@ -75,20 +92,7 @@ RSpec.shared_context 'project navbar structure' do ...@@ -75,20 +92,7 @@ RSpec.shared_context 'project navbar structure' do
security_and_compliance_nav_item, security_and_compliance_nav_item,
{ {
nav_item: _('Operations'), nav_item: _('Operations'),
nav_sub_items: [ nav_sub_items: operations_menu_items
_('Metrics'),
_('Logs'),
_('Tracing'),
_('Error Tracking'),
_('Alerts'),
_('Incidents'),
_('Serverless'),
_('Terraform'),
_('Kubernetes'),
_('Environments'),
_('Feature Flags'),
_('Product Analytics')
]
}, },
analytics_nav_item, analytics_nav_item,
{ {
......
...@@ -471,56 +471,71 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -471,56 +471,71 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'Serverless' do context 'when feature flag :sidebar_refactor is disabled' do
it 'has a link to the serverless page' do before do
render stub_feature_flags(sidebar_refactor: false)
expect(rendered).to have_link('Serverless', href: project_serverless_functions_path(project))
end end
describe 'when the user does not have access' do describe 'Serverless' do
let(:user) { nil } it 'has a link to the serverless page' do
it 'does not have a link to the serverless page' do
render render
expect(rendered).not_to have_link('Serverless') page = Nokogiri::HTML.parse(rendered)
expect(page.at_css('.shortcuts-operations').parent.css('[aria-label="Serverless"]')).not_to be_empty
expect(rendered).to have_link('Serverless', href: project_serverless_functions_path(project))
end end
end
end
describe 'Terraform' do describe 'when the user does not have access' do
it 'has a link to the terraform page' do let(:user) { nil }
render
expect(rendered).to have_link('Terraform', href: project_terraform_index_path(project)) it 'does not have a link to the serverless page' do
end render
describe 'when the user does not have access' do expect(rendered).not_to have_link('Serverless')
let(:user) { nil } end
end
end
it 'does not have a link to the terraform page' do describe 'Terraform' do
it 'has a link to the terraform page' do
render render
expect(rendered).not_to have_link('Terraform') page = Nokogiri::HTML.parse(rendered)
expect(page.at_css('.shortcuts-operations').parent.css('[aria-label="Terraform"]')).not_to be_empty
expect(rendered).to have_link('Terraform', href: project_terraform_index_path(project))
end end
end
end
describe 'Kubernetes' do describe 'when the user does not have access' do
it 'has a link to the kubernetes page' do let(:user) { nil }
render
expect(rendered).to have_link('Kubernetes', href: project_clusters_path(project)) it 'does not have a link to the terraform page' do
end render
describe 'when the user does not have access' do expect(rendered).not_to have_link('Terraform')
let(:user) { nil } end
end
end
it 'does not have a link to the kubernetes page' do describe 'Kubernetes' do
it 'has a link to the kubernetes page' do
render render
expect(rendered).not_to have_link('Kubernetes') page = Nokogiri::HTML.parse(rendered)
expect(page.at_css('.shortcuts-operations').parent.css('[aria-label="Kubernetes"]')).not_to be_empty
expect(rendered).to have_link('Kubernetes', href: project_clusters_path(project))
end
describe 'when the user does not have access' do
let(:user) { nil }
it 'does not have a link to the kubernetes page' do
render
expect(rendered).not_to have_link('Kubernetes')
end
end end
end end
end end
...@@ -580,6 +595,62 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -580,6 +595,62 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'Infrastructure' do
describe 'Serverless platform' do
it 'has a link to the serverless page' do
render
expect(rendered).to have_link('Serverless platform', href: project_serverless_functions_path(project))
end
describe 'when the user does not have access' do
let(:user) { nil }
it 'does not have a link to the serverless page' do
render
expect(rendered).not_to have_link('Serverless platform')
end
end
end
describe 'Terraform' do
it 'has a link to the terraform page' do
render
expect(rendered).to have_link('Terraform', href: project_terraform_index_path(project))
end
describe 'when the user does not have access' do
let(:user) { nil }
it 'does not have a link to the terraform page' do
render
expect(rendered).not_to have_link('Terraform')
end
end
end
describe 'Kubernetes clusters' do
it 'has a link to the kubernetes page' do
render
expect(rendered).to have_link('Kubernetes clusters', href: project_clusters_path(project))
end
describe 'when the user does not have access' do
let(:user) { nil }
it 'does not have a link to the kubernetes page' do
render
expect(rendered).not_to have_link('Kubernetes clusters')
end
end
end
end
describe 'Packages and Registries' do describe 'Packages and Registries' do
let(:registry_enabled) { true } let(:registry_enabled) { true }
let(:packages_enabled) { true } let(:packages_enabled) { true }
......
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