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

[#68045] switch to single select variant for change parent

Eric Schubert4e1192a60904
diff --git a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb
index d424ee57919..db0f3ae75f4 100644
--- a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb
@@ -86,13 +86,19 @@ module Admin
{
label: item.label,
current: current?(item),
- value: item.id
+ value: item.id,
+ select_variant: :single,
+ disabled: disabled?(item)
}
end
def current?(item)
item.id == @hierarchy_item.id
end
+
+ def disabled?(item)
+ item.id == @hierarchy_item.id || item.id == @hierarchy_item.parent.id
+ end
end
end
end
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb
index 4edbd0d4e2a..28b097ee56a 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb
@@ -97,24 +97,20 @@ module Admin
end
def change_parent
- result = parse_parent_input(new_parent_params).bind do |new_parent|
- validate_new_parent(new_parent).bind do
- item_service.move_item(item: @active_item, new_parent:)
- end
- end
-
- result.either(
- ->(result) do
- redirect_to action: :show,
- id: result.parent,
- status: :see_other,
- notice: I18n.t(:notice_successful_update)
- end,
- ->(error) do
- render_error_flash_message_via_turbo_stream(message: error)
- respond_with_turbo_streams(&:html)
- end
- )
+ parse_parent_input(new_parent_params)
+ .bind { item_service.move_item(item: @active_item, new_parent: it) }
+ .either(
+ ->(result) do
+ redirect_to action: :show,
+ id: result.parent,
+ status: :see_other,
+ notice: I18n.t(:notice_successful_update)
+ end,
+ ->(error) do
+ render_error_flash_message_via_turbo_stream(message: error)
+ respond_with_turbo_streams(&:html)
+ end
+ )
end
def destroy
@@ -211,13 +207,6 @@ module Admin
end
end
- def validate_new_parent(new_parent)
- return Failure("Parent must not be the same as before.") if @active_item.parent.id == new_parent.id
- return Failure("Parent must not be the current item.") if @active_item.id == new_parent.id
-
- Success()
- end
-
def find_model_object
@object = find_custom_field
@custom_field = @object