Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Speed up the transactions list: lazy dropdown frames, cached rows (#4475)

GFRadfe9fae6b96
diff --git a/app/components/DS/popover.html.erb b/app/components/DS/popover.html.erb
index a2030628a6..ba33268bbf 100644
--- a/app/components/DS/popover.html.erb
+++ b/app/components/DS/popover.html.erb
@@ -1,4 +1,4 @@
-<%= tag.div data: { controller: "DS--popover", DS__popover_placement_value: placement, DS__popover_offset_value: offset, DS__popover_mobile_fullwidth_value: mobile_fullwidth, testid: testid } do %>
+<%= tag.div data: { controller: "DS--popover", DS__popover_placement_value: placement, DS__popover_offset_value: offset, DS__popover_mobile_fullwidth_value: mobile_fullwidth, DS__popover_frame_id_value: frame_id, DS__popover_frame_src_value: frame_src, testid: testid } do %>
<% if variant == :icon %>
<%= render DS::Button.new(variant: "icon", icon: icon, aria_label: trigger_aria_label, aria: { haspopup: "dialog", expanded: "false", controls: panel_id }, data: { DS__popover_target: "button" }) %>
<% elsif variant == :button %>
@@ -25,7 +25,12 @@
<%= header %>
<%= tag.div class: class_names("py-1" => !no_padding) do %>
- <%= custom_content %>
+ <% if lazy_frame? %>
+ <%# Filled with the <turbo-frame> by the controller on first open. %>
+ <%= tag.div data: { DS__popover_target: "frame" } %>
+ <% else %>
+ <%= custom_content %>
+ <% end %>
<% end %>
<% end %>
</div>
diff --git a/app/components/DS/popover.rb b/app/components/DS/popover.rb
index 8361e9519f..faf73febb8 100644
--- a/app/components/DS/popover.rb
+++ b/app/components/DS/popover.rb
@@ -8,7 +8,8 @@
#
# Use `DS::Menu` instead when the panel is a flat list of clickable actions.
class DS::Popover < DesignSystemComponent
- attr_reader :variant, :avatar_url, :initials, :placement, :offset, :icon, :no_padding, :testid, :mobile_fullwidth, :max_width, :panel_id
+ attr_reader :variant, :avatar_url, :initials, :placement, :offset, :icon, :no_padding, :testid, :mobile_fullwidth, :max_width, :panel_id,
+ :frame_id, :frame_src
renders_one :button, ->(**button_options, &block) do
options_with_target = button_options.deep_dup
@@ -35,7 +36,11 @@ class DS::Popover < DesignSystemComponent
VARIANTS = %i[icon button avatar].freeze
- def initialize(variant: "icon", avatar_url: nil, initials: nil, placement: "bottom-end", offset: 12, icon: "more-horizontal", no_padding: false, testid: nil, mobile_fullwidth: true, max_width: nil, aria_label: nil)
+ # `frame_id:` / `frame_src:` make the panel a lazily loaded Turbo Frame: the
+ # `<turbo-frame>` is only created (and its `src` fetched) the first time the
+ # popover opens. Use it for panels repeated per list row, which are rarely
+ # opened.
+ def initialize(variant: "icon", avatar_url: nil, initials: nil, placement: "bottom-end", offset: 12, icon: "more-horizontal", no_padding: false, testid: nil, mobile_fullwidth: true, max_width: nil, aria_label: nil, frame_id: nil, frame_src: nil)
@variant = variant.to_sym
@avatar_url = avatar_url
@initials = initials
@@ -47,9 +52,16 @@ class DS::Popover < DesignSystemComponent
@mobile_fullwidth = mobile_fullwidth
@max_width = max_width
@aria_label = aria_label
+ @frame_id = frame_id
+ @frame_src = frame_src
@panel_id = "popover-#{SecureRandom.hex(4)}"
raise ArgumentError, "Invalid variant: #{@variant}" unless VARIANTS.include?(@variant)
+ raise ArgumentError, "frame_id and frame_src must be given together" if frame_id.present? ^ frame_src.present?
+ end
+
+ def lazy_frame?
+ frame_src.present?
end
# Accessible name for the trigger button. The `:avatar` variant has no
diff --git a/app/components/DS/popover_controller.js b/app/components/DS/popover_controller.js
index d020b65c46..120ca2d86a 100644
--- a/app/components/DS/popover_controller.js
+++ b/app/components/DS/popover_controller.js
@@ -15,13 +15,15 @@ import { Controller } from "@hotwired/stimulus";
* "collapsed" as the panel opens / closes.
*/
export default class extends Controller {
- static targets = ["button", "content"];
+ static targets = ["button", "content", "frame"];
static values = {
show: Boolean,
placement: { type: String, default: "bottom-end" },
offset: { type: Number, default: 6 },
mobileFullwidth: { type: Boolean, default: true },
+ frameId: String,
+ frameSrc: String,
};
connect() {
@@ -85,11 +87,32 @@ export default class extends Controller {
this.contentTarget.classList.toggle("hidden", !nextShow);
this.buttonTarget.setAttribute("aria-expanded", nextShow.toString());
if (nextShow) {
+ this.mountFrame();
this.update();
this.focusFirstElement();
}
};
+ // Lazy panels (frameSrc value) get their <turbo-frame> on first open only;
+ // connecting it with a src makes Turbo fetch it. Until then the panel is an
+ // empty slot, so a page with hundreds of popovers ships no frame markup
+ // for the ones never opened. Turbo marks the frame aria-busy while loading.
+ mountFrame() {
+ if (!this.hasFrameTarget || !this.frameSrcValue) return;
+ if (this.frameTarget.childElementCount > 0) return;
+
+ const frame = document.createElement("turbo-frame");
+ frame.id = this.frameIdValue;
+ frame.setAttribute("src", this.frameSrcValue);
+ const placeholder = document.createElement("div");
+ placeholder.className = "p-6 flex items-center justify-center";
+ const skeleton = document.createElement("div");
+ skeleton.className = "h-4 w-24 rounded-md bg-container-inset animate-pulse";
+ placeholder.append(skeleton);
+ frame.append(placeholder);
+ this.frameTarget.replaceChildren(frame);
+ }
+
// Used as an action (a Cancel button in the panel), close() returns focus
// to the trigger like Escape does, instead of dropping it to <body>.
close(event) {
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index a3e754b4df..7fb659ddc3 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -61,6 +61,86 @@ module TransactionsHelper
entry.split_child? && Current.user.show_split_grouped? && params_grouped == "true"
end
+ # Files whose content shapes a cached transaction row; see
+ # transaction_row_cache_key.
+ TRANSACTION_ROW_SOURCES = %w[
+ app/views/transactions/_transaction.html.erb
+ app/views/transactions/_transaction_category.html.erb
+ app/views/transactions/_transfer_match.html.erb
+ app/views/categories/_*.html.erb
+ app/views/tags/_*.html.erb
+ app/views/investment_activity/_*.html.erb
+ app/helpers/transactions_helper.rb
+ app/helpers/categories_helper.rb
+ app/components/DS/*.{rb,html.erb}
+ config/locales/**/*.yml
+ ].freeze
+
+ TRANSACTION_ROW_SOURCES_DIGEST = Digest::SHA256.hexdigest(
+ TRANSACTION_ROW_SOURCES.flat_map { |pattern| Dir[Rails.root.join(pattern).to_s] }.sort.map { |file| File.read(file) }.join
+ ).first(16)
+
+ # Fragment cache key for one row of the transactions list. Everything the
+ # row shows or branches on is part of the key, so any change renders the
+ # row fresh:
+ #
+ # - the records it reads (entry, transaction, tags, merchant, transfer and
+ # its other leg, whose kind and category an inflow row depends on, the
+ # security a brokerage activity shows a logo for)
+ # - the displayed attributes of the accounts and categories it shows, and
+ # whether an account supports trades (a crypto account's subtype); their
+ # record versions would change on every balance sync or category pick
+ # - per-user or per-request state (locale, user, family display settings,
+ # whether the user may annotate the account or see the counterpart,
+ # whether the entry is a split parent, grouped rendering, view context)
+ # - a digest of the row's templates, the helpers and DS components it
+ # renders and the locale files (TRANSACTION_ROW_SOURCES), plus the image
+ # build or app version, so a deploy with new markup or translations never
+ # serves old rows, also for source builds without BUILD_COMMIT_SHA; skip_digest is on because the ERB
+ # dependency tracker cannot digest DS::* components (see
+ # account_sidebar_tabs)
+ # - the Brandfetch settings that shape logo URLs
+ #
+ # Add a file to TRANSACTION_ROW_SOURCES when the row starts rendering it.
+ def transaction_row_cache_key(entry, view_ctx:, in_split_group:)
+ transaction = entry.entryable
+ transfer = transaction.transfer
+ outflow_leg = transaction.transfer_as_outflow.present?
+ counterpart = transfer && (outflow_leg ? transfer.to_account : transfer.from_account)
+ other_leg = transfer && (outflow_leg ? transfer.inflow_transaction : transfer.outflow_transaction)
+ split_parent = @split_parent_entry_ids ? @split_parent_entry_ids.include?(entry.id) : entry.split_parent?
+ account_key = ->(account) { account && [ account.id, account.name, account.accountable_type, account.supports_trades? ] }
+ category_key = ->(category) { category && [ category.id, category.name, category.color, category.lucide_icon ] }
+
+ [
+ "transaction_row",
+ TRANSACTION_ROW_SOURCES_DIGEST,
+ ENV["BUILD_COMMIT_SHA"].presence || (@app_version ||= Sure.version.to_s),
+ I18n.locale,
+ Current.user&.id,
+ Current.family&.currency,
+ Current.family&.locale,
+ view_ctx,
+ in_split_group,
+ split_parent,
+ can_annotate_account?(entry.account),
+ counterpart.present? && @accessible_account_ids&.include?(counterpart.id),
+ Setting.brand_fetch_logo_size,
+ Setting.brand_fetch_client_id.presence&.then { |id| Digest::SHA256.hexdigest(id) },
+ entry.cache_key_with_version,
+ transaction.cache_key_with_version,
+ account_key.(entry.account),
+ category_key.(transaction.category),
+ transaction.merchant&.cache_key_with_version,
+ transaction.tags.map(&:cache_key_with_version).sort,
+ transfer&.cache_key_with_version,
+ other_leg&.cache_key_with_version,
+ account_key.(counterpart),
+ (category_key.(other_leg.category) if transfer && !outflow_leg),
+ transaction.activity_security&.cache_key_with_version
+ ]
+ end
+
# Whether the current user may annotate (e.g. re-tag) entries on this
# account. Memoized per request so list rows don't query per row.
def can_annotate_account?(account)
diff --git a/app/views/categories/_menu.html.erb b/app/views/categories/_menu.html.erb
index 321f91f9c7..25fb96526f 100644
--- a/app/views/categories/_menu.html.erb
+++ b/app/views/categories/_menu.html.erb
@@ -1,20 +1,22 @@
-<%# locals: (transaction:, in_split_group: false) %>
+<%# locals: (transaction:, in_split_group: false, variant: "desktop") %>
-<%= render DS::Popover.new(variant: "button") do |popover| %>
+<%# The dropdown frame is created when the popover opens (DS::Popover frame_src),
+ not rendered per row. The badge inside the trigger is only the one this
+ variant's breakpoints can show: the mobile cell (below md) never reaches
+ the lg pill, the desktop cell still needs the icon badge between md and lg. %>
+<%= render DS::Popover.new(
+ variant: "button",
+ frame_id: "category_dropdown",
+ frame_src: category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id, grouped: in_split_group)
+ ) do |popover| %>
<% popover.with_button(class: "block w-full overflow-hidden") do %>
- <div class="hidden min-w-0 w-full lg:flex">
- <%= render partial: "categories/badge", locals: { category: transaction.category } %>
- </div>
+ <% if variant.to_s == "desktop" %>
+ <div class="hidden min-w-0 w-full lg:flex">
+ <%= render partial: "categories/badge", locals: { category: transaction.category } %>
+ </div>
+ <% end %>
<div class="flex lg:hidden">
<%= render partial: "categories/badge_mobile", locals: { category: transaction.category } %>
</div>
<% end %>
-
- <% popover.with_custom_content do %>
- <%= turbo_frame_tag "category_dropdown", src: category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id, grouped: in_split_group), loading: :lazy do %>
- <div class="p-6 flex items-center justify-center">
- <p class="text-sm text-secondary animate-pulse"><%= t(".loading") %></p>
- </div>
- <% end %>
- <% end %>
<% end %>
diff --git a/app/views/tags/_menu.html.erb b/app/views/tags/_menu.html.erb
index c1c62b4819..b8a3a162a5 100644
--- a/app/views/tags/_menu.html.erb
+++ b/app/views/tags/_menu.html.erb
@@ -9,18 +9,12 @@
from the drawer), and read-only shares can't change tags at all. %>
<%= render "tags/summary", transaction: transaction, variant: variant, editable: false %>
<% else %>
- <%= render DS::Popover.new(variant: "button", aria_label: t(".label")) do |popover| %>
+ <%# The dropdown frame is created when the popover opens (DS::Popover
+ frame_src) rather than rendered for every row. %>
+ <%= render DS::Popover.new(variant: "button", aria_label: t(".label"), frame_id: "tag_dropdown", frame_src: tag_dropdown_path(entry_id: entry.id)) do |popover| %>
<% popover.with_button(class: "flex w-full min-w-0 items-center") do %>
<%= render "tags/summary", transaction: transaction, variant: variant %>
<% end %>
-
- <% popover.with_custom_content do %>
- <%= turbo_frame_tag "tag_dropdown", src: tag_dropdown_path(entry_id: entry.id), loading: :lazy do %>
- <div class="p-6 flex items-center justify-center">
- <p class="text-sm text-secondary animate-pulse"><%= t(".loading") %></p>
- </div>
- <% end %>
- <% end %>
<% end %>
<% end %>
</div>
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
index 3fbdacccd6..4123be9952 100644
--- a/app/views/transactions/_transaction.html.erb
+++ b/app/views/transactions/_transaction.html.erb
@@ -1,13 +1,18 @@
<%# locals: (entry:, balance_trend: nil, view_ctx: "global", in_split_group: false) %>
<% transaction = entry.entryable %>
+
+<%# Cached per row; see TransactionsHelper#transaction_row_cache_key for what
+ busts it; list any new partial or component in TRANSACTION_ROW_SOURCES.
+ A pending transfer match is never cached: its confirm and reject forms
+ embed the session's CSRF token, and the session may not be loaded yet. %>
+<% cache_unless transaction.transfer&.pending?, transaction_row_cache_key(entry, view_ctx: view_ctx, in_split_group: in_split_group), expires_in: 12.hours, skip_digest: true do %>
<% transaction_security_logo_url = transaction.activity_security&.display_logo_url %>
<% open_path = if transaction.transfer?
transaction.transfer.present? ? transfer_path(transaction.transfer) : entry_path(entry)
else
in_split_group ? entry_path(entry, grouped: true) : entry_path(entry)
end %>
-
<%= turbo_frame_tag dom_id(entry) do %>
<%= turbo_frame_tag dom_id(transaction) do %>
<div class="group flex lg:grid lg:grid-cols-12 items-center text-primary text-sm font-medium p-3 lg:p-4 <%= "pl-8 lg:pl-12" if in_split_group %>"
@@ -247,3 +252,4 @@
</div>
<% end %>
<% end %>
+<% end %>
diff --git a/app/views/transactions/_transaction_category.html.erb b/app/views/transactions/_transaction_category.html.erb
index d92889708f..0eedcfc9ea 100644
--- a/app/views/transactions/_transaction_category.html.erb
+++ b/app/views/transactions/_transaction_category.html.erb
@@ -2,18 +2,20 @@
<div id="<%= dom_id(transaction, "category_menu_#{variant}") %>" class="min-w-0 overflow-hidden">
<% if transaction.category_editable? %>
- <%= render "categories/menu", transaction: transaction, in_split_group: in_split_group %>
+ <%= render "categories/menu", transaction: transaction, in_split_group: in_split_group, variant: variant %>
<% else %>
<% category = read_only_category(transaction) %>
<% set_on_outflow = transaction.category_set_on_transfer_outflow? %>
- <div class="hidden lg:flex items-center gap-1 min-w-0">
- <div class="<%= "opacity-60 cursor-not-allowed" if set_on_outflow %>">
- <%= render "categories/badge", category: category %>
+ <% if variant.to_s == "desktop" %>
+ <div class="hidden lg:flex items-center gap-1 min-w-0">
+ <div class="<%= "opacity-60 cursor-not-allowed" if set_on_outflow %>">
+ <%= render "categories/badge", category: category %>
+ </div>
+ <% if set_on_outflow %>
+ <%= render DS::Tooltip.new(text: t("transactions.transaction_category.set_on_outflow")) %>
+ <% end %>
</div>
- <% if set_on_outflow %>
- <%= render DS::Tooltip.new(text: t("transactions.transaction_category.set_on_outflow")) %>
- <% end %>
- </div>
+ <% end %>
<div class="flex lg:hidden">
<%= render "categories/badge_mobile", category: category %>
</div>
diff --git a/config/locales/views/categories/ca.yml b/config/locales/views/categories/ca.yml
index 619864531f..f9747c1c62 100644
--- a/config/locales/views/categories/ca.yml
+++ b/config/locales/views/categories/ca.yml
@@ -33,8 +33,6 @@ ca:
empty: No s'han trobat categories
new: Nova categoria
merge: Fusiona categories
- menu:
- loading: Carregant...
new:
new_category: Nova categoria
update:
diff --git a/config/locales/views/categories/de.yml b/config/locales/views/categories/de.yml
index 59546cb915..f099ddb0b5 100644
--- a/config/locales/views/categories/de.yml
+++ b/config/locales/views/categories/de.yml
@@ -31,8 +31,6 @@ de:
new: Neue Kategorie
delete_all: Alle löschen
merge: Kategorien zusammenführen
- menu:
- loading: Wird geladen...
new:
new_category: Neue Kategorie
update:
diff --git a/config/locales/views/categories/en.yml b/config/locales/views/categories/en.yml
index 528619b24a..74f7c2a7c0 100644
--- a/config/locales/views/categories/en.yml
+++ b/config/locales/views/categories/en.yml
@@ -48,8 +48,6 @@ en:
sources_label: Categories to merge
sources_hint: Selected categories will be deleted after their transactions and budget lines move to the target. Do not select the target as a source.
submit: Merge selected
- menu:
- loading: Loading...
new:
new_category: New category
perform_merge:
diff --git a/config/locales/views/categories/es.yml b/config/locales/views/categories/es.yml
index 17b4b8adde..a0f54009ee 100644
--- a/config/locales/views/categories/es.yml
+++ b/config/locales/views/categories/es.yml
@@ -40,8 +40,6 @@ es:
sources_label: Categorías a fusionar
sources_hint: Las categorías seleccionadas se eliminarán después de que sus transacciones y líneas de presupuesto se muevan al destino. No selecciones el destino como origen.
submit: Fusionar seleccionadas
- menu:
- loading: Cargando...
new:
new_category: Nueva categoría
perform_merge:
diff --git a/config/locales/views/categories/fr.yml b/config/locales/views/categories/fr.yml
index f73e5178b1..a0736b3bda 100644
--- a/config/locales/views/categories/fr.yml
+++ b/config/locales/views/categories/fr.yml
@@ -37,8 +37,6 @@ fr:
new: Nouvelle catégorie
unlock_categories: Déverrouiller la création de catégories
locked: Les catégories sont verrouillées. Déverrouillez-les pour ajouter une nouvelle catégorie.
- menu:
- loading: Chargement...
merge:
description: Sélectionnez une catégorie cible et les catégories à y fusionner. Les transactions et lignes budgétaires correspondantes seront déplacées vers la cible.
select_target: Sélectionner la catégorie cible...
diff --git a/config/locales/views/categories/hu.yml b/config/locales/views/categories/hu.yml
index 1410c25fd7..c915d82be8 100644
--- a/config/locales/views/categories/hu.yml
+++ b/config/locales/views/categories/hu.yml
@@ -31,8 +31,6 @@ hu:
delete_all: Összes törlése
empty: Nem található kategória
new: Új kategória
- menu:
- loading: Betöltés...
new:
new_category: Új kategória
update:
diff --git a/config/locales/views/categories/it.yml b/config/locales/views/categories/it.yml
index d91281cc9a..5414b0a3c5 100644
--- a/config/locales/views/categories/it.yml
+++ b/config/locales/views/categories/it.yml
@@ -41,8 +41,6 @@ it:
sources_label: Categorie da unire
sources_hint: Le categorie selezionate verranno eliminate dopo che le loro transazioni e righe di budget si saranno spostate nella destinazione. Non selezionare la destinazione come sorgente.
submit: Unisci selezionate
- menu:
- loading: Caricamento...
new:
new_category: Nuova categoria
perform_merge:
diff --git a/config/locales/views/categories/nb.yml b/config/locales/views/categories/nb.yml
index 3ef4e69412..10d711abb3 100644
--- a/config/locales/views/categories/nb.yml
+++ b/config/locales/views/categories/nb.yml
@@ -21,8 +21,6 @@ nb:
categories_incomes: Inntektskategorier
empty: Ingen kategorier funnet
new: Ny kategori
- menu:
- loading: Laster...
new:
new_category: Ny kategori
update:
diff --git a/config/locales/views/categories/nl.yml b/config/locales/views/categories/nl.yml
index 8d9c5f6ea6..a96d67328c 100644
--- a/config/locales/views/categories/nl.yml
+++ b/config/locales/views/categories/nl.yml
@@ -21,8 +21,6 @@ nl:
categories_incomes: Inkomenscategorieën
empty: Geen categorieën gevonden
new: Nieuwe categorie
- menu:
- loading: Laden...
new:
new_category: Nieuwe categorie
update:
diff --git a/config/locales/views/categories/pl.yml b/config/locales/views/categories/pl.yml
index 4d083dca8f..9e6df67c68 100644
--- a/config/locales/views/categories/pl.yml
+++ b/config/locales/views/categories/pl.yml
@@ -33,8 +33,6 @@ pl:
empty: Nie znaleziono kategorii
merge: Scal kategorie
new: Nowa kategoria
- menu:
- loading: Ładowanie...
merge:
description: Wybierz kategorię docelową oraz kategorie do scalenia z nią. Pasujące
transakcje i pozycje budżetu przeniosą się do kategorii docelowej.
diff --git a/config/locales/views/categories/pt-BR.yml b/config/locales/views/categories/pt-BR.yml
index d928bedf52..becbf75085 100644
--- a/config/locales/views/categories/pt-BR.yml
+++ b/config/locales/views/categories/pt-BR.yml
@@ -21,8 +21,6 @@ pt-BR:
categories_incomes: Categorias de receitas
empty: Nenhuma categoria encontrada
new: Nova categoria
- menu:
- loading: Carregando...
new:
new_category: Nova categoria
update:
diff --git a/config/locales/views/categories/pt-PT.yml b/config/locales/views/categories/pt-PT.yml
index 73fcaf01ce..b6d71e6d3d 100644
--- a/config/locales/views/categories/pt-PT.yml
+++ b/config/locales/views/categories/pt-PT.yml
@@ -41,8 +41,6 @@ pt-PT:
sources_label: Categorias a unir
sources_hint: As categorias selecionadas serão eliminadas depois de as suas transações e linhas de orçamento serem movidas para o destino. Não selecione o destino como origem.
submit: Unir selecionadas
- menu:
- loading: A carregar...
new:
new_category: Nova categoria
perform_merge:
diff --git a/config/locales/views/categories/ro.yml b/config/locales/views/categories/ro.yml
index c18f70a4d2..38adee3f71 100644
--- a/config/locales/views/categories/ro.yml
+++ b/config/locales/views/categories/ro.yml
@@ -21,8 +21,6 @@ ro:
categories_incomes: Categorii de venituri
empty: Nicio categorie găsită
new: Categorie nouă
- menu:
- loading: Se încarcă...
new:
new_category: Categorie nouă
update:
diff --git a/config/locales/views/categories/ru.yml b/config/locales/views/categories/ru.yml
index 9de9bd0177..0d0aa32c43 100644
--- a/config/locales/views/categories/ru.yml
+++ b/config/locales/views/categories/ru.yml
@@ -33,8 +33,6 @@ ru:
empty: Категории не найдены
merge: Объединить категории
new: Новая категория
- menu:
- loading: Загрузка...
merge:
description: Выберите целевую категорию и категории, которые нужно в неё объединить.
Соответствующие операции и строки бюджета будут перемещены.
diff --git a/config/locales/views/categories/tr.yml b/config/locales/views/categories/tr.yml
index fa53d2d521..6399732f04 100644
--- a/config/locales/views/categories/tr.yml
+++ b/config/locales/views/categories/tr.yml
@@ -33,8 +33,6 @@ tr:
empty: Hiç kategori bulunamadı
merge: Kategorileri birleştir
new: Yeni kategori
- menu:
- loading: Yükleniyor...
merge:
description: Hedef bir kategori ve bu kategoriyle birleştirilecek kategorileri
seçin. Eşleşen işlemler ve bütçe satırları hedefe taşınacaktır.
diff --git a/config/locales/views/categories/uk.yml b/config/locales/views/categories/uk.yml
index d573cf906c..81aac26481 100644
--- a/config/locales/views/categories/uk.yml
+++ b/config/locales/views/categories/uk.yml
@@ -41,8 +41,6 @@ uk:
sources_label: "Категорії для об'єднання"
sources_hint: "Вибрані категорії буде видалено після переміщення їхніх транзакцій та бюджетних рядків до цільової. Не вибирайте цільову категорію як джерело."
submit: "Об'єднати вибране"
- menu:
- loading: "Завантаження..."
new:
new_category: "Нова категорія"
perform_merge:
diff --git a/config/locales/views/categories/vi.yml b/config/locales/views/categories/vi.yml
index 63439dcbcf..d0a065d33b 100644
--- a/config/locales/views/categories/vi.yml
+++ b/config/locales/views/categories/vi.yml
@@ -32,8 +32,6 @@ vi:
delete_all: Xóa tất cả
empty: Không tìm thấy danh mục
new: Danh mục mới
- menu:
- loading: Đang tải...
new:
new_category: Danh mục mới
update:
diff --git a/config/locales/views/categories/zh-CN.yml b/config/locales/views/categories/zh-CN.yml
index 26a7decb5b..7179b7e187 100644
--- a/config/locales/views/categories/zh-CN.yml
+++ b/config/locales/views/categories/zh-CN.yml
@@ -33,8 +33,6 @@ zh-CN:
empty: 未找到分类
new: 新建分类
merge: 合并分类
- menu:
- loading: 正在加载...
new:
new_category: 新建分类
update:
diff --git a/config/locales/views/categories/zh-TW.yml b/config/locales/views/categories/zh-TW.yml
index 080d2daa82..d07b31005c 100644
--- a/config/locales/views/categories/zh-TW.yml
+++ b/config/locales/views/categories/zh-TW.yml
@@ -41,8 +41,6 @@ zh-TW:
sources_label: 要合併的分類
sources_hint: 所選分類的交易與預算項目移到目標分類後,這些分類會被刪除。請勿將目標分類選為來源。
submit: 合併所選項目
- menu:
- loading: 載入中...
new:
new_category: 新增分類
perform_merge:
diff --git a/config/locales/views/tags/en.yml b/config/locales/views/tags/en.yml
index f374d56bff..3b252010c6 100644
--- a/config/locales/views/tags/en.yml
+++ b/config/locales/views/tags/en.yml
@@ -19,7 +19,6 @@ en:
delete_all: Delete all
menu:
label: Edit tags
- loading: Loading tags...
new:
new: New tag
summary:
diff --git a/test/components/DS/popover_test.rb b/test/components/DS/popover_test.rb
new file mode 100644
index 0000000000..8d2a0c7786
--- /dev/null
+++ b/test/components/DS/popover_test.rb
@@ -0,0 +1,32 @@
+require "test_helper"
+
+class DS::PopoverTest < ViewComponent::TestCase
+ test "renders the custom content inside the panel" do
+ render_inline(DS::Popover.new(variant: "button")) do |popover|
+ popover.with_button(text: "Open")
+ popover.with_custom_content { "Panel body" }
+ end
+
+ assert_selector "[data-controller='DS--popover']"
+ assert_selector "[data-ds--popover-target='content']", text: "Panel body", visible: :all
+ assert_no_selector "[data-ds--popover-target='frame']", visible: :all
+ assert_no_selector "[data-ds--popover-frame-src-value]"
+ end
+
+ test "a lazy frame panel ships an empty slot and the frame details for the controller" do
+ render_inline(DS::Popover.new(variant: "button", frame_id: "tag_dropdown", frame_src: "/tag/dropdown?entry_id=1")) do |popover|
+ popover.with_button(text: "Open")
+ end
+
+ assert_selector "[data-controller='DS--popover'][data-ds--popover-frame-id-value='tag_dropdown'][data-ds--popover-frame-src-value='/tag/dropdown?entry_id=1']"
+ assert_selector "[data-ds--popover-target='frame']", visible: :all
+ assert_no_selector "turbo-frame", visible: :all
+ end
+
+ test "frame id and src must come together" do
+ error = assert_raises(ArgumentError) { DS::Popover.new(frame_id: "tag_dropdown") }
+ assert_match(/frame_id and frame_src/, error.message)
+ error = assert_raises(ArgumentError) { DS::Popover.new(frame_src: "/tag/dropdown") }
+ assert_match(/frame_id and frame_src/, error.message)
+ end
+end
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index d39797fa14..35052e60c0 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -746,6 +746,33 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
assert_equal original_tag_ids, read_only_entry.reload.entryable.tag_ids
end
+ # The category and tag dropdowns are fetched when their popover opens, so
+ # rows carry no <turbo-frame> markup for them.
+ test "transaction rows defer the category and tag dropdown frames until opened" do
+ get transactions_url
+
+ assert_response :success
+ assert_select "turbo-frame#category_dropdown", count: 0
+ assert_select "turbo-frame#tag_dropdown", count: 0
+
+ transaction = @entry.entryable
+ %w[desktop mobile].each do |variant|
+ assert_select "##{dom_id(transaction, "category_menu_#{variant}")} [data-ds--popover-frame-id-value='category_dropdown'][data-ds--popover-frame-src-value=?]",
+ category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id, grouped: false)
+ end
+ assert_select "[data-ds--popover-frame-id-value='tag_dropdown'][data-ds--popover-frame-src-value=?]",
+ tag_dropdown_path(entry_id: @entry.id), count: 2
+ end
+
+ test "the mobile category cell renders only the icon badge, the desktop cell both" do
+ get transactions_url
+
+ assert_response :success
+ transaction = @entry.entryable
+ assert_select "##{dom_id(transaction, "category_menu_mobile")} [data-testid='category-name']", count: 0
+ assert_select "##{dom_id(transaction, "category_menu_desktop")} [data-testid='category-name']", count: 1
+ end
+
test "transaction rows show tags" do
@entry.entryable.update!(tag_ids: [ tags(:one).id ])
@@ -2198,7 +2225,7 @@ end
get transactions_url
assert_response :success
- assert_select "##{dom_id(outflow, "category_menu_desktop")} turbo-frame#category_dropdown"
+ assert_select "##{dom_id(outflow, "category_menu_desktop")} [data-ds--popover-frame-id-value='category_dropdown']"
end
test "update drops a category sent for a matched transfer's inflow leg" do
diff --git a/test/views/transactions/tag_summary_view_test.rb b/test/views/transactions/tag_summary_view_test.rb
index 77d8f60aaf..96c1edaf48 100644
--- a/test/views/transactions/tag_summary_view_test.rb
+++ b/test/views/transactions/tag_summary_view_test.rb
@@ -111,7 +111,7 @@ class Transactions::TagSummaryViewTest < ActionView::TestCase
html = Nokogiri::HTML.fragment(render(partial: "transactions/transaction", locals: { entry: entry.reload, balance_trend: nil, view_ctx: "global" }))
summary = html.at_css("##{dom_id(entry.transaction, "tag_summary_desktop")}")
- assert_nil html.at_css("turbo-frame#tag_dropdown")
+ assert_nil html.at_css("[data-ds--popover-frame-id-value='tag_dropdown']"), "read-only rows have no picker popover"
assert summary.at_css("[aria-describedby] [tabindex='0']"), "read-only trigger should be keyboard focusable"
end
@@ -121,7 +121,10 @@ class Transactions::TagSummaryViewTest < ActionView::TestCase
html = Nokogiri::HTML.fragment(render_row)
- assert html.at_css("turbo-frame#tag_dropdown")
+ # The picker's <turbo-frame> is created by the popover on first open; the
+ # row only carries the frame's id and src.
+ assert html.at_css("[data-ds--popover-frame-id-value='tag_dropdown'][data-ds--popover-frame-src-value]")
+ assert_nil html.at_css("turbo-frame#tag_dropdown")
assert_nil html.at_css("##{dom_id(@transaction, "tag_summary_desktop")} [tabindex='0']")
end
@@ -157,7 +160,7 @@ class Transactions::TagSummaryViewTest < ActionView::TestCase
html = Nokogiri::HTML.fragment(render(partial: "transactions/transaction", locals: { entry: outflow_entry, balance_trend: nil, view_ctx: "global" }))
assert html.at_css("##{dom_id(outflow_tx, "tag_summary_desktop")}")
- assert_nil html.at_css("turbo-frame#tag_dropdown")
+ assert_nil html.at_css("[data-ds--popover-frame-id-value='tag_dropdown']")
assert_empty html.at_css("##{dom_id(outflow_tx, "tag_summary_desktop")}").text.strip
end
diff --git a/test/views/transactions/transaction_row_cache_test.rb b/test/views/transactions/transaction_row_cache_test.rb
new file mode 100644
index 0000000000..a3778f039f
--- /dev/null
+++ b/test/views/transactions/transaction_row_cache_test.rb
@@ -0,0 +1,145 @@
+require "test_helper"
+
+class Transactions::TransactionRowCacheTest < ActionView::TestCase
+ include TransactionsHelper
+
+ setup do
+ Current.session = Session.create!(user: users(:family_admin))
+
+ @accessible_account_ids = Current.user.accessible_accounts.pluck(:id).to_set
+ @split_parent_entry_ids = Set.new
+
+ @entry = entries(:transaction)
+ @transaction = @entry.transaction
+ @category = categories(:food_and_drink)
+ @transaction.update!(category: @category)
+
+ # The test environment uses :null_store, which would make every assertion
+ # below pass without exercising the cache.
+ controller.perform_caching = true
+ controller.cache_store = ActiveSupport::Cache::MemoryStore.new
+ end
+
+ test "an unchanged row is served from the cache" do
+ original_name = @entry.name
+ assert_includes render_row, original_name
+
+ # update_all leaves updated_at alone, so only a cache hit can show the old name.
+ Entry.where(id: @entry.id).update_all(name: "Renamed behind the cache")
+
+ html = render_row
+ assert_includes html, original_name
+ assert_not_includes html, "Renamed behind the cache"
+ end
+
+ test "editing the entry, category, tags or account renders the row fresh" do
+ render_row
+
+ @entry.update!(name: "Renamed entry")
+ assert_includes render_row, "Renamed entry"
+
+ @category.update!(name: "Renamed category")
+ assert_includes render_row, "Renamed category"
+
+ tag = Tag.create!(family: @entry.account.family, name: "Fresh tag")
+ @transaction.update!(tag_ids: [ tag.id ])
+ assert_includes render_row, "Fresh tag"
+
+ tag.update!(name: "Renamed tag")
+ assert_includes render_row, "Renamed tag"
+
+ @entry.account.update!(name: "Renamed account")
+ assert_includes render_row, "Renamed account"
+ end
+
+ test "the key depends on the viewer, locale, view context and grouping" do
+ base = row_key
+
+ assert_not_equal base, row_key(view_ctx: "account")
+ assert_not_equal base, row_key(in_split_group: true)
+ assert_not_equal base, I18n.with_locale(:de) { row_key }
+
+ Current.session = Session.create!(user: users(:family_member))
+ assert_not_equal base, row_key
+ end
+
+ test "renaming the merchant renders the row fresh, a balance sync does not" do
+ merchant = merchants(:netflix)
+ @transaction.update!(merchant: merchant)
+ render_row
+
+ merchant.update!(name: "Renamed merchant")
+ assert_includes render_row, "Renamed merchant"
+
+ # A sync rewrites the account balance; the row doesn't show it, so it
+ # stays cached (update_all keeps the entry's own version unchanged).
+ Entry.where(id: @entry.id).update_all(name: "Renamed behind the cache")
+ @entry.account.update!(balance: @entry.account.balance + 1)
+ assert_not_includes render_row, "Renamed behind the cache"
+ end
+
+ test "an inflow row's key follows the outflow leg and the counterpart account" do
+ transfer = transfers(:one)
+ inflow_entry = transfer.inflow_transaction.entry
+ base = row_key(entry: inflow_entry)
+
+ transfer.outflow_transaction.update!(kind: "loan_payment")
+ assert_not_equal base, (base = row_key(entry: inflow_entry))
+
+ transfer.outflow_transaction.update!(category: @category)
+ assert_not_equal base, (base = row_key(entry: inflow_entry))
+
+ @category.update!(name: "Renamed category")
+ assert_not_equal base, (base = row_key(entry: inflow_entry))
+
+ transfer.from_account.update!(name: "Renamed counterpart")
+ assert_not_equal base, row_key(entry: inflow_entry)
+ end
+
+ # The confirm and reject forms of a pending transfer match embed the
+ # session's CSRF token, which a cached row would hand to other sessions.
+ test "a row with a pending transfer match is never served from the cache" do
+ @entry = transfers(:one).tap { |t| t.update!(status: "pending") }.inflow_transaction.entry
+ render_row
+
+ Entry.where(id: @entry.id).update_all(name: "Renamed behind the cache")
+
+ assert_includes render_row, "Renamed behind the cache"
+ end
+
+ # A crypto account's subtype decides whether its rows show the activity
+ # label or the category menu, and changing it leaves the account's
+ # displayed attributes as they were.
+ test "the key changes when the account starts supporting trades" do
+ base = row_key
+
+ Account.any_instance.stubs(:supports_trades?).returns(true)
+
+ assert_not_equal base, row_key
+ end
+
+ test "the key carries a digest of the row's templates and components" do
+ TransactionsHelper::TRANSACTION_ROW_SOURCES.each do |pattern|
+ assert Dir[Rails.root.join(pattern).to_s].any?, "#{pattern} matches no file"
+ end
+
+ assert_includes row_key, TransactionsHelper::TRANSACTION_ROW_SOURCES_DIGEST
+ end
+
+ test "the key changes with the BUILD_COMMIT_SHA of the deployed image" do
+ base = row_key
+
+ with_env_overrides("BUILD_COMMIT_SHA" => "abc1234") do
+ assert_not_equal base, row_key
+ end
+ end
+
+ private
+ def row_key(entry: @entry, view_ctx: "global", in_split_group: false)
+ transaction_row_cache_key(entry.reload, view_ctx: view_ctx, in_split_group: in_split_group)
+ end
+
+ def render_row
+ render(partial: "transactions/transaction", locals: { entry: @entry.reload, balance_trend: nil, view_ctx: "global" })
+ end
+end