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

refactor: extract method `respond_with_relations_tab_update`

Christophe Bliarda10a0befe9ae
diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rb
index 61fab59c7e1..71f2d5833d1 100644
--- a/app/controllers/work_package_relations_controller.rb
+++ b/app/controllers/work_package_relations_controller.rb
@@ -59,15 +59,7 @@ class WorkPackageRelationsController < ApplicationController
service_result = Relations::CreateService.new(user: current_user)
.call(create_relation_params)
- if service_result.success?
- @work_package.reload
- component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
- relation_to_scroll_to: service_result.result)
- replace_via_turbo_stream(component:)
- respond_with_turbo_streams
- else
- respond_with_turbo_streams(status: :unprocessable_entity)
- end
+ respond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)
end
def update
@@ -76,30 +68,30 @@ class WorkPackageRelationsController < ApplicationController
model: @relation)
.call(update_relation_params)
- if service_result.success?
- @work_package.reload
- component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package)
- replace_via_turbo_stream(component:)
- respond_with_turbo_streams
- else
- respond_with_turbo_streams(status: :unprocessable_entity)
- end
+ respond_with_relations_tab_update(service_result)
end
def destroy
service_result = Relations::DeleteService.new(user: current_user, model: @relation).call
+ respond_with_relations_tab_update(service_result)
+ end
+
+ private
+
+ def respond_with_relations_tab_update(service_result, **)
if service_result.success?
- component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package.reload)
+ @work_package.reload
+ component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package, **)
replace_via_turbo_stream(component:)
+ render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))
+
respond_with_turbo_streams
else
respond_with_turbo_streams(status: :unprocessable_entity)
end
end
- private
-
def set_work_package
@work_package = WorkPackage.find(params[:work_package_id])
end