From 0799ad050b5112e9c5c3aa03313f580c62091fae Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 22:08:09 -0400 Subject: [PATCH] Collection workflow edits render a turbo frame so we don't disturb the rest of the edit page. --- .../collections/workflows_controller.rb | 2 +- .../collections/edit/_workflows.html.erb | 44 ++++++++++--------- .../collections/workflows_controller_test.rb | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/controllers/collections/workflows_controller.rb b/app/controllers/collections/workflows_controller.rb index a24e646ee..fd503473c 100644 --- a/app/controllers/collections/workflows_controller.rb +++ b/app/controllers/collections/workflows_controller.rb @@ -5,7 +5,7 @@ class Collections::WorkflowsController < ApplicationController def update @collection.update! workflow: @workflow - redirect_to edit_collection_path(@collection), notice: "Collection updated" + render turbo_stream: turbo_stream.replace([ @collection, :workflows ], partial: "collections/edit/workflows", locals: { collection: @collection }) end private diff --git a/app/views/collections/edit/_workflows.html.erb b/app/views/collections/edit/_workflows.html.erb index 1b6154415..73d36de66 100644 --- a/app/views/collections/edit/_workflows.html.erb +++ b/app/views/collections/edit/_workflows.html.erb @@ -1,21 +1,23 @@ -Workflows -
Use a Workflow to track progress in this Collection.
-
- <% Workflow.all.each do |workflow| %> -
- <%= button_to collection_workflow_path(collection), method: :patch do %> - <%= hidden_field_tag "collection[workflow_id]", workflow.id %> - <%= workflow.name %> -
    - <% workflow.stages.each do |stage| %> -
  • - - <%= stage.name %> -
  • - <% end %> -
- <% end %> -
- <% end %> -
-

<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>

+<%= turbo_frame_tag @collection, :workflows do %> + Workflows +
Use a Workflow to track progress in this Collection.
+
+ <% Workflow.all.each do |workflow| %> +
+ <%= button_to collection_workflow_path(collection), method: :patch do %> + <%= hidden_field_tag "collection[workflow_id]", workflow.id %> + <%= workflow.name %> +
    + <% workflow.stages.each do |stage| %> +
  • + + <%= stage.name %> +
  • + <% end %> +
+ <% end %> +
+ <% end %> +
+

<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link" %>

+<% end %> diff --git a/test/controllers/collections/workflows_controller_test.rb b/test/controllers/collections/workflows_controller_test.rb index 68a85b956..e4e739720 100644 --- a/test/controllers/collections/workflows_controller_test.rb +++ b/test/controllers/collections/workflows_controller_test.rb @@ -10,7 +10,7 @@ class Collections::WorkflowsControllerTest < ActionDispatch::IntegrationTest patch collection_workflow_path(collection), params: { collection: { workflow_id: workflows(:on_call).id } } - assert_redirected_to edit_collection_path(collection) + assert_turbo_stream action: :replace, target: dom_id(collection, :workflows) assert_equal workflows(:on_call), collection.reload.workflow end end