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

Enable morphing the Stages and Gates form preview action

Dombi Attila8040262a8bea
diff --git a/app/components/concerns/op_turbo/streamable.rb b/app/components/concerns/op_turbo/streamable.rb
index dfad026a782..89180a56ddc 100644
--- a/app/components/concerns/op_turbo/streamable.rb
+++ b/app/components/concerns/op_turbo/streamable.rb
@@ -33,6 +33,8 @@ module OpTurbo
# 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 @@ module OpTurbo
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 @@ module OpTurbo
"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 6cc60cd3691..f7cd5e1369b 100644
--- a/app/controllers/concerns/op_turbo/component_stream.rb
+++ b/app/controllers/concerns/op_turbo/component_stream.rb
@@ -42,23 +42,24 @@ module OpTurbo
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 eee4d16064e..1cc2421b730 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 c56cd76dcac..679701ae7bc 100644
--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb
+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb
@@ -94,7 +94,8 @@ module ::Overviews
.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.