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

account for the newly build element already being part of the childrens scope

ulferts505dc2b71bf8
diff --git a/app/components/admin/custom_fields/hierarchy/items_component.rb b/app/components/admin/custom_fields/hierarchy/items_component.rb
index 9c83089684a..89253771c21 100644
--- a/app/components/admin/custom_fields/hierarchy/items_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/items_component.rb
@@ -54,13 +54,9 @@ module Admin
list = model.children
return list unless @new_item
- position = @new_item.sort_order&.to_i
-
- if position
- list[0...position] + [@new_item] + list[position..]
- else
- list + [@new_item]
- end
+ # Sort by sort order. But if there is a new item, sort it to be before the other
+ # item that has the same sort order.
+ list.sort { |a, b| [a.sort_order.to_i, a.id.to_i] <=> [b.sort_order.to_i, b.id.to_i] }
end
def item_header
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index ae67c1e363b..a23eda79907 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -56,7 +56,7 @@ module Admin
end
def new
- @new_item = ::CustomField::Hierarchy::Item.new(parent: @active_item, sort_order: params[:position])
+ @new_item = @active_item.children.build(sort_order: params[:position])
end
def edit; end