diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /lib/sidebars | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'lib/sidebars')
-rw-r--r-- | lib/sidebars/concerns/container_with_html_options.rb | 10 | ||||
-rw-r--r-- | lib/sidebars/menu.rb | 10 | ||||
-rw-r--r-- | lib/sidebars/menu_item.rb | 8 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/infrastructure_menu.rb | 2 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/issues_menu.rb | 2 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/labels_menu.rb | 2 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/learn_gitlab_menu.rb | 9 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/monitor_menu.rb | 6 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/packages_registries_menu.rb | 2 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/project_information_menu.rb | 29 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/scope_menu.rb | 26 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/security_compliance_menu.rb | 22 | ||||
-rw-r--r-- | lib/sidebars/projects/menus/settings_menu.rb | 2 |
13 files changed, 88 insertions, 42 deletions
diff --git a/lib/sidebars/concerns/container_with_html_options.rb b/lib/sidebars/concerns/container_with_html_options.rb index 873cb5b0de9..79dddd309b5 100644 --- a/lib/sidebars/concerns/container_with_html_options.rb +++ b/lib/sidebars/concerns/container_with_html_options.rb @@ -38,6 +38,16 @@ module Sidebars # in the helper method that sets the active class # on each element. def nav_link_html_options + { + data: { + track_label: self.class.name.demodulize.underscore + } + }.deep_merge(extra_nav_link_html_options) + end + + # Classes should mostly override this method + # and not `nav_link_html_options`. + def extra_nav_link_html_options {} end diff --git a/lib/sidebars/menu.rb b/lib/sidebars/menu.rb index d81e413f4a9..dcdc130b0d7 100644 --- a/lib/sidebars/menu.rb +++ b/lib/sidebars/menu.rb @@ -83,6 +83,16 @@ module Sidebars insert_element_after(@items, after_item, new_item) end + override :container_html_options + def container_html_options + super.tap do |html_options| + # Flagging menus that can be rendered and with renderable menu items + if render? && has_renderable_items? + html_options[:class] = [*html_options[:class], 'has-sub-items'].join(' ') + end + end + end + private override :index_of diff --git a/lib/sidebars/menu_item.rb b/lib/sidebars/menu_item.rb index b0a12e769dc..1375f9fffca 100644 --- a/lib/sidebars/menu_item.rb +++ b/lib/sidebars/menu_item.rb @@ -22,5 +22,13 @@ module Sidebars def render? true end + + def nav_link_html_options + { + data: { + track_label: item_id + } + } + end end end diff --git a/lib/sidebars/projects/menus/infrastructure_menu.rb b/lib/sidebars/projects/menus/infrastructure_menu.rb index 75b6cae295f..8cf7abc613c 100644 --- a/lib/sidebars/projects/menus/infrastructure_menu.rb +++ b/lib/sidebars/projects/menus/infrastructure_menu.rb @@ -6,7 +6,7 @@ module Sidebars class InfrastructureMenu < ::Sidebars::Menu override :configure_menu_items def configure_menu_items - return false if Feature.disabled?(:sidebar_refactor, context.current_user) + return false if Feature.disabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) return false unless context.project.feature_available?(:operations, context.current_user) add_item(kubernetes_menu_item) diff --git a/lib/sidebars/projects/menus/issues_menu.rb b/lib/sidebars/projects/menus/issues_menu.rb index 9840f644179..79603803b8f 100644 --- a/lib/sidebars/projects/menus/issues_menu.rb +++ b/lib/sidebars/projects/menus/issues_menu.rb @@ -98,7 +98,7 @@ module Sidebars end def labels_menu_item - if Feature.enabled?(:sidebar_refactor, context.current_user) + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) return ::Sidebars::NilMenuItem.new(item_id: :labels) end diff --git a/lib/sidebars/projects/menus/labels_menu.rb b/lib/sidebars/projects/menus/labels_menu.rb index 12cf0444994..7cb28ababdb 100644 --- a/lib/sidebars/projects/menus/labels_menu.rb +++ b/lib/sidebars/projects/menus/labels_menu.rb @@ -40,7 +40,7 @@ module Sidebars override :render? def render? - return false if Feature.enabled?(:sidebar_refactor, context.current_user) + return false if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) can?(context.current_user, :read_label, context.project) && !context.project.issues_enabled? end diff --git a/lib/sidebars/projects/menus/learn_gitlab_menu.rb b/lib/sidebars/projects/menus/learn_gitlab_menu.rb index e3fcd8f25d5..f29f4a6eed6 100644 --- a/lib/sidebars/projects/menus/learn_gitlab_menu.rb +++ b/lib/sidebars/projects/menus/learn_gitlab_menu.rb @@ -35,14 +35,13 @@ module Sidebars end end - override :extra_container_html_options - def nav_link_html_options + override :extra_nav_link_html_options + def extra_nav_link_html_options { class: 'home', data: { - track_action: 'click_menu', - track_property: context.learn_gitlab_experiment_tracking_category, - track_label: 'learn_gitlab' + track_label: 'learn_gitlab', + track_property: context.learn_gitlab_experiment_tracking_category } } end diff --git a/lib/sidebars/projects/menus/monitor_menu.rb b/lib/sidebars/projects/menus/monitor_menu.rb index 18c990d0e1f..8ebdacc7c7e 100644 --- a/lib/sidebars/projects/menus/monitor_menu.rb +++ b/lib/sidebars/projects/menus/monitor_menu.rb @@ -139,7 +139,7 @@ module Sidebars end def serverless_menu_item - if Feature.enabled?(:sidebar_refactor, context.current_user) || + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) || !can?(context.current_user, :read_cluster, context.project) return ::Sidebars::NilMenuItem.new(item_id: :serverless) end @@ -153,7 +153,7 @@ module Sidebars end def terraform_menu_item - if Feature.enabled?(:sidebar_refactor, context.current_user) || + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) || !can?(context.current_user, :read_terraform_state, context.project) return ::Sidebars::NilMenuItem.new(item_id: :terraform) end @@ -167,7 +167,7 @@ module Sidebars end def kubernetes_menu_item - if Feature.enabled?(:sidebar_refactor, context.current_user) || + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) || !can?(context.current_user, :read_cluster, context.project) return ::Sidebars::NilMenuItem.new(item_id: :kubernetes) end diff --git a/lib/sidebars/projects/menus/packages_registries_menu.rb b/lib/sidebars/projects/menus/packages_registries_menu.rb index 7087916bb04..27e318d73c5 100644 --- a/lib/sidebars/projects/menus/packages_registries_menu.rb +++ b/lib/sidebars/projects/menus/packages_registries_menu.rb @@ -58,7 +58,7 @@ module Sidebars end def infrastructure_registry_menu_item - if Feature.disabled?(:infrastructure_registry_page, context.current_user) + if Feature.disabled?(:infrastructure_registry_page, context.current_user, default_enabled: :yaml) return ::Sidebars::NilMenuItem.new(item_id: :infrastructure_registry) end diff --git a/lib/sidebars/projects/menus/project_information_menu.rb b/lib/sidebars/projects/menus/project_information_menu.rb index cbb34714087..c148e7cf931 100644 --- a/lib/sidebars/projects/menus/project_information_menu.rb +++ b/lib/sidebars/projects/menus/project_information_menu.rb @@ -17,24 +17,26 @@ module Sidebars override :link def link - project_path(context.project) + renderable_items.first.link end override :extra_container_html_options def extra_container_html_options - { - class: 'shortcuts-project rspec-project-link' - } + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) + { class: 'shortcuts-project-information' } + else + { class: 'shortcuts-project rspec-project-link' } + end end - override :nav_link_html_options - def nav_link_html_options + override :extra_nav_link_html_options + def extra_nav_link_html_options { class: 'home' } end override :title def title - if Feature.enabled?(:sidebar_refactor, context.current_user) + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) _('Project information') else _('Project overview') @@ -43,24 +45,17 @@ module Sidebars override :sprite_icon def sprite_icon - if Feature.enabled?(:sidebar_refactor, context.current_user) + if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) 'project' else 'home' end end - override :active_routes - def active_routes - return {} if Feature.disabled?(:sidebar_refactor, context.current_user) - - { path: 'projects#show' } - end - private def details_menu_item - return if Feature.enabled?(:sidebar_refactor, context.current_user) + return if Feature.enabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) ::Sidebars::MenuItem.new( title: _('Details'), @@ -103,7 +98,7 @@ module Sidebars end def labels_menu_item - if Feature.disabled?(:sidebar_refactor, context.current_user) + if Feature.disabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) return ::Sidebars::NilMenuItem.new(item_id: :labels) end diff --git a/lib/sidebars/projects/menus/scope_menu.rb b/lib/sidebars/projects/menus/scope_menu.rb index 1d1cf11b271..1cd0218d4ac 100644 --- a/lib/sidebars/projects/menus/scope_menu.rb +++ b/lib/sidebars/projects/menus/scope_menu.rb @@ -13,6 +13,32 @@ module Sidebars def title context.project.name end + + override :active_routes + def active_routes + { path: 'projects#show' } + end + + override :extra_container_html_options + def extra_container_html_options + return {} if Feature.disabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) + + { + class: 'shortcuts-project rspec-project-link' + } + end + + override :extra_nav_link_html_options + def extra_nav_link_html_options + return {} if Feature.disabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) + + { class: 'context-header' } + end + + override :render? + def render? + true + end end end end diff --git a/lib/sidebars/projects/menus/security_compliance_menu.rb b/lib/sidebars/projects/menus/security_compliance_menu.rb index 6c9fb8312bd..5616b466560 100644 --- a/lib/sidebars/projects/menus/security_compliance_menu.rb +++ b/lib/sidebars/projects/menus/security_compliance_menu.rb @@ -17,7 +17,7 @@ module Sidebars override :link def link - project_security_configuration_path(context.project) + renderable_items.first&.link end override :title @@ -33,18 +33,16 @@ module Sidebars private def configuration_menu_item - strong_memoize(:configuration_menu_item) do - unless render_configuration_menu_item? - next ::Sidebars::NilMenuItem.new(item_id: :configuration) - end - - ::Sidebars::MenuItem.new( - title: _('Configuration'), - link: project_security_configuration_path(context.project), - active_routes: { path: configuration_menu_item_paths }, - item_id: :configuration - ) + unless render_configuration_menu_item? + return ::Sidebars::NilMenuItem.new(item_id: :configuration) end + + ::Sidebars::MenuItem.new( + title: _('Configuration'), + link: project_security_configuration_path(context.project), + active_routes: { path: configuration_menu_item_paths }, + item_id: :configuration + ) end def render_configuration_menu_item? diff --git a/lib/sidebars/projects/menus/settings_menu.rb b/lib/sidebars/projects/menus/settings_menu.rb index 4ea6f5e298a..c9d7e736b21 100644 --- a/lib/sidebars/projects/menus/settings_menu.rb +++ b/lib/sidebars/projects/menus/settings_menu.rb @@ -136,7 +136,7 @@ module Sidebars def packages_and_registries_menu_item if !Gitlab.config.registry.enabled || - Feature.disabled?(:sidebar_refactor, context.current_user) || + Feature.disabled?(:sidebar_refactor, context.current_user, default_enabled: :yaml) || !can?(context.current_user, :destroy_container_image, context.project) return ::Sidebars::NilMenuItem.new(item_id: :packages_and_registries) end |