From 2377770ef6372d96ad86e55cfebd6d52946792cf Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 16:52:22 -0400 Subject: [PATCH 1/5] Stay on the collection edit page after changing workflow ref: https://fizzy.37signals.com/5986089/collections/2/cards/852 --- app/controllers/collections/workflows_controller.rb | 2 +- test/controllers/collections/workflows_controller_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/collections/workflows_controller.rb b/app/controllers/collections/workflows_controller.rb index 28b691f11..a24e646ee 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 cards_path(collection_ids: [ @collection ]) + redirect_to edit_collection_path(@collection), notice: "Collection updated" end private diff --git a/test/controllers/collections/workflows_controller_test.rb b/test/controllers/collections/workflows_controller_test.rb index 8fb0e8dce..68a85b956 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 cards_path(collection_ids: [ collection.id ]) + assert_redirected_to edit_collection_path(collection) assert_equal workflows(:on_call), collection.reload.workflow end end From 36727ba5ea77d80d2eaaf65f106ce31ee6a23ef7 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 17:41:29 -0400 Subject: [PATCH 2/5] Introduce a separate controller for collection entropy config which opens the door to rendering turbo frames in the responses to collection edits. --- .../entropy_configurations_controller.rb | 14 ++++++++++++++ app/views/collections/edit/_auto_close.html.erb | 2 +- config/routes.rb | 1 + .../entropy_configurations_controller_test.rb | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/controllers/collections/entropy_configurations_controller.rb create mode 100644 test/controllers/collections/entropy_configurations_controller_test.rb diff --git a/app/controllers/collections/entropy_configurations_controller.rb b/app/controllers/collections/entropy_configurations_controller.rb new file mode 100644 index 000000000..c09edcf98 --- /dev/null +++ b/app/controllers/collections/entropy_configurations_controller.rb @@ -0,0 +1,14 @@ +class Collections::EntropyConfigurationsController < ApplicationController + include CollectionScoped + + def update + @collection.entropy_configuration.update!(entropy_configuration_params) + + redirect_to edit_collection_path(@collection), notice: "Collection updated" + end + + private + def entropy_configuration_params + params.expect(collection: [ :auto_close_period, :auto_reconsider_period ]) + end +end diff --git a/app/views/collections/edit/_auto_close.html.erb b/app/views/collections/edit/_auto_close.html.erb index d222fd5e8..825915756 100644 --- a/app/views/collections/edit/_auto_close.html.erb +++ b/app/views/collections/edit/_auto_close.html.erb @@ -1,4 +1,4 @@
Do or Die - <%= render "entropy/auto_close", model: collection %> + <%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %>
diff --git a/config/routes.rb b/config/routes.rb index 27fdf59a6..26dbfd3d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,7 @@ Rails.application.routes.draw do resource :workflow, only: :update resource :involvement resource :publication + resource :entropy_configuration end resources :cards diff --git a/test/controllers/collections/entropy_configurations_controller_test.rb b/test/controllers/collections/entropy_configurations_controller_test.rb new file mode 100644 index 000000000..0b2ddf060 --- /dev/null +++ b/test/controllers/collections/entropy_configurations_controller_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +class Collections::EntropyConfigurationsControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :kevin + @collection = collections(:writebook) + end + + test "update" do + put collection_entropy_configuration_path(@collection), params: { collection: { auto_close_period: 1.day, auto_reconsider_period: 2.days } } + + assert_equal 1.day, @collection.entropy_configuration.reload.auto_close_period + assert_equal 2.days, @collection.entropy_configuration.reload.auto_reconsider_period + + assert_redirected_to edit_collection_path(@collection) + end +end From 263bc486ed0f42096d27e630e16d4c5b60baba93 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 17:50:37 -0400 Subject: [PATCH 3/5] Collection entropy config edits render a turbo frame so we don't disturb the rest of the edit page. --- .../collections/entropy_configurations_controller.rb | 2 +- app/views/collections/edit/_auto_close.html.erb | 10 ++++++---- .../entropy_configurations_controller_test.rb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/collections/entropy_configurations_controller.rb b/app/controllers/collections/entropy_configurations_controller.rb index c09edcf98..98a2b1b0f 100644 --- a/app/controllers/collections/entropy_configurations_controller.rb +++ b/app/controllers/collections/entropy_configurations_controller.rb @@ -4,7 +4,7 @@ class Collections::EntropyConfigurationsController < ApplicationController def update @collection.entropy_configuration.update!(entropy_configuration_params) - redirect_to edit_collection_path(@collection), notice: "Collection updated" + render turbo_stream: turbo_stream.replace([ @collection, :entropy_configuration ], partial: "collections/edit/auto_close", locals: { collection: @collection }) end private diff --git a/app/views/collections/edit/_auto_close.html.erb b/app/views/collections/edit/_auto_close.html.erb index 825915756..79125016d 100644 --- a/app/views/collections/edit/_auto_close.html.erb +++ b/app/views/collections/edit/_auto_close.html.erb @@ -1,4 +1,6 @@ -
- Do or Die - <%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %> -
+<%= turbo_frame_tag @collection, :entropy_configuration do %> +
+ Do or Die + <%= render "entropy/auto_close", model: collection, url: collection_entropy_configuration_path(collection) %> +
+<% end %> diff --git a/test/controllers/collections/entropy_configurations_controller_test.rb b/test/controllers/collections/entropy_configurations_controller_test.rb index 0b2ddf060..b96c3b198 100644 --- a/test/controllers/collections/entropy_configurations_controller_test.rb +++ b/test/controllers/collections/entropy_configurations_controller_test.rb @@ -12,6 +12,6 @@ class Collections::EntropyConfigurationsControllerTest < ActionDispatch::Integra assert_equal 1.day, @collection.entropy_configuration.reload.auto_close_period assert_equal 2.days, @collection.entropy_configuration.reload.auto_reconsider_period - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :entropy_configuration) end end From 0799ad050b5112e9c5c3aa03313f580c62091fae Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 22:08:09 -0400 Subject: [PATCH 4/5] 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 From 4589360dd1afbac09cc2ad743d8a676afbac60de Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 2 Jul 2025 22:15:21 -0400 Subject: [PATCH 5/5] Collection publication edits render a turbo frame so we don't disturb the rest of the edit page. --- .../collections/publications_controller.rb | 5 +- .../collections/edit/_publication.html.erb | 97 ++++++++++--------- .../publications_controller_test.rb | 4 +- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/app/controllers/collections/publications_controller.rb b/app/controllers/collections/publications_controller.rb index feb5ae4b7..2ded7eda2 100644 --- a/app/controllers/collections/publications_controller.rb +++ b/app/controllers/collections/publications_controller.rb @@ -3,11 +3,12 @@ class Collections::PublicationsController < ApplicationController def create @collection.publish - redirect_to edit_collection_path(@collection) + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end def destroy @collection.unpublish - redirect_to edit_collection_path(@collection) + @collection.reload + render turbo_stream: turbo_stream.replace([ @collection, :publication ], partial: "collections/edit/publication", locals: { collection: @collection }) end end diff --git a/app/views/collections/edit/_publication.html.erb b/app/views/collections/edit/_publication.html.erb index 72f315b8d..921cd6fe2 100644 --- a/app/views/collections/edit/_publication.html.erb +++ b/app/views/collections/edit/_publication.html.erb @@ -1,54 +1,55 @@ -
- Public link -

Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.

+<%= turbo_frame_tag @collection, :publication do %> +
+ Public link +

Turn on the Public link to share this collection with anyone in the world. They won’t need to log in and they won’t be able to see anything else in Fizzy.

- <% if collection.published? %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
+ <% if collection.published? %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> -
- <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> - <%= icon_tag "copy-paste" %> - Copy public link +
+ <%= text_field_tag :publication_url, published_collection_url(collection), disabled: true, class: "full-width input fill-white" %> +
+ <%= button_to_copy_to_clipboard(published_collection_url(collection)) do %> + <%= icon_tag "copy-paste" %> + Copy public link + <% end %> +
+
+ Add an optional description to the public page +
+ <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> + <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", + placeholder: "Add a public note about this collection…", + data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> + <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> <% end %>
- Add an optional description to the public page -
- <%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %> - <%= form.rich_textarea :public_description, class: "rich-text-content txt-small", - placeholder: "Add a public note about this collection…", - data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %> - <%= form.button "Save changes", type: :submit, class: "btn txt-small" %> - <% end %> + <% else %> +
+
+ <%= icon_tag "lock" %> + + <%= icon_tag "world" %> +
-
- <% else %> -
-
- <%= icon_tag "lock" %> - - <%= icon_tag "world" %> -
-
- <% end %> -
- + <% end %> +
+<% end %> diff --git a/test/controllers/collections/publications_controller_test.rb b/test/controllers/collections/publications_controller_test.rb index 2bd9ec1dc..da24c22da 100644 --- a/test/controllers/collections/publications_controller_test.rb +++ b/test/controllers/collections/publications_controller_test.rb @@ -13,7 +13,7 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest post collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end test "unpublish a collection" do @@ -24,6 +24,6 @@ class Collections::PublicationsControllerTest < ActionDispatch::IntegrationTest delete collection_publication_path(@collection) end - assert_redirected_to edit_collection_path(@collection) + assert_turbo_stream action: :replace, target: dom_id(@collection, :publication) end end