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 last occurenes of tabNav with new helper

Henriette Darge5b6f02c69053
diff --git a/app/components/settings/project_custom_fields/edit_form_header_component.html.erb b/app/components/settings/project_custom_fields/edit_form_header_component.html.erb
index a8b6ed3bf0a..22ff5ee0bf1 100644
--- a/app/components/settings/project_custom_fields/edit_form_header_component.html.erb
+++ b/app/components/settings/project_custom_fields/edit_form_header_component.html.erb
@@ -31,20 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
header.with_title { @custom_field.name }
header.with_description { t("settings.project_attributes.edit.description") }
header.with_breadcrumbs(breadcrumbs_items)
- header.with_tab_nav(label: nil, test_selector: :project_attribute_detail_header) do |tab_nav|
- tab_nav.with_tab(
- selected: project_custom_field_edit_selected?,
- href: edit_admin_settings_project_custom_field_path(@custom_field)
- ) do |tab|
- tab.with_text { t(:label_details) }
- end
-
- tab_nav.with_tab(
- selected: project_custom_field_project_mappings_selected?,
- href: project_mappings_admin_settings_project_custom_field_path(@custom_field)
- ) do |tab|
- tab.with_text { t(:label_project_mappings) }
- end
- end
+
+ helpers.render_tab_header_nav(header, tabs, test_selector: :project_attribute_detail_header)
end
%>
diff --git a/app/components/settings/project_custom_fields/edit_form_header_component.rb b/app/components/settings/project_custom_fields/edit_form_header_component.rb
index 451b9f55e8c..461f0a75b0a 100644
--- a/app/components/settings/project_custom_fields/edit_form_header_component.rb
+++ b/app/components/settings/project_custom_fields/edit_form_header_component.rb
@@ -29,11 +29,6 @@
module Settings
module ProjectCustomFields
class EditFormHeaderComponent < ApplicationComponent
- TAB_NAVS = %i[
- project_custom_field_edit
- project_custom_field_project_mappings
- ].freeze
-
def initialize(custom_field:, selected:)
selected = selected.to_sym
raise "selected must be one of the following: #{TAB_NAVS.join(', ')}" unless TAB_NAVS.include?(selected)
@@ -43,10 +38,19 @@ module Settings
@selected = selected
end
- TAB_NAVS.each do |tab_nav|
- define_method(:"#{tab_nav}_selected?") do
- @selected == tab_nav
- end
+ def tabs
+ [
+ {
+ name: "project_custom_field_edit",
+ path: edit_admin_settings_project_custom_field_path(@custom_field),
+ label: t(:label_details)
+ },
+ {
+ name: "project_custom_field_project_mappings",
+ path: project_mappings_admin_settings_project_custom_field_path(@custom_field),
+ label: t(:label_project_mappings)
+ }
+ ]
end
def breadcrumbs_items
diff --git a/app/components/settings/project_work_packages/header_component.html.erb b/app/components/settings/project_work_packages/header_component.html.erb
index 00c0c904694..78515b9b559 100644
--- a/app/components/settings/project_work_packages/header_component.html.erb
+++ b/app/components/settings/project_work_packages/header_component.html.erb
@@ -30,25 +30,7 @@ See COPYRIGHT and LICENSE files for more details.
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t(:label_work_package_plural) }
header.with_breadcrumbs(breadcrumbs_items)
- header.with_tab_nav(label: nil) do |tab_nav|
- if show_types?
- tab_nav.with_tab(selected: selected?(:types), href: project_settings_work_packages_types_path) do |tab|
- tab.with_text { t("label_type_plural") }
- end
- end
- if show_categories?
- tab_nav.with_tab(selected: selected?(:categories), href: project_settings_work_packages_categories_path) do |tab|
- tab.with_text { t("documents.label_categories") }
- end
- end
- if show_custom_fields?
- tab_nav.with_tab(selected: selected?(:custom_fields), href: project_settings_work_packages_custom_fields_path) do |tab|
- tab.with_text { t("attributes.custom_values") }
- end
- end
- tab_nav.with_tab(selected: selected?(:internal_coments), href: project_settings_work_packages_internal_comments_path) do |tab|
- tab.with_text { internal_comments_title }
- end
- end
+
+ helpers.render_tab_header_nav(header, tabs)
end
%>
diff --git a/app/components/settings/project_work_packages/header_component.rb b/app/components/settings/project_work_packages/header_component.rb
index 11a89cff62f..3c2b2ccfdbf 100644
--- a/app/components/settings/project_work_packages/header_component.rb
+++ b/app/components/settings/project_work_packages/header_component.rb
@@ -43,10 +43,6 @@ module Settings
t(:label_work_package_plural)]
end
- def selected?(key)
- @selected == key
- end
-
def show_types?
User.current.allowed_in_project?(:manage_types, @project)
end
@@ -71,6 +67,42 @@ module Settings
internal_comments_translation
end
+ def tabs
+ tabs = []
+
+ if show_types?
+ tabs << {
+ name: "types",
+ path: project_settings_work_packages_types_path,
+ label: t("label_type_plural")
+ }
+ end
+
+ if show_categories?
+ tabs << {
+ name: "categories",
+ path: project_settings_work_packages_categories_path,
+ label: t("documents.label_categories")
+ }
+ end
+
+ if show_custom_fields?
+ tabs << {
+ name: "custom_fields",
+ path: project_settings_work_packages_custom_fields_path,
+ label: t("attributes.custom_values")
+ }
+ end
+
+ tabs << {
+ name: "internal_comments",
+ path: project_settings_work_packages_internal_comments_path,
+ label: internal_comments_title
+ }
+
+ tabs
+ end
+
private
def internal_comments_translation = t("ee.features.internal_comments").html_safe
diff --git a/lookbook/docs/components/page-header.md.erb b/lookbook/docs/components/page-header.md.erb
index 1464029eebb..a3614304ab8 100644
--- a/lookbook/docs/components/page-header.md.erb
+++ b/lookbook/docs/components/page-header.md.erb
@@ -105,6 +105,22 @@ class ModuleA::IndexPageHeaderComponent < ApplicationComponent
"Bar"]
end
+ def tabs
+ [
+ {
+ name: "id1",
+ path: "example_path",
+ label: "Tab 1"
+ },
+ {
+ name: "id2",
+ path: "another_example_path",
+ label: "Tab 1",
+ enterprise_feature: :some_key
+ }
+ ]
+ end
+
def additional_logic
# ...
end
@@ -120,6 +136,8 @@ end
header.with_title { 'Some title' }
header.with_breadcrumbs(breadcrumb_items)
+ helpers.render_tab_header_nav(header, tabs)
+
#... additional logic
end
%&gt;
diff --git a/modules/storages/app/components/storages/project_storages/header_component.html.erb b/modules/storages/app/components/storages/project_storages/header_component.html.erb
new file mode 100644
index 00000000000..298f7e4f66d
--- /dev/null
+++ b/modules/storages/app/components/storages/project_storages/header_component.html.erb
@@ -0,0 +1,51 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { t("project_module_storages") }
+ header.with_breadcrumbs(breadcrumbs_items)
+
+ header.with_action_button(
+ tag: :a,
+ href: new_project_settings_project_storage_path,
+ scheme: :primary,
+ mobile_icon: :plus,
+ mobile_label: t(:"storages.label_storage"),
+ size: :medium,
+ aria: { label: t(:"storages.label_new_storage") },
+ title: t(:"storages.label_new_storage")
+ ) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t(:"storages.label_storage")
+ end
+
+ helpers.render_tab_header_nav(header, tabs)
+ end
+%>
diff --git a/modules/storages/app/components/storages/project_storages/header_component.rb b/modules/storages/app/components/storages/project_storages/header_component.rb
new file mode 100644
index 00000000000..51516be0aa2
--- /dev/null
+++ b/modules/storages/app/components/storages/project_storages/header_component.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Storages
+ module ProjectStorages
+ class HeaderComponent < ApplicationComponent
+ def initialize(project:)
+ super
+ @project = project
+ end
+
+ def breadcrumbs_items
+ [{ href: project_overview_path(@project.id), text: @project.name },
+ { href: project_settings_general_path, text: t("label_project_settings") },
+ t("project_module_storages")]
+ end
+
+ def tabs
+ [
+ {
+ name: "external",
+ path: external_file_storages_project_settings_project_storages_path,
+ label: t(:external_file_storages)
+ },
+ {
+ name: "attachments",
+ path: attachments_project_settings_project_storages_path,
+ label: t(:"attributes.attachments")
+ }
+ ]
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/views/storages/project_settings/attachments.html.erb b/modules/storages/app/views/storages/project_settings/attachments.html.erb
index 2dfdb21ec91..74ae1f86baf 100644
--- a/modules/storages/app/views/storages/project_settings/attachments.html.erb
+++ b/modules/storages/app/views/storages/project_settings/attachments.html.erb
@@ -29,35 +29,7 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t(:label_administration), t("project_module_storages") %>
-<%= render(Primer::OpenProject::PageHeader.new(border_bottom: 0)) do |header|
- header.with_title { t("project_module_storages") }
- header.with_breadcrumbs(
- [{ href: project_overview_path(@project.id), text: @project.name },
- { href: project_settings_general_path, text: t("label_project_settings") },
- t("project_module_storages")]
- )
- header.with_action_button(
- tag: :a,
- href: new_project_settings_project_storage_path,
- scheme: :primary,
- mobile_icon: :plus,
- mobile_label: t(:"storages.label_storage"),
- size: :medium,
- aria: { label: t(:"storages.label_new_storage") },
- title: t(:"storages.label_new_storage")
- ) do |button|
- button.with_leading_visual_icon(icon: :plus)
- t(:"storages.label_storage")
- end
- header.with_tab_nav(label: nil) do |tab_nav|
- tab_nav.with_tab(selected: false, href: external_file_storages_project_settings_project_storages_path) do |tab|
- tab.with_text { t(:external_file_storages) }
- end
- tab_nav.with_tab(selected: true, href: attachments_project_settings_project_storages_path) do |tab|
- tab.with_text { t(:"attributes.attachments") }
- end
- end
- end %>
+<%= render(::Storages::ProjectStorages::HeaderComponent.new(project: @project)) %>
<%=
render(Primer::OpenProject::FlexLayout.new(p: 3)) do |container|
diff --git a/modules/storages/app/views/storages/project_settings/external_file_storages.html.erb b/modules/storages/app/views/storages/project_settings/external_file_storages.html.erb
index 9577da8c153..df1d6f34e00 100644
--- a/modules/storages/app/views/storages/project_settings/external_file_storages.html.erb
+++ b/modules/storages/app/views/storages/project_settings/external_file_storages.html.erb
@@ -29,34 +29,6 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title t(:label_administration), t("project_module_storages") %>
-<%= render(Primer::OpenProject::PageHeader.new(border_bottom: 0)) do |header|
- header.with_title { t("project_module_storages") }
- header.with_breadcrumbs(
- [{ href: project_overview_path(@project.id), text: @project.name },
- { href: project_settings_general_path, text: t("label_project_settings") },
- t("project_module_storages")]
- )
- header.with_action_button(
- tag: :a,
- href: new_project_settings_project_storage_path,
- scheme: :primary,
- mobile_icon: :plus,
- mobile_label: t(:"storages.label_storage"),
- size: :medium,
- aria: { label: t(:"storages.label_new_storage") },
- title: t(:"storages.label_new_storage")
- ) do |button|
- button.with_leading_visual_icon(icon: :plus)
- t(:"storages.label_storage")
- end
- header.with_tab_nav(label: nil) do |tab_nav|
- tab_nav.with_tab(selected: true, href: external_file_storages_project_settings_project_storages_path) do |tab|
- tab.with_text { t(:external_file_storages) }
- end
- tab_nav.with_tab(selected: false, href: attachments_project_settings_project_storages_path) do |tab|
- tab.with_text { t(:"attributes.attachments") }
- end
- end
- end %>
+<%= render(::Storages::ProjectStorages::HeaderComponent.new(project: @project)) %>
<%= render(::Storages::ProjectStorages::TableComponent.new(rows: @project_storages)) %>