From 44650cc36e42ff06c86275f1feff227bc6b5069c Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 21 Mar 2025 17:40:11 -0400 Subject: [PATCH] Reload the assignees turbo frame when assigments are updated Also, add a cache around the dropdown keyed on [bubble, bucket]. --- .../assignments/toggles_controller.rb | 14 +++++++- app/views/bubbles/_assignees.html.erb | 4 +-- .../bubbles/sidebar/_assignment.html.erb | 36 ++++++++++--------- .../assignments/toggles_controller_test.rb | 14 +++++--- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/controllers/assignments/toggles_controller.rb b/app/controllers/assignments/toggles_controller.rb index a2285b35e..08562dde4 100644 --- a/app/controllers/assignments/toggles_controller.rb +++ b/app/controllers/assignments/toggles_controller.rb @@ -1,6 +1,10 @@ class Assignments::TogglesController < ApplicationController include BubbleScoped, BucketScoped + def new + render partial: "bubbles/sidebar/assignment", locals: { bubble: @bubble } + end + def create new_assignee_ids = Array(params[:assignee_id]) current_assignees = @bubble.assignees @@ -14,7 +18,15 @@ class Assignments::TogglesController < ApplicationController @bubble.toggle_assignment(assignee) unless current_assignees.include?(assignee) end - redirect_to @bubble + @bubble.assignees.reload + + respond_to do |format| + format.turbo_stream do + render turbo_stream: turbo_stream.replace([ @bubble, :assignees ], + partial: "bubbles/assignees", + locals: { bubble: @bubble }) + end + end end private diff --git a/app/views/bubbles/_assignees.html.erb b/app/views/bubbles/_assignees.html.erb index f054bb3ed..d6af2a636 100644 --- a/app/views/bubbles/_assignees.html.erb +++ b/app/views/bubbles/_assignees.html.erb @@ -10,9 +10,7 @@ Assign - - <%= render "bubbles/sidebar/assignment", bubble: bubble %> - + <%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) %> <% end %> diff --git a/app/views/bubbles/sidebar/_assignment.html.erb b/app/views/bubbles/sidebar/_assignment.html.erb index 72dc42976..1c6f223b4 100644 --- a/app/views/bubbles/sidebar/_assignment.html.erb +++ b/app/views/bubbles/sidebar/_assignment.html.erb @@ -1,21 +1,23 @@ -<%= turbo_frame_tag bubble, :assignment do %> - - Assign this to… +<% cache [bubble, bubble.bucket] do %> + <%= turbo_frame_tag bubble, :assignment do %> + + Assign this to… - <%= form_with url: bucket_bubble_assignment_toggles_path(bubble.bucket, bubble), class: "flex flex-column full-width popup__list", data: { controller: "form" } do |form| %> - <% bubble.bucket.users.active.sort_by(&:name).each do |user| %> - + <% end %> <% end %> - <% end %> - + + <% end %> <% end %> diff --git a/test/controllers/assignments/toggles_controller_test.rb b/test/controllers/assignments/toggles_controller_test.rb index 6579ad0df..3a1d4fcdb 100644 --- a/test/controllers/assignments/toggles_controller_test.rb +++ b/test/controllers/assignments/toggles_controller_test.rb @@ -5,15 +5,21 @@ class Assignments::TogglesControllerTest < ActionDispatch::IntegrationTest sign_in_as :kevin end + test "new" do + get new_bucket_bubble_assignment_toggle_url(buckets(:writebook), bubbles(:logo)) + + assert_response :success + end + test "create" do assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: false, to: true do - post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id } + post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id }, as: :turbo_stream end - assert_redirected_to bubbles(:logo) + assert_response :success assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: true, to: false do - post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id } + post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id }, as: :turbo_stream end - assert_redirected_to bubbles(:logo) + assert_response :success end end