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

Clean up the ItemForm

Marcello Rocha752a42c641c0
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
index 19e98ea72e8..680363dffee 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- primer_form_with(url: @url, method: @method, test_selector: "op-custom-fields--new-item-form") do |f|
+ primer_form_with(**item_options, test_selector: "op-custom-fields--new-item-form") do |f|
render(CustomFields::Hierarchy::ItemForm.new(f, target_item: model))
end
%>
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.rb b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
index 779b15079c1..bf1ce2b250a 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
@@ -34,10 +34,29 @@ module Admin
class ItemFormComponent < ApplicationComponent
include OpTurbo::Streamable
- def initialize(target_item:, url:, method:)
- super(target_item)
- @url = url
- @method = method
+ def item_options
+ options = { url:, method: http_verb }
+ options[:data] = { turbo_frame: ItemsComponent.wrapper_key } if model.new_record?
+
+ options
+ end
+
+ def http_verb
+ model.new_record? ? :post : :put
+ end
+
+ def url
+ if model.new_record?
+ new_child_custom_field_item_path(root.custom_field_id, model.parent, position: model.sort_order)
+ else
+ custom_field_item_path(root.custom_field_id, model)
+ end
+ end
+
+ private
+
+ def root
+ @root ||= model.new_record? ? model.parent.root : model.root
end
end
end