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

fix[Op#54456]: Use `TabNav` instead for URL navigation on tab change

Kabiru Mwenja5bb158fa43cb
diff --git a/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb
new file mode 100644
index 00000000000..fc359803426
--- /dev/null
+++ b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.html.erb
@@ -0,0 +1,47 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2023 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(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field)) %>
+
+<%=
+ render(Primer::Alpha::TabNav.new(label: "label")) do |component|
+ component.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
+
+ component.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 { I18n.t(:label_project_plural) }
+ end
+ end
+%>
diff --git a/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.rb b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.rb
new file mode 100644
index 00000000000..b75aeb59537
--- /dev/null
+++ b/app/components/admin/settings/project_custom_fields/project_attribute_detail_header_component.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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 Admin
+ module Settings
+ module ProjectCustomFields
+ class ProjectAttributeDetailHeaderComponent < 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)
+
+ super
+ @custom_field = custom_field
+ @selected = selected
+ end
+
+ TAB_NAVS.each do |tab_nav|
+ define_method(:"#{tab_nav}_selected?") do
+ @selected == tab_nav
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index 1dcdafd7913..ebbc36252f2 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -35,7 +35,7 @@ module Admin::Settings
menu_item :project_custom_fields_settings
before_action :set_sections, only: %i[show index edit move drop]
- before_action :find_custom_field, only: %i[show edit unlink destroy move drop]
+ before_action :find_custom_field, only: %i[show edit project_mappings unlink destroy move drop]
def show_local_breadcrumb
false
@@ -66,11 +66,20 @@ module Admin::Settings
end
end
+ def project_mappings
+ @project_custom_field_mappings_query = Queries::Projects::ProjectQuery.new(
+ name: "project-custom-field-mappings-#{@custom_field.id}"
+ ) do |query|
+ query.where(:available_project_attributes, "=", [@custom_field.id])
+ query.select(:name)
+ end
+ end
+
def unlink
project = Project.find(permitted_params.project_custom_field_project_mapping[:project_id])
- custom_field_project_mapping = @custom_field.project_custom_field_project_mappings.find_by(project:)
+ project_custom_field_mapping = @custom_field.project_custom_field_project_mappings.find_by(project:)
delete_service = ProjectCustomFieldProjectMappings::DeleteService
- .new(user: current_user, model: custom_field_project_mapping)
+ .new(user: current_user, model: project_custom_field_mapping)
.call
remove_via_turbo_stream(
diff --git a/app/views/admin/settings/project_custom_fields/edit.html.erb b/app/views/admin/settings/project_custom_fields/edit.html.erb
index f4e2a5687ca..5b648073d90 100644
--- a/app/views/admin/settings/project_custom_fields/edit.html.erb
+++ b/app/views/admin/settings/project_custom_fields/edit.html.erb
@@ -33,25 +33,11 @@ See COPYRIGHT and LICENSE files for more details.
<% local_assigns[:additional_breadcrumb] = @custom_field.name %>
-<%= render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field)) %>
-
<%=
- render(Primer::Alpha::TabPanels.new(label: 'label')) do |component|
- component.with_tab(selected: true, id: "project-custom-fields-details-tab") do |tab|
- tab.with_panel do
- render partial: 'details_form', locals: { custom_field: @custom_field }
- end
-
- tab.with_text { I18n.t(:label_details) }
- end
-
- component.with_tab(selected: false, id: "project-custom-fields-mapping-tab") do |tab|
- tab.with_panel do
- render partial: 'project_custom_field_mapping',
- locals: { custom_field: @custom_field, query: @project_custom_field_mapping_query }
- end
-
- tab.with_text { I18n.t(:label_project_plural) }
- end
- end
+ render(Admin::Settings::ProjectCustomFields::ProjectAttributeDetailHeaderComponent.new(
+ custom_field: @custom_field,
+ selected: :project_custom_field_edit
+ ))
%>
+
+<%= render partial: 'details_form', locals: { custom_field: @custom_field } %>
diff --git a/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb
similarity index 72%
rename from app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb
rename to app/views/admin/settings/project_custom_fields/project_mappings.html.erb
index 1fbdd903eb3..4bdb9e3605d 100644
--- a/app/views/admin/settings/project_custom_fields/_project_custom_field_mapping.html.erb
+++ b/app/views/admin/settings/project_custom_fields/project_mappings.html.erb
@@ -27,4 +27,18 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(query:, params: { custom_field: })) %>
+<% local_assigns[:additional_breadcrumb] = @custom_field.name %>
+
+<%=
+ render(Admin::Settings::ProjectCustomFields::ProjectAttributeDetailHeaderComponent.new(
+ custom_field: @custom_field,
+ selected: :project_custom_field_project_mappings
+ ))
+%>
+
+<%=
+ render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(
+ query: @project_custom_field_mappings_query,
+ params: { custom_field: @custom_field })
+ )
+%>
diff --git a/config/routes.rb b/config/routes.rb
index 601c7ba39fc..88a188eb2d2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -455,6 +455,8 @@ Rails.application.routes.draw do
post :reorder_alphabetical
put :move
put :drop
+
+ get :project_mappings
delete :unlink
end
end