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

chore[Op#57579]: elevate custom fields modals from project attributes

Kabiru Mwenjab9f4b57aafdb
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.html.erb b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.html.erb
similarity index 84%
rename from app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.html.erb
rename to app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.html.erb
index 9cfde730389..a7596230ea1 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.html.erb
+++ b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.html.erb
@@ -30,20 +30,20 @@ See COPYRIGHT and LICENSE files for more details.
<%=
component_wrapper do
primer_form_with(
- class: "op-new-project-mapping-form",
- model: @project_mapping,
- url: link_admin_settings_project_custom_field_path(@project_custom_field),
+ model: ,
+ url:,
data: { turbo: true },
method: :post
) do |form|
concat(render(Primer::Alpha::Dialog::Body.new(
- id: DIALOG_BODY_ID, test_selector: DIALOG_BODY_ID, aria: { label: title },
+ id: dialog_body_id, test_selector: dialog_body_id, aria: { label: title },
style: "min-height: 300px"
)) do
- render(Projects::CustomFields::CustomFieldMappingForm.new(form, project_mapping: @project_mapping))
+ render(Projects::CustomFields::CustomFieldMappingForm.new(form, project_mapping: @custom_field_project_mapping))
end)
+
concat(render(Primer::Alpha::Dialog::Footer.new(show_divider: false)) do
- concat(render(Primer::ButtonComponent.new(data: { 'close-dialog-id': DIALOG_ID })) { cancel_button_text })
+ concat(render(Primer::ButtonComponent.new(data: { 'close-dialog-id': dialog_id })) { cancel_button_text })
concat(render(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) { submit_button_text })
end)
end
diff --git a/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.rb b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.rb
new file mode 100644
index 00000000000..647e2fec7ac
--- /dev/null
+++ b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_form_modal_component.rb
@@ -0,0 +1,70 @@
+#-- 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 Admin
+ module CustomFields
+ module CustomFieldProjects
+ class NewCustomFieldProjectsFormModalComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ DIALOG_ID = "new-custom-field-projects-modal".freeze
+ DIALOG_BODY_ID = "new-custom-field-projects-modal-body".freeze
+
+ def initialize(custom_field_project_mapping:, custom_field:, **)
+ @custom_field_project_mapping = custom_field_project_mapping
+ @custom_field = custom_field
+
+ super(@custom_field_project_mapping, **)
+ end
+
+ private
+
+ def url
+ url_helpers.custom_field_projects_path(@custom_field)
+ end
+
+ def dialog_id = DIALOG_ID
+ def dialog_body_id = DIALOG_BODY_ID
+
+ attr_reader :custom_field_project_mapping, :custom_field
+
+ def title
+ I18n.t(:label_add_projects)
+ end
+
+ def cancel_button_text
+ I18n.t("button_cancel")
+ end
+
+ def submit_button_text
+ I18n.t("button_add")
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.html.erb b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.html.erb
new file mode 100644
index 00000000000..346ef80311d
--- /dev/null
+++ b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.html.erb
@@ -0,0 +1,18 @@
+<%=
+ render(
+ Primer::Alpha::Dialog.new(
+ id: dialog_id,
+ title:,
+ test_selector: dialog_id,
+ size: :large
+ )
+ ) do |dialog|
+ dialog.with_header(
+ show_divider: false,
+ visually_hide_title: false,
+ variant: :large
+ )
+
+ render(form_modal_component)
+ end
+%>
diff --git a/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.rb b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.rb
new file mode 100644
index 00000000000..e264b251323
--- /dev/null
+++ b/app/components/admin/custom_fields/custom_field_projects/new_custom_field_projects_modal_component.rb
@@ -0,0 +1,64 @@
+#-- 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 Admin
+ module CustomFields
+ module CustomFieldProjects
+ class NewCustomFieldProjectsModalComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ def initialize(custom_field_project_mapping:, custom_field:, **)
+ @custom_field_project_mapping = custom_field_project_mapping
+ @custom_field = custom_field
+ super(@custom_field_project_mapping, **)
+ end
+
+ def render?
+ !custom_field.is_for_all?
+ end
+
+ private
+
+ attr_reader :custom_field_project_mapping, :custom_field
+
+ def dialog_id = NewCustomFieldProjectsFormModalComponent::DIALOG_ID
+ def dialog_body_id = NewCustomFieldProjectsFormModalComponent::DIALOG_BODY_ID
+
+ def title
+ I18n.t(:label_add_projects)
+ end
+
+ def form_modal_component
+ Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsFormModalComponent.new(
+ custom_field_project_mapping:, custom_field:
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.html.erb b/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.html.erb
deleted file mode 100644
index 6fe98a3cdc6..00000000000
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<%=
- render(
- Primer::Alpha::Dialog.new(
- id: Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent::DIALOG_ID,
- title:,
- test_selector: Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent::DIALOG_ID,
- size: :large
- )
- ) do |dialog|
- dialog.with_header(
- show_divider: false,
- visually_hide_title: false,
- variant: :large
- )
-
- render(Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent.new(project_mapping: @project_mapping, project_custom_field: @project_custom_field))
- end
-%>
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.rb b/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.rb
index 327b7a1a936..1879fa8776b 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.rb
+++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_component.rb
@@ -29,23 +29,18 @@
module Settings
module ProjectCustomFields
module ProjectCustomFieldMapping
- class NewProjectMappingComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
- include OpTurbo::Streamable
-
- def initialize(project_mapping:, project_custom_field:, **)
- @project_mapping = project_mapping
- @project_custom_field = project_custom_field
- super(@project_mapping, **)
- end
-
+ class NewProjectMappingComponent < Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsModalComponent
def render?
- !@project_custom_field.required?
+ !custom_field.required?
end
private
- def title
- I18n.t(:label_add_projects)
+ def form_modal_component
+ Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent.new(
+ custom_field_project_mapping:,
+ custom_field:
+ )
end
end
end
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.rb b/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.rb
index e024bc27713..806ac8b223d 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.rb
+++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/new_project_mapping_form_component.rb
@@ -29,30 +29,11 @@
module Settings
module ProjectCustomFields
module ProjectCustomFieldMapping
- class NewProjectMappingFormComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
- include OpTurbo::Streamable
-
- DIALOG_ID = "settings--new-project-custom-field-mapping-component".freeze
- DIALOG_BODY_ID = "settings--new-project-custom-field-mapping-body-component".freeze
-
- def initialize(project_mapping:, project_custom_field:)
- super
- @project_mapping = project_mapping
- @project_custom_field = project_custom_field
- end
-
+ class NewProjectMappingFormComponent < Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsFormModalComponent
private
- def title
- I18n.t(:label_add_projects)
- end
-
- def cancel_button_text
- I18n.t("button_cancel")
- end
-
- def submit_button_text
- I18n.t("button_add")
+ def url
+ url_helpers.link_admin_settings_project_custom_field_path(@custom_field)
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 ab06963ee7c..2b10ab128af 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -76,8 +76,8 @@ module Admin::Settings
def new_link
@project_mapping = ProjectCustomFieldProjectMapping.new(project_custom_field: @custom_field)
respond_with_dialog Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingComponent.new(
- project_mapping: @project_mapping,
- project_custom_field: @custom_field
+ custom_field_project_mapping: @project_mapping,
+ custom_field: @custom_field
)
end
@@ -205,8 +205,8 @@ module Admin::Settings
project_mapping = ProjectCustomFieldProjectMapping.new(project_custom_field: @custom_field)
project_mapping.errors.add(:project_ids, :blank)
component = Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent.new(
- project_mapping:,
- project_custom_field: @custom_field
+ custom_field_project_mapping: project_mapping,
+ custom_field: @custom_field
)
update_via_turbo_stream(component:, status: :bad_request)
respond_with_turbo_streams
diff --git a/app/forms/projects/custom_fields/custom_field_mapping_form.rb b/app/forms/projects/custom_fields/custom_field_mapping_form.rb
index cda7e1c10e4..1f598a73067 100644
--- a/app/forms/projects/custom_fields/custom_field_mapping_form.rb
+++ b/app/forms/projects/custom_fields/custom_field_mapping_form.rb
@@ -73,10 +73,14 @@ module Projects::CustomFields
end
def projects_with_custom_field_mapping
- ProjectCustomFieldProjectMapping
+ join_table
.where(custom_field_id: @project_mapping.custom_field_id)
.pluck(:project_id)
.to_h { |id| [id, id] }
end
+
+ def join_table
+ @project_mapping.class
+ end
end
end
diff --git a/spec/features/admin/project_custom_fields/project_mappings_spec.rb b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
index a5bb3bf0bb0..015f636f5b6 100644
--- a/spec/features/admin/project_custom_fields/project_mappings_spec.rb
+++ b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
@@ -103,7 +103,7 @@ RSpec.describe "Project Custom Field Mappings", :js do
subproject = create(:project, parent: project)
click_on "Add projects"
- within_test_selector("settings--new-project-custom-field-mapping-component") do
+ within_test_selector("new-custom-field-projects-modal") do
autocompleter = page.find(".op-project-autocompleter")
autocompleter.fill_in with: project.name