Reload the assignees turbo frame when assigments are updated

Also, add a cache around the dropdown keyed on [bubble, bucket].
This commit is contained in:
Mike Dalessio
2025-03-21 17:40:11 -04:00
parent a830ec1999
commit 44650cc36e
4 changed files with 43 additions and 25 deletions
@@ -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
+1 -3
View File
@@ -10,9 +10,7 @@
<span class="for-screen-reader">Assign</span>
</button>
<turbo-frame id="<%= dom_id(bubble, :assignment) %>">
<%= render "bubbles/sidebar/assignment", bubble: bubble %>
</turbo-frame>
<%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) %>
</div>
</div>
<% end %>
+19 -17
View File
@@ -1,21 +1,23 @@
<%= turbo_frame_tag bubble, :assignment do %>
<dialog class="popup panel flex-column align-start gap-half fill-white shadow" data-dialog-target="dialog">
<strong class="popup__title margin-block-start-half pad-inline-half txt-nowrap">Assign this to…</strong>
<% cache [bubble, bubble.bucket] do %>
<%= turbo_frame_tag bubble, :assignment do %>
<dialog class="popup panel flex-column align-start gap-half fill-white shadow" data-dialog-target="dialog">
<strong class="popup__title margin-block-start-half pad-inline-half txt-nowrap">Assign this to…</strong>
<%= 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| %>
<div class="btn popup__item">
<%= form.check_box "assignee_id[]", {
checked: bubble.assigned_to?(user),
data: { action: "change->form#submit" },
id: dom_id(user, :assign),
include_hidden: false,
}, user.id %>
<%= 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| %>
<div class="btn popup__item">
<%= form.check_box "assignee_id[]", {
checked: bubble.assigned_to?(user),
data: { action: "change->form#submit" },
id: dom_id(user, :assign),
include_hidden: false,
}, user.id %>
<%= form.label "assignee_id[]", user.name, for: dom_id(user, :assign), class: "overflow-ellipsis" %>
<%= image_tag "check.svg", aria: { hidden: true }, size: 18, class: "checked flex-item-justify-end" %>
</div>
<%= form.label "assignee_id[]", user.name, for: dom_id(user, :assign), class: "overflow-ellipsis" %>
<%= image_tag "check.svg", aria: { hidden: true }, size: 18, class: "checked flex-item-justify-end" %>
</div>
<% end %>
<% end %>
<% end %>
</dialog>
</dialog>
<% end %>
<% end %>
@@ -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