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

Add turbo power so we can change urls in turbo streams

Oliver Günther743ea7caa2bd
diff --git a/Gemfile b/Gemfile
index 49515bab39d..0dad7754f4c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -228,6 +228,7 @@ gem "factory_bot", "~> 6.4.0", require: false
gem "factory_bot_rails", "~> 6.4.0", require: false
gem "turbo-rails", "~> 2.0.0"
+gem "turbo_power", "~> 0.6.2"
gem "httpx"
diff --git a/Gemfile.lock b/Gemfile.lock
index 50757e4a4d2..3489f44c98f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1093,6 +1093,8 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
+ turbo_power (0.6.2)
+ turbo-rails (>= 1.3.0)
typed_dag (2.0.2)
rails (>= 5.0.4)
tzinfo (2.0.6)
@@ -1347,6 +1349,7 @@ DEPENDENCIES
timecop (~> 0.9.0)
ttfunk (~> 1.7.0)
turbo-rails (~> 2.0.0)
+ turbo_power (~> 0.6.2)
turbo_tests!
typed_dag (~> 2.0.2)
tzinfo-data (~> 1.2024.1)
diff --git a/app/components/work_packages/details/tab_component.html.erb b/app/components/work_packages/details/tab_component.html.erb
index 0bee0932f43..3ee5de0932c 100644
--- a/app/components/work_packages/details/tab_component.html.erb
+++ b/app/components/work_packages/details/tab_component.html.erb
@@ -6,7 +6,7 @@
component.with_tab(selected: @tab == node.name,
href: url_for(node.url),
test_selector: "wp-details-tab-component--tab-#{node.name}",
- data: { turbo: true, turbo_action: "replace" }
+ data: { turbo: true, turbo_stream: true, turbo_action: "replace" }
) do |c|
c.with_text { t("js.work_packages.tabs.#{node.name}") }
count = node.badge(work_package:).to_i
@@ -30,7 +30,7 @@
render(Primer::Beta::IconButton.new(icon: :x,
tag: :a,
href: url_for(action: :close_split_view),
- data: { 'turbo-stream': true },
+ data: { turbo: true, 'turbo-stream': true },
scheme: :invisible,
test_selector: "wp-details-tab-component--close",
aria: { label: I18n.t(:button_close) }))
diff --git a/app/controllers/concerns/work_packages/with_split_view.rb b/app/controllers/concerns/work_packages/with_split_view.rb
index 010f5c16caa..9845312380c 100644
--- a/app/controllers/concerns/work_packages/with_split_view.rb
+++ b/app/controllers/concerns/work_packages/with_split_view.rb
@@ -30,19 +30,35 @@ module WorkPackages
module WithSplitView
extend ActiveSupport::Concern
- def close_split_view
- id = params[:work_package_id].to_i
+ included do
+ helper_method :split_view_base_route
+ end
+
+ def split_view_work_package_id
+ params[:work_package_id].to_i
+ end
+ def close_split_view
respond_to do |format|
- format.turbo_stream { render turbo_stream: turbo_stream.remove("work-package-details-#{id}") }
- format.html { redirect_to public_send(params[:base_route]) }
+ format.turbo_stream do
+ render turbo_stream: [
+ turbo_stream.remove("work-package-details-#{split_view_work_package_id}"),
+ turbo_stream.push_state(url: split_view_base_route)
+ ]
+ end
+ format.html do
+ redirect_to split_view_base_route
+ end
end
end
def respond_to_with_split_view(&format_block)
respond_to do |format|
format.turbo_stream do
- render turbo_stream: turbo_stream.update("content-bodyRight", helpers.split_view_instance.render_in(view_context))
+ render turbo_stream: [
+ turbo_stream.update("content-bodyRight", helpers.split_view_instance.render_in(view_context)),
+ turbo_stream.push_state(url: request.path)
+ ]
end
yield(format) if format_block
diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb
index 173b7b709cc..a94c502dc34 100644
--- a/app/controllers/notifications_controller.rb
+++ b/app/controllers/notifications_controller.rb
@@ -65,6 +65,8 @@ class NotificationsController < ApplicationController
private
+ def split_view_base_route = notifications_path
+
def default_breadcrumb; end
def render_notifications_layout
diff --git a/config/routes.rb b/config/routes.rb
index 6d522e2ab95..d8b56eec65d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -705,13 +705,11 @@ Rails.application.routes.draw do
action: options.fetch(:action, :split_view),
defaults: { tab: :overview },
as: :details,
- work_package_split_view: true,
- base_route: options.fetch(:base_route)
+ work_package_split_view: true
get "/:work_package_id/close",
on: :collection,
- action: :close_split_view,
- base_route: options.fetch(:base_route)
+ action: :close_split_view
end
resources :notifications, only: :index do
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index d14ef266cf8..b49f9b715f3 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -99,6 +99,7 @@
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
"ts-action-operators": "^9.1.2",
+ "turbo_power": "^0.6.2",
"typedjson": "^1.5.1",
"urijs": "^1.19.11",
"uuid": "^8.3.2",
@@ -20479,6 +20480,15 @@
"node": ">=16 || 14 >=14.17"
}
},
+ "node_modules/turbo_power": {
+ "version": "0.6.2",
+ "resolved": "https://registry.npmjs.org/turbo_power/-/turbo_power-0.6.2.tgz",
+ "integrity": "sha512-GCrwi6+rSLVORqb1LwP9pf/jP1Zo5lJgzGbLVu8g79T6LvB/9GGg7VWdLlWB0RvvDE1/+3hm32MPtEL5g89fsg==",
+ "license": "MIT",
+ "peerDependencies": {
+ "@hotwired/turbo": ">= 7.2"
+ }
+ },
"node_modules/type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
@@ -37048,6 +37058,11 @@
}
}
},
+ "turbo_power": {
+ "version": "0.6.2",
+ "resolved": "https://registry.npmjs.org/turbo_power/-/turbo_power-0.6.2.tgz",
+ "integrity": "sha512-GCrwi6+rSLVORqb1LwP9pf/jP1Zo5lJgzGbLVu8g79T6LvB/9GGg7VWdLlWB0RvvDE1/+3hm32MPtEL5g89fsg=="
+ },
"type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index c1653f208fd..d6d3ad400f6 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -150,6 +150,7 @@
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
"ts-action-operators": "^9.1.2",
+ "turbo_power": "^0.6.2",
"typedjson": "^1.5.1",
"urijs": "^1.19.11",
"uuid": "^8.3.2",
diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.ts
index 9bd905bbb9a..1cda5f53a90 100644
--- a/frontend/src/turbo/setup.ts
+++ b/frontend/src/turbo/setup.ts
@@ -1,5 +1,6 @@
import '../typings/shims.d.ts';
import * as Turbo from '@hotwired/turbo';
+import TurboPower from 'turbo_power'
import { registerDialogStreamAction } from './dialog-stream-action';
import { addTurboEventListeners } from './turbo-event-listeners';
@@ -8,9 +9,13 @@ Turbo.session.drive = false;
// Start turbo
Turbo.start();
+// Register our own actions
addTurboEventListeners();
registerDialogStreamAction();
+// Register turbo power actions
+TurboPower.initialize(Turbo.StreamActions);
+
// Error handling when "Content missing" returned
document.addEventListener('turbo:frame-missing', (event:CustomEvent) => {
const { detail: { response, visit } } = event as { detail:{ response:Response, visit:(url:string) => void } };