diff --git a/app/components/concerns/op_turbo/streamable.rb b/app/components/concerns/op_turbo/streamable.rb index dfad026a7825..89180a56ddc2 100644 --- a/app/components/concerns/op_turbo/streamable.rb +++ b/app/components/concerns/op_turbo/streamable.rb @@ -33,6 +33,8 @@ class MissingComponentWrapper < StandardError; end # rubocop:enable OpenProject/AddPreviewForViewComponent INLINE_ACTIONS = %i[dialog flash].freeze + # Turbo allows the response method for these actions only: + ACTIONS_WITH_METHOD = %i[update replace].freeze extend ActiveSupport::Concern @@ -43,7 +45,7 @@ def wrapper_key end included do - def render_as_turbo_stream(view_context:, action: :update) + def render_as_turbo_stream(view_context:, action: :update, method: nil) case action when :update, *INLINE_ACTIONS @inner_html_only = true @@ -63,8 +65,13 @@ def render_as_turbo_stream(view_context:, action: :update) "Wrap your component in a `component_wrapper` block in order to use turbo-stream methods" end + if method && !action.in?(ACTIONS_WITH_METHOD) + raise ArgumentError, "The #{action} action does not supports a method" + end + OpTurbo::StreamComponent.new( action:, + method:, target: wrapper_key, template: ).render_in(view_context) diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rb index 6cc60cd36918..f7cd5e1369bc 100644 --- a/app/controllers/concerns/op_turbo/component_stream.rb +++ b/app/controllers/concerns/op_turbo/component_stream.rb @@ -42,23 +42,24 @@ def respond_to_with_turbo_streams(status: turbo_status, &format_block) alias_method :respond_with_turbo_streams, :respond_to_with_turbo_streams - def update_via_turbo_stream(component:, status: :ok) - modify_via_turbo_stream(component:, action: :update, status:) + def update_via_turbo_stream(component:, status: :ok, method: nil) + modify_via_turbo_stream(component:, action: :update, status:, method:) end - def replace_via_turbo_stream(component:, status: :ok) - modify_via_turbo_stream(component:, action: :replace, status:) + def replace_via_turbo_stream(component:, status: :ok, method: nil) + modify_via_turbo_stream(component:, action: :replace, status:, method:) end def remove_via_turbo_stream(component:, status: :ok) modify_via_turbo_stream(component:, action: :remove, status:) end - def modify_via_turbo_stream(component:, action:, status:) + def modify_via_turbo_stream(component:, action:, status:, method: nil) @turbo_status = status turbo_streams << component.render_as_turbo_stream( view_context:, - action: + action:, + method: ) end diff --git a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts index eee4d16064e0..1cc2421b730f 100644 --- a/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts +++ b/frontend/src/stimulus/controllers/dynamic/overview/project-life-cycles-form.controller.ts @@ -43,8 +43,6 @@ export default class ProjectLifeCyclesFormController extends Controller { return; // flatpickr is still open, do not submit yet. } - // TODO: If morphing is working correctly, we don't need to blur the input field. - target.blur(); const form = this.formTarget; form.action = previewUrl; diff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rb index c56cd76dcacf..679701ae7bca 100644 --- a/modules/overviews/app/controllers/overviews/overviews_controller.rb +++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb @@ -94,7 +94,8 @@ def project_life_cycles_form .call(permitted_params.project_life_cycles) update_via_turbo_stream( - component: ProjectLifeCycles::Sections::EditComponent.new(service_call.result) + component: ProjectLifeCycles::Sections::EditComponent.new(service_call.result), + method: "morph" ) # TODO: :unprocessable_entity is not nice, change the dialog logic to accept :ok # without dismissing the dialog, alternatively use turbo frames instead of streams.