Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Replace some more tabNavs with the new standardized helper

Henriette Dargec5f6b2b01ab3
diff --git a/app/components/admin/attachments_settings_header_component.html.erb b/app/components/admin/attachments_settings_header_component.html.erb
index 65260b6688a..368a700fdd4 100644
--- a/app/components/admin/attachments_settings_header_component.html.erb
+++ b/app/components/admin/attachments_settings_header_component.html.erb
@@ -36,18 +36,6 @@ See COPYRIGHT and LICENSE files for more details.
{ href: admin_settings_storages_path, text: t("project_module_storages") },
t(:"attributes.attachments")]
)
- header.with_tab_nav(label: nil) do |tab_nav|
- tab_nav.with_tab(selected: @selected == 1, href: admin_settings_attachments_path) do |tab|
- tab.with_text { t("settings.general") }
- end
- tab_nav.with_tab(selected: @selected == 2, href: admin_settings_virus_scanning_path) do |tab|
- tab.with_icon(icon: :"op-enterprise-addons") unless EnterpriseToken.allows_to?("virus_scanning")
- tab.with_text { t(:"settings.antivirus.title") }
- end
- if User.current.admin? && (EnterpriseToken.allows_to?(:virus_scanning) || Attachment.status_quarantined.any?)
- tab_nav.with_tab(selected: @selected == 3, href: admin_quarantined_attachments_path) do |tab|
- tab.with_text { t(:"antivirus_scan.quarantined_attachments.title") }
- end
- end
- end
+
+ helpers.render_tab_header_nav(header, tabs)
end %>
diff --git a/app/components/admin/attachments_settings_header_component.rb b/app/components/admin/attachments_settings_header_component.rb
index af967d00555..5b9dcf659d5 100644
--- a/app/components/admin/attachments_settings_header_component.rb
+++ b/app/components/admin/attachments_settings_header_component.rb
@@ -36,5 +36,31 @@ module Admin
@title = title
@selected = selected
end
+
+ def tabs
+ tabs = [
+ {
+ name: "general",
+ path: admin_settings_attachments_path,
+ label: t("settings.general")
+ },
+ {
+ name: "virus",
+ path: admin_settings_virus_scanning_path,
+ label: t(:"settings.antivirus.title"),
+ enterprise_feature: :virus_scanning
+ }
+ ]
+
+ if User.current.admin? && (EnterpriseToken.allows_to?(:virus_scanning) || Attachment.status_quarantined.any?)
+ tabs << {
+ name: "quarantined",
+ path: admin_quarantined_attachments_path,
+ label: t(:"antivirus_scan.quarantined_attachments.title")
+ }
+ end
+
+ tabs
+ end
end
end
diff --git a/app/components/admin/custom_fields/edit_form_header_component.html.erb b/app/components/admin/custom_fields/edit_form_header_component.html.erb
index f3853f41a7a..3a87af24a09 100644
--- a/app/components/admin/custom_fields/edit_form_header_component.html.erb
+++ b/app/components/admin/custom_fields/edit_form_header_component.html.erb
@@ -33,29 +33,6 @@ See COPYRIGHT and LICENSE files for more details.
header.with_breadcrumbs(breadcrumbs_items)
- header.with_tab_nav(label: nil, test_selector: :custom_field_detail_header) do |tab_nav|
- tab_nav.with_tab(
- selected: tab_selected?(:edit),
- href: edit_custom_field_path(@custom_field)
- ) do |tab|
- tab.with_text { t(:label_details) }
- end
-
- if @custom_field.field_format_hierarchy?
- tab_nav.with_tab(
- selected: tab_selected?(:items),
- href: custom_field_items_path(@custom_field)
- ) do |tab|
- tab.with_text { t(:label_item_plural) }
- end
- end
-
- tab_nav.with_tab(
- selected: tab_selected?(:custom_field_projects),
- href: custom_field_projects_path(@custom_field)
- ) do |tab|
- tab.with_text { t(:label_project_plural) }
- end
- end
+ helpers.render_tab_header_nav(header, tabs, test_selector: :custom_field_detail_header)
end
%>
diff --git a/app/components/admin/custom_fields/edit_form_header_component.rb b/app/components/admin/custom_fields/edit_form_header_component.rb
index 9882900223f..8a21e586e20 100644
--- a/app/components/admin/custom_fields/edit_form_header_component.rb
+++ b/app/components/admin/custom_fields/edit_form_header_component.rb
@@ -29,20 +29,30 @@
module Admin
module CustomFields
class EditFormHeaderComponent < ApplicationComponent
- TAB_NAVS = %i[
- edit
- items
- custom_field_projects
- ].freeze
-
def initialize(custom_field:, selected:, **)
@custom_field = custom_field
@selected = selected
super(custom_field, **)
end
- def tab_selected?(tab_name)
- TAB_NAVS.include?(tab_name) && tab_name == @selected
+ def tabs
+ [
+ {
+ name: "edit",
+ path: edit_custom_field_path(@custom_field),
+ label: t(:label_details)
+ },
+ {
+ name: "items",
+ path: custom_field_items_path(@custom_field),
+ label: t(:label_item_plural)
+ },
+ {
+ name: "custom_field_projects",
+ path: custom_field_projects_path(@custom_field),
+ label: t(:label_project_plural)
+ }
+ ]
end
private
diff --git a/app/components/custom_fields/index_page_header_component.html.erb b/app/components/custom_fields/index_page_header_component.html.erb
index d865ec68f3f..f1e79de078b 100644
--- a/app/components/custom_fields/index_page_header_component.html.erb
+++ b/app/components/custom_fields/index_page_header_component.html.erb
@@ -31,14 +31,6 @@ See COPYRIGHT and LICENSE files for more details.
header.with_title { I18n.t(:label_custom_field_plural) }
header.with_breadcrumbs(breadcrumb_items, selected_item_font_weight: :normal)
- if @tabs.present?
- header.with_tab_nav(label: nil, test_selector: "custom-fields--tab-nav") do |tab_nav|
- @tabs.each do |tab|
- tab_nav.with_tab(selected: currently_selected_tab == tab, href: tab[:path]) do |t|
- t.with_text { I18n.t(tab[:label]) }
- end
- end
- end
- end
+ helpers.render_tab_header_nav(header, @tabs, test_selector: "custom-fields--tab-nav")
end
%>
diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb
index edabf49a877..7beb0f81f48 100644
--- a/app/helpers/tabs_helper.rb
+++ b/app/helpers/tabs_helper.rb
@@ -39,10 +39,10 @@ module TabsHelper
end
end
- def render_tab_header_nav(header, tabs)
+ def render_tab_header_nav(header, tabs, test_selector: nil)
return if tabs.blank?
- header.with_tab_nav(label: nil) do |tab_nav|
+ header.with_tab_nav(label: nil, test_selector:) do |tab_nav|
tabs.each do |tab|
tab_nav.with_tab(selected: selected_tab(tabs) == tab, href: tab[:path]) do |t|
feature = tab[:enterprise_feature]
diff --git a/modules/storages/app/components/storages/admin/edit_form_header_component.html.erb b/modules/storages/app/components/storages/admin/edit_form_header_component.html.erb
index c76f2b752ab..a45af3e0aae 100644
--- a/modules/storages/app/components/storages/admin/edit_form_header_component.html.erb
+++ b/modules/storages/app/components/storages/admin/edit_form_header_component.html.erb
@@ -54,20 +54,7 @@ See COPYRIGHT and LICENSE files for more details.
I18n.t("button_delete")
end
- header.with_tab_nav(label: nil, test_selector: :storage_detail_header) do |tab_nav|
- tab_nav.with_tab(
- selected: tab_selected?(:edit),
- href: edit_admin_settings_storage_path(@storage)
- ) do |tab|
- tab.with_text { t(:label_details) }
- end
- tab_nav.with_tab(
- selected: tab_selected?(:project_storages),
- href: admin_settings_storage_project_storages_path(@storage)
- ) do |tab|
- tab.with_text { t(:label_project_mappings) }
- end
- end
+ helpers.render_tab_header_nav(header, tabs, test_selector: :storage_detail_header)
end
%>
<% end %>
diff --git a/modules/storages/app/components/storages/admin/edit_form_header_component.rb b/modules/storages/app/components/storages/admin/edit_form_header_component.rb
index b6a43654c34..c2a54d9bed7 100644
--- a/modules/storages/app/components/storages/admin/edit_form_header_component.rb
+++ b/modules/storages/app/components/storages/admin/edit_form_header_component.rb
@@ -31,22 +31,12 @@
module Storages
module Admin
class EditFormHeaderComponent < ApplicationComponent
- TAB_NAVS = %i[
- edit
- project_storages
- ].freeze
-
def initialize(storage:, selected:)
super
@storage = storage
@selected = selected
end
- def tab_selected?(tab_name)
- TAB_NAVS.include?(tab_name) &&
- tab_name == @selected
- end
-
def label_storage_name_with_provider_label
"#{h(@storage.name)} #{label_storage_provider_part}".html_safe # rubocop:disable Rails/OutputSafety
end
@@ -62,6 +52,21 @@ module Storages
{ href: admin_settings_storages_path, text: t("project_module_storages") },
@storage.name]
end
+
+ def tabs
+ [
+ {
+ name: "edit",
+ path: edit_admin_settings_storage_path(@storage),
+ label: t(:label_details)
+ },
+ {
+ name: "project_storages",
+ path: admin_settings_storage_project_storages_path(@storage),
+ label: t(:label_project_mappings)
+ }
+ ]
+ end
end
end
end