From a830ec19993a0d5ce70f4aefafc466251256c2f4 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 21 Mar 2025 16:41:40 -0400 Subject: [PATCH 1/2] Extract an "assignees" partial pulling the avatars down from the "people" partial, and pulling the add button up from the "assignment" partial. The result is: - the "bubbles/sidebar/assignment" partial is just the dialog box - the "bubbles/assignees" partial contains everything about assignees - the "bubbles/people" partial makes one render call and I've introduced some turbo frames in the expectation of the next commit which will load the dialog in the background. --- app/views/bubbles/_assignees.html.erb | 18 ++++++++++++++++++ app/views/bubbles/_people.html.erb | 9 ++------- app/views/bubbles/sidebar/_assignment.html.erb | 11 +++-------- 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 app/views/bubbles/_assignees.html.erb diff --git a/app/views/bubbles/_assignees.html.erb b/app/views/bubbles/_assignees.html.erb new file mode 100644 index 000000000..f054bb3ed --- /dev/null +++ b/app/views/bubbles/_assignees.html.erb @@ -0,0 +1,18 @@ +<%= turbo_frame_tag bubble, :assignees do %> +
+ <% bubble.assignees.each do |assignee| %> + <%= avatar_tag assignee, loading: :lazy, class: "avatar" %> + <% end %> + +
+ + + + <%= render "bubbles/sidebar/assignment", bubble: bubble %> + +
+
+<% end %> diff --git a/app/views/bubbles/_people.html.erb b/app/views/bubbles/_people.html.erb index daf4e311f..68268ce55 100644 --- a/app/views/bubbles/_people.html.erb +++ b/app/views/bubbles/_people.html.erb @@ -6,12 +6,7 @@
Assigned -
- <% bubble.assignees.each do |assignee| %> - <%= avatar_tag assignee, loading: :lazy, class: "avatar" %> - <% end %> - <%= render "bubbles/sidebar/assignment", bubble: bubble, users: bubble.bucket.users.active %> -
+ <%= render "bubbles/assignees", bubble: bubble %>
- \ No newline at end of file + diff --git a/app/views/bubbles/sidebar/_assignment.html.erb b/app/views/bubbles/sidebar/_assignment.html.erb index 8610cf086..72dc42976 100644 --- a/app/views/bubbles/sidebar/_assignment.html.erb +++ b/app/views/bubbles/sidebar/_assignment.html.erb @@ -1,14 +1,9 @@ -
- - +<%= 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| %> - <% users.sort_by(&:name).each do |user| %> + <% bubble.bucket.users.active.sort_by(&:name).each do |user| %> -
+<% end %> From 44650cc36e42ff06c86275f1feff227bc6b5069c Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 21 Mar 2025 17:40:11 -0400 Subject: [PATCH 2/2] 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