The personal finance app for everyone (by everyone)
Ruby
Move transfer matching controls beside transaction amounts (#4303)
Sure Admin (bot)9e61f38e4770
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erbindex fc22593bdf..f68324e83f 100644--- a/app/views/transactions/_transaction.html.erb+++ b/app/views/transactions/_transaction.html.erb@@ -139,10 +139,6 @@<%= icon "corner-down-right", size: "sm", color: "current" %></span><% end %>-- <% if transaction.transfer.present? %>- <%= render "transactions/transfer_match", transaction: transaction %>- <% end %></div><div class="md:hidden flex shrink-0 min-w-0 max-w-1/2 has-[[data-tag-empty]]:hidden">@@ -193,7 +189,7 @@</div></div>- <div class="hidden md:flex min-w-0 items-center gap-1 col-span-3 pr-2">+ <div class="hidden md:flex md:shrink-0 min-w-0 items-center gap-1 col-span-3 pr-2"><% if entry.account.supports_trades? && !transaction.transfer? %><%# For investment/crypto accounts, show activity label instead of category %><%= render "investment_activity/quick_edit_badge", entry: entry, entryable: transaction %>@@ -202,23 +198,31 @@<% end %></div>- <div class="hidden md:flex md:w-1/5 md:shrink-0 lg:w-auto min-w-0 items-center col-span-2 pr-2" data-tag-fit-bounds="1">- <%= render "tags/menu", entry: entry, transaction: transaction, variant: :desktop %>- </div>+ <div class="col-span-4 ml-auto lg:ml-0 md:flex-none flex lg:flex-wrap items-center justify-end gap-2 lg:gap-4 min-w-0">+ <div class="<%= class_names("hidden md:flex md:w-40 lg:w-auto lg:flex-1 min-w-7 items-center", "lg:hidden": transaction.transfer? && transaction.tags.empty?) %>" data-tag-fit-bounds="1">+ <%= render "tags/menu", entry: entry, transaction: transaction, variant: :desktop %>+ </div>- <div class="shrink-0 col-span-4 lg:col-span-2 ml-auto flex items-center justify-end gap-2 <%= "opacity-50" if entry.excluded %>">- <%# Protection indicator - shows on hover when entry is protected from sync %>- <% if entry.protected_from_sync? && !entry.excluded? %>- <%= link_to entry_path(entry),- data: { turbo_frame: "drawer", turbo_prefetch: false },- class: "invisible group-hover:visible transition-opacity",- title: t("entries.protection.tooltip") do %>- <%= icon "lock", size: "sm", class: "text-secondary" %>+ <div class="<%= class_names("flex justify-end min-w-0", transaction.transfer&.pending? ? "flex-col-reverse items-end gap-1 lg:flex-row lg:flex-wrap lg:items-center lg:gap-2" : "items-center gap-2 lg:gap-4") %>">+ <% if transaction.transfer.present? %>+ <%= render "transactions/transfer_match", transaction: transaction %><% end %>- <% end %>- <%= content_tag :p,- transaction.transfer? && view_ctx == "global" ? "+/- #{format_money(entry.amount_money.abs)}" : format_money(-entry.amount_money),- class: ["privacy-sensitive", "text-green-600": entry.amount.negative?] %>++ <div class="shrink-0 ml-auto flex items-center justify-end gap-2 <%= "opacity-50" if entry.excluded %>">+ <%# Protection indicator - shows on hover when entry is protected from sync %>+ <% if entry.protected_from_sync? && !entry.excluded? %>+ <%= link_to entry_path(entry),+ data: { turbo_frame: "drawer", turbo_prefetch: false },+ class: "invisible group-hover:visible transition-opacity",+ title: t("entries.protection.tooltip") do %>+ <%= icon "lock", size: "sm", class: "text-secondary" %>+ <% end %>+ <% end %>+ <%= content_tag :p,+ transaction.transfer? && view_ctx == "global" ? "+/- #{format_money(entry.amount_money.abs)}" : format_money(-entry.amount_money),+ class: ["privacy-sensitive", "text-green-600": entry.amount.negative?] %>+ </div>+ </div></div></div><% end %>diff --git a/app/views/transactions/_transfer_match.html.erb b/app/views/transactions/_transfer_match.html.erbindex c7c8cf8de7..749e21b6f9 100644--- a/app/views/transactions/_transfer_match.html.erb+++ b/app/views/transactions/_transfer_match.html.erb@@ -1,6 +1,6 @@<%# locals: (transaction:) %>-<div id="<%= dom_id(transaction, "transfer_match") %>" class="flex items-center gap-1">+<div id="<%= dom_id(transaction, "transfer_match") %>" class="flex flex-wrap items-center justify-end gap-1 min-w-0 max-w-full"><% if transaction.transfer.confirmed? %><span title="<%= transaction.transfer.payment? ? t("transactions.transfer_match.payment_confirmed") : t("transactions.transfer_match.transfer_confirmed") %>"><%= icon "link-2", size: "sm", class: "text-secondary" %>@@ -23,19 +23,23 @@) %></span>- <%= button_to transfer_path(transaction.transfer, transfer: { status: "confirmed" }),- method: :patch,- class: "text-secondary flex items-center justify-center cursor-pointer",- title: t("transactions.transfer_match.confirm_match") do %>- <%= icon "check", size: "sm", class: "text-secondary hover:text-primary" %>- <% end %>+ <div class="flex items-center gap-1">+ <%= render DS::Button.new(+ variant: :icon, size: :sm, icon: "check",+ href: transfer_path(transaction.transfer, transfer: { status: "confirmed" }),+ method: :patch,+ title: t("transactions.transfer_match.confirm_match"),+ aria: { label: t("transactions.transfer_match.confirm_match") }+ ) %>- <%= button_to transfer_path(transaction.transfer, transfer: { status: "rejected" }),- method: :patch,- data: { turbo: false },- class: "text-secondary hover:text-primary flex items-center justify-center cursor-pointer",- title: t("transactions.transfer_match.reject_match") do %>- <%= icon "x", size: "sm", class: "text-subdued hover:text-primary" %>- <% end %>+ <%= render DS::Button.new(+ variant: :icon, size: :sm, icon: "x",+ href: transfer_path(transaction.transfer, transfer: { status: "rejected" }),+ method: :patch,+ data: { turbo: false },+ title: t("transactions.transfer_match.reject_match"),+ aria: { label: t("transactions.transfer_match.reject_match") }+ ) %>+ </div><% end %></div>diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.ymlindex c9cf987a79..16611bf9dc 100644--- a/config/locales/views/transactions/en.yml+++ b/config/locales/views/transactions/en.yml@@ -168,7 +168,7 @@ en:split_label: "Split"transfer_match:auto_matched: Auto-matched- auto_matched_short: A/M+ auto_matched_short: Autoconfirm_match: Confirm matchpayment_confirmed: Payment is confirmedreject_match: Reject matchdiff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rbindex 4186a349cf..479c96cb58 100644--- a/test/system/transactions_test.rb+++ b/test/system/transactions_test.rb@@ -140,6 +140,78 @@ class TransactionsTest < ApplicationSystemTestCaseassert_text @transaction.nameend+ test "confirms an auto-matched transfer from beside the amount" do+ outflow = create_transaction("Payment to credit card", Date.current, 100)+ inflow = create_transaction("Payment received", Date.current, -100, account: accounts(:credit_card))+ transfer = Transfer.create!(outflow_transaction: outflow.entryable, inflow_transaction: inflow.entryable)+ match = "##{dom_id(outflow.entryable, :transfer_match)}"+ visit transactions_url(per_page: @page_size)++ assert_selector match+ assert_no_selector "[data-tag-fit-bounds='0.5'] #{match}"++ within(match) { click_button I18n.t("transactions.transfer_match.confirm_match") }++ assert_no_selector "#{match} button"+ assert transfer.reload.confirmed?++ page.current_window.resize_to(390, 900)+ visit transactions_url(per_page: @page_size)+ indicator_bounds = find(match).evaluate_script("this.getBoundingClientRect().toJSON()")+ amount_bounds = find("##{dom_id(outflow)} p.privacy-sensitive").evaluate_script("this.getBoundingClientRect().toJSON()")+ assert_in_delta indicator_bounds["y"] + indicator_bounds["height"] / 2,+ amount_bounds["y"] + amount_bounds["height"] / 2, 1,+ "confirmed matches should stay beside the amount on phones"+ end++ test "rejects an auto-matched transfer from a mobile row" do+ outflow = create_transaction("Payment to credit card", Date.current, 100)+ inflow = create_transaction("Payment received", Date.current, -100, account: accounts(:credit_card))+ transfer = Transfer.create!(outflow_transaction: outflow.entryable, inflow_transaction: inflow.entryable)+ match = "##{dom_id(outflow.entryable, :transfer_match)}"+ page.current_window.resize_to(390, 900)+ visit transactions_url(per_page: @page_size)++ within(match) do+ assert_text I18n.t("transactions.transfer_match.auto_matched_short")+ assert_selector "button[aria-label='#{I18n.t("transactions.transfer_match.confirm_match")}']"+ click_button I18n.t("transactions.transfer_match.reject_match")+ end++ assert_no_selector match+ assert_not Transfer.exists?(transfer.id)+ assert Entry.exists?(outflow.id)+ assert Entry.exists?(inflow.id)+ end++ test "keeps long auto-matched tablet and desktop rows contained" do+ @user.update!(show_ai_sidebar: false)+ outflow = create_transaction("Bank of America online payment with a long bank descriptor", Date.current, 4321.09, tags: [ tags(:one), tags(:two) ])+ inflow = create_transaction("Payment received", Date.current, -4321.09, account: accounts(:credit_card))+ Transfer.create!(outflow_transaction: outflow.entryable, inflow_transaction: inflow.entryable)+ outflow.entryable.update!(kind: "funds_movement", extra: { "plaid" => { "pending" => true }, "potential_posted_match" => { "entry_id" => inflow.id, "confidence" => "low" } })+ [ 820, 1024, 1440 ].each do |width|+ page.current_window.resize_to(width, 900)+ visit transactions_url(per_page: @page_size)++ row = find("##{dom_id(outflow)} [data-controller='clickable-row']")+ row_bounds = row.evaluate_script("this.getBoundingClientRect().toJSON()")+ amount_bounds = row.find("p.privacy-sensitive").evaluate_script("this.getBoundingClientRect().toJSON()")+ tags_bounds = row.find("[id^='tag_summary_desktop']").evaluate_script("this.getBoundingClientRect().toJSON()")+ match_bounds = row.find("[id^='transfer_match']").evaluate_script("this.getBoundingClientRect().toJSON()")+ controls_bounds = row.find("[data-tag-fit-bounds='1']").find(:xpath, "..").evaluate_script("this.getBoundingClientRect().toJSON()")++ assert_operator match_bounds["left"], :>=, controls_bounds["left"], "matching controls must not spill into the category at #{width}px"+ assert_operator match_bounds["right"], :<=, controls_bounds["right"]++ assert_operator amount_bounds["right"], :<=, row_bounds["right"]+ assert_operator amount_bounds["left"], :>=, row_bounds["left"]+ assert_operator amount_bounds["height"], :<=, 24, "the amount should stay on one line at #{width}px"+ assert tags_bounds["right"] <= match_bounds["left"] || tags_bounds["bottom"] <= match_bounds["top"],+ "tags and matching controls must not overlap at #{width}px"+ end+ end+test "can toggle tags from the transaction row" dotransaction = @transaction.entryablesummary_id = dom_id(transaction, "tag_summary_desktop")@@ -166,6 +238,8 @@ class TransactionsTest < ApplicationSystemTestCasesummary = "##{dom_id(transaction, "tag_summary_desktop")}"cell = "document.querySelector('#{summary}').closest('[data-tag-fit-bounds]')"+ # Control the actual available width even when the tag cell is a flex item.+ page.execute_script("#{cell}.style.flex = 'none'")page.execute_script("#{cell}.style.width = '400px'")assert_selector "#{summary} [data-tag-fit-target=full]", text: "Ab"assert_no_selector "#{summary} [data-tag-fit-target=compact]"