From 6d716fa9324b71085753891a3dac422477bb971c Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 2 Apr 2025 11:21:30 +0200 Subject: [PATCH] Prevent turbo frames from loading edit forms when previwing cards in collections To render N cards we were loading 3xN turbo frames. I suspect this makes staging choke. --- app/helpers/bubbles_helper.rb | 9 ++++++ app/views/bubbles/_assignees.html.erb | 2 +- app/views/bubbles/_card.html.erb | 18 +++++------ app/views/bubbles/_card_mini.html.erb | 38 +++++++++++++----------- app/views/bubbles/_card_preview.html.erb | 3 ++ app/views/bubbles/_tags.html.erb | 2 +- app/views/bubbles/index.html.erb | 20 ++++++------- 7 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 app/views/bubbles/_card_preview.html.erb diff --git a/app/helpers/bubbles_helper.rb b/app/helpers/bubbles_helper.rb index 22f319362..93afa0f30 100644 --- a/app/helpers/bubbles_helper.rb +++ b/app/helpers/bubbles_helper.rb @@ -21,4 +21,13 @@ module BubblesHelper } end end + + def previewing_card + @previewing_bubble = true + yield + end + + def previewing_card? + @previewing_bubble + end end diff --git a/app/views/bubbles/_assignees.html.erb b/app/views/bubbles/_assignees.html.erb index 603c0ef7d..0ac5036c3 100644 --- a/app/views/bubbles/_assignees.html.erb +++ b/app/views/bubbles/_assignees.html.erb @@ -10,7 +10,7 @@ Assign - <%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) %> + <%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) unless previewing_card? %> <% end %> diff --git a/app/views/bubbles/_card.html.erb b/app/views/bubbles/_card.html.erb index 177b84b39..41bd539d2 100644 --- a/app/views/bubbles/_card.html.erb +++ b/app/views/bubbles/_card.html.erb @@ -1,9 +1,9 @@ <% cache bubble do %> -
- <%= link_to bubble.bucket.name, bubbles_path(bucket_ids: [ bubble.bucket ]), + <%= link_to bubble.bucket.name, bubbles_path(bucket_ids: [ bubble.bucket ]), class: "card__bucket txt-uppercase overflow-ellipsis txt-reversed" %> <%= render "bubbles/tags", bubble: bubble %> @@ -18,9 +18,9 @@ <% end %> <% else %> <%= form_with model: bubble, url: bucket_bubble_path(bubble.bucket, bubble), id: "bubble_form", data: { controller: "auto-save" } do |form| %> - <%= form.text_area :title, placeholder: "Name it…", - class: "input input--textarea full-width borderless txt-align-start #{ "fill-highlight" if bubble.creating? }", - autofocus: bubble.title.blank?, + <%= form.text_area :title, placeholder: "Name it…", + class: "input input--textarea full-width borderless txt-align-start #{ "fill-highlight" if bubble.creating? }", + autofocus: bubble.title.blank?, data: { action: "auto-save#change blur->auto-save#submit keydown.enter->auto-save#submit:prevent keydown.ctrl+enter->auto-save#submit:prevent" } %> <% end %> <% end %> @@ -29,8 +29,8 @@ <%= bubble_title(bubble) %> <% end %> - - <%= turbo_frame_tag dom_id(bubble, :stage_picker), src: new_bucket_bubble_stage_picker_path(bubble.bucket, bubble) %> + + <%= turbo_frame_tag dom_id(bubble, :stage_picker), src: new_bucket_bubble_stage_picker_path(bubble.bucket, bubble) unless previewing_card? %>
@@ -50,4 +50,4 @@ <% end %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/bubbles/_card_mini.html.erb b/app/views/bubbles/_card_mini.html.erb index 18f890cb1..2bb4cdf07 100644 --- a/app/views/bubbles/_card_mini.html.erb +++ b/app/views/bubbles/_card_mini.html.erb @@ -1,25 +1,27 @@ -
- <%= avatar_image_tag bubble.creator, loading: :lazy, class: "avatar" %> +<% previewing_card do %> +
+ <%= avatar_image_tag bubble.creator, loading: :lazy, class: "avatar" %> -
-

- <%= bubble.title %> -

-
<%= "Added to #{bubble.bucket.name} by #{bubble.creator.name}" %> <%= +
+

+ <%= bubble.title %> +

+
<%= "Added to #{bubble.bucket.name} by #{bubble.creator.name}" %> <%= days = (Date.current - bubble.created_at.to_date).to_i case days - when 0 then "today" - when 1 then "yesterday" - else "#{days} days ago".html_safe + when 0 then "today" + when 1 then "yesterday" + else "#{days} days ago".html_safe end %>
-
- <%= render "bubbles/assignees", bubble: bubble %> -
<%= render "bubbles/tags", bubble: bubble %>
+
+ <%= render "bubbles/assignees", bubble: bubble %> +
<%= render "bubbles/tags", bubble: bubble %>
+
-
- <%= link_to bucket_bubble_path(bubble.bucket, bubble), class: "card__link" do %> - <%= bubble_title(bubble) %> - <% end %> -
\ No newline at end of file + <%= link_to bucket_bubble_path(bubble.bucket, bubble), class: "card__link" do %> + <%= bubble_title(bubble) %> + <% end %> +
+<% end %> diff --git a/app/views/bubbles/_card_preview.html.erb b/app/views/bubbles/_card_preview.html.erb new file mode 100644 index 000000000..1065566cf --- /dev/null +++ b/app/views/bubbles/_card_preview.html.erb @@ -0,0 +1,3 @@ +<% previewing_card do %> + <%= render "bubbles/card", bubble: bubble %> +<% end %> diff --git a/app/views/bubbles/_tags.html.erb b/app/views/bubbles/_tags.html.erb index 9903f9af5..da0cf75ae 100644 --- a/app/views/bubbles/_tags.html.erb +++ b/app/views/bubbles/_tags.html.erb @@ -18,7 +18,7 @@ Add a tag - <%= turbo_frame_tag bubble, :tagging, src: new_bucket_bubble_tagging_toggle_path(bubble.bucket, bubble) %> + <%= turbo_frame_tag bubble, :tagging, src: new_bucket_bubble_tagging_toggle_path(bubble.bucket, bubble) unless previewing_card? %>
<% end %> diff --git a/app/views/bubbles/index.html.erb b/app/views/bubbles/index.html.erb index 1a9a31994..f8dfd9dea 100644 --- a/app/views/bubbles/index.html.erb +++ b/app/views/bubbles/index.html.erb @@ -28,7 +28,7 @@ In Collection - <%= form_with url: bubbles_path, method: :get, class: "flex flex-column full-width popup__list", + <%= form_with url: bubbles_path, method: :get, class: "flex flex-column full-width popup__list", data: { controller: "form" } do |form| %> <% @filter.as_params.except(:bucket_ids).each do |key, value| %> <%= filter_hidden_field_tag key, value %> @@ -37,10 +37,10 @@ <%= link_to bubbles_path(@filter.as_params.except(:bucket_ids)), class: "btn popup__item" do %> All collections <% end %> - + <% Current.user.buckets.order(:name).each do |bucket| %> + <% if (bucket = @filter.buckets.first) && @filter.buckets.one? %> @@ -115,7 +115,7 @@ aria-label="In stage…" aria-description="In stage…" data-dialog-target="dialog" data-action="turbo:before-cache@document->dialog#close"> In stage(s)… - <%= form_with url: bubbles_path, method: :get, class: "flex flex-column full-width popup__list", + <%= form_with url: bubbles_path, method: :get, class: "flex flex-column full-width popup__list", data: { controller: "form" } do |form| %> <% @filter.as_params.except(:stage_ids).each do |key, value| %> <%= filter_hidden_field_tag key, value %> @@ -124,7 +124,7 @@ <%= link_to bubbles_path(@filter.as_params.except(:stage_ids)), class: "btn popup__item" do %> All stages <% end %> - + <% workflow.stages.each do |stage| %>