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

Base respond_with_dialog on OpTurbo::ComponentStream

Jan Sandbrinkef6fdb29d5ed
diff --git a/app/controllers/concerns/op_turbo/dialog_stream_helper.rb b/app/controllers/concerns/op_turbo/dialog_stream_helper.rb
index 0eec3f4f1eb..9dbfef59aa9 100644
--- a/app/controllers/concerns/op_turbo/dialog_stream_helper.rb
+++ b/app/controllers/concerns/op_turbo/dialog_stream_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -29,13 +31,9 @@
module OpTurbo
module DialogStreamHelper
def respond_with_dialog(dialog_component, status: :ok, &format_block)
- respond_to do |format|
- format.turbo_stream do
- render turbo_stream: dialog_component.render_as_turbo_stream(view_context:, action: :dialog), status:
- end
+ modify_via_turbo_stream(component: dialog_component, action: :dialog, status:)
- yield(format) if format_block
- end
+ respond_to_with_turbo_streams(&format_block)
end
end
end
diff --git a/app/controllers/projects/settings/general_controller.rb b/app/controllers/projects/settings/general_controller.rb
index f4432d0bad9..2318c0f363b 100644
--- a/app/controllers/projects/settings/general_controller.rb
+++ b/app/controllers/projects/settings/general_controller.rb
@@ -29,6 +29,7 @@
#++
class Projects::Settings::GeneralController < Projects::SettingsController
+ include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper
menu_item :settings_general
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 55dc5234c2c..12e3c69d7a5 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -28,6 +28,7 @@
class ProjectsController < ApplicationController
include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
menu_item :overview
menu_item :roadmap, only: :roadmap
@@ -47,7 +48,6 @@ class ProjectsController < ApplicationController
include QueriesHelper
include ProjectsHelper
include Queries::Loading
- include OpTurbo::DialogStreamHelper
helper_method :has_managed_project_folders?
diff --git a/lookbook/docs/patterns/05-dialogs.md.erb b/lookbook/docs/patterns/05-dialogs.md.erb
index b3cf7b675b6..c17d61aa34a 100644
--- a/lookbook/docs/patterns/05-dialogs.md.erb
+++ b/lookbook/docs/patterns/05-dialogs.md.erb
@@ -28,7 +28,8 @@ The async-controller stimulus controller will ensure that a loading progress bar
```ruby
class TestController < ApplicationControler
- # include the helper module
+ # include the helper modules
+ include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper
# ...
@@ -39,7 +40,7 @@ class TestController < ApplicationControler
end
```
-For this to work, the `OpTurbo::Streamable` module needs to be included in the modal component, along with the `OpTurbo::DialogStreamHelper` module in the corresponding controller:
+For this to work, the `OpTurbo::Streamable` module needs to be included in the modal component, along with the `OpTurbo::DialogStreamHelper` and `OpTurbo::ComponentStream` modules in the corresponding controller:
```ruby
class MyDialogComponent < ApplicationControler
@@ -70,9 +71,6 @@ You can also render the dialog in a manual turbo_stream template:
```ruby
class TestController < ApplicationControler
- # include the helper module
- include OpTurbo::DialogStreamHelper
-
# ...
def dialog; end
@@ -144,7 +142,8 @@ Referring to the example above (see "Dialogs with separate forms"), a controller
```ruby
class TestController < ApplicationControler
- # include the helper module
+ # include the helper modules
+ include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper
# ...