The personal finance app for everyone (by everyone)
Ruby
Line bill rows up with their headers and stack review rows on phones (#3921)
Guillem Arias Faustee05dd72573a9
diff --git a/app/components/DS/review_row.html.erb b/app/components/DS/review_row.html.erbnew file mode 100644index 0000000000..09ea2db7d8--- /dev/null+++ b/app/components/DS/review_row.html.erb@@ -0,0 +1,14 @@+<div class="@container">+ <div class="flex flex-col items-start gap-3 @md:flex-row @md:items-center @md:justify-between @md:gap-4 px-4 py-3">+ <%# wrap-anywhere lets an unspaced bank descriptor break, and shrinks the+ column's min-content width so it can't push past the card. %>+ <div class="min-w-0 max-w-full wrap-anywhere">+ <%= content %>+ </div>+ <% if actions? %>+ <div class="flex items-center gap-2 shrink-0">+ <%= actions %>+ </div>+ <% end %>+ </div>+</div>diff --git a/app/components/DS/review_row.rb b/app/components/DS/review_row.rbnew file mode 100644index 0000000000..d966673f0c--- /dev/null+++ b/app/components/DS/review_row.rb@@ -0,0 +1,22 @@+class DS::ReviewRow < DesignSystemComponent+ # A question and the buttons that answer it: text on the left, actions on+ # the right, and the actions dropped under the text when the row is narrower+ # than @md. Beside the text on a phone they took most of the row and cut+ # the question down to "VERIZON …". Extracted from the Bills "Needs review"+ # queue and the "Possible new bills" strip, which hand-built the same row+ # (#3921 review).+ #+ # The content is the text; the actions slot holds the buttons:+ #+ # <%= render DS::ReviewRow.new do |row| %>+ # <% row.with_actions do %>+ # <%= render DS::Link.new(text: t(".confirm"), variant: "primary", href: path, method: :post) %>+ # <% end %>+ # <p class="text-sm text-primary @md:truncate"><%= name %></p>+ # <% end %>+ #+ # The row is its own query container, so `@md:` classes in the content+ # (truncating a title once there's room beside the buttons) follow the row's+ # width, not the viewport's.+ renders_one :actions+enddiff --git a/app/views/bills/_occurrence.html.erb b/app/views/bills/_occurrence.html.erbindex f6c16221bc..f944500eb4 100644--- a/app/views/bills/_occurrence.html.erb+++ b/app/views/bills/_occurrence.html.erb@@ -13,7 +13,7 @@whole row took the secondary text below 3:1 in light mode. %><%# The row reads as interactive without dressing up as a button: a hover tintand the name underlining, the same cues the transaction list uses. %>-<div class="flex items-center gap-3 lg:gap-4 p-3 lg:p-4 transition-colors hover:bg-surface-hover">+<div class="flex items-center gap-3 @lg:gap-4 px-4 py-3 transition-colors hover:bg-surface-hover"><%# The bulk of the row is the inspect control. Only the trailing verb sitsoutside it, so there are no anchors inside anchors. The link has nopadding of its own, so its ring is pushed out into the row's: clear of@@ -23,7 +23,7 @@NEXT one and reported it unpaid. %><%= link_to bill_path(series, display: "drawer", occurrence: occurrence.id),data: { turbo_frame: "drawer", turbo_prefetch: false },- class: "flex items-center gap-3 lg:gap-4 min-w-0 flex-1 group rounded-lg focus-ring outline-offset-4" do %>+ class: "flex items-center gap-3 @lg:gap-4 min-w-0 flex-1 group rounded-lg focus-ring outline-offset-4" do %><%# A date rail, and only a date. It used to print "Overdue" beside asubline already reading "14 days overdue", which spent the row's onepiece of temporal context saying the same word twice. The colour stilldiff --git a/app/views/bills/index.html.erb b/app/views/bills/index.html.erbindex 13d7aa4045..f3d4d9b7d8 100644--- a/app/views/bills/index.html.erb+++ b/app/views/bills/index.html.erb@@ -76,30 +76,8 @@<div class="bg-container rounded-lg shadow-border-xs divide-y divide-subdued"><% @suggested_allocations.each do |suggestion| %><% series = suggestion.recurring_occurrence.recurring_transaction %>- <div class="flex items-center justify-between gap-4 px-4 py-3">- <div class="min-w-0">- <p class="text-sm text-primary truncate">- <%= t(".suggestion_line",- entry: suggestion.entry&.name.presence || t(".suggestion_unknown_entry"),- bill: series.display_name) %>- </p>- <%# The matcher stores WHY it proposed each of these. This line- used to show a bare percentage of that reasoning instead of- the reasoning, which told nobody anything they could judge. %>- <% reasons = bills_match_reasons(- suggestion.match_signals,- currency: suggestion.recurring_occurrence.currency,- expected: suggestion.recurring_occurrence.resolved_expected_amount,- actual: suggestion.entry&.amount&.abs,- due_on: suggestion.recurring_occurrence.effective_due_on,- paid_on: suggestion.paid_on- ) %>- <p class="text-xs text-secondary privacy-sensitive">- <%= format_money(suggestion.allocated_amount_money) %>- · <%= l(suggestion.paid_on, format: :short_with_year) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>- </p>- </div>- <div class="flex items-center gap-2 shrink-0">+ <%= render DS::ReviewRow.new do |row| %>+ <% row.with_actions do %><%= render DS::Link.new(text: t("recurring_occurrences.show.link_payment"),variant: "primary",@@ -112,8 +90,28 @@href: reject_recurring_allocation_path(suggestion),method: :post) %>- </div>- </div>+ <% end %>+ <p class="text-sm text-primary @md:truncate">+ <%= t(".suggestion_line",+ entry: suggestion.entry&.name.presence || t(".suggestion_unknown_entry"),+ bill: series.display_name) %>+ </p>+ <%# The matcher stores WHY it proposed each of these. This line+ used to show a bare percentage of that reasoning instead of+ the reasoning, which told nobody anything they could judge. %>+ <% reasons = bills_match_reasons(+ suggestion.match_signals,+ currency: suggestion.recurring_occurrence.currency,+ expected: suggestion.recurring_occurrence.resolved_expected_amount,+ actual: suggestion.entry&.amount&.abs,+ due_on: suggestion.recurring_occurrence.effective_due_on,+ paid_on: suggestion.paid_on+ ) %>+ <p class="text-xs text-secondary privacy-sensitive">+ <%= format_money(suggestion.allocated_amount_money) %>+ · <%= l(suggestion.paid_on, format: :short_with_year) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>+ </p>+ <% end %><% end %></div></div>diff --git a/app/views/recurring_transactions/_suggested_series.html.erb b/app/views/recurring_transactions/_suggested_series.html.erbindex a8c8fb8801..c20a8f2f49 100644--- a/app/views/recurring_transactions/_suggested_series.html.erb+++ b/app/views/recurring_transactions/_suggested_series.html.erb@@ -32,16 +32,8 @@<div class="bg-container rounded-lg divide-y divide-subdued"><% suggested.each do |suggestion| %>- <div class="flex items-center justify-between gap-4 px-4 py-3">- <div class="min-w-0">- <p class="text-sm font-medium text-primary truncate"><%= suggestion.display_name %></p>- <p class="text-xs text-secondary">- <span class="privacy-sensitive"><%= format_money(suggestion.amount_money.abs) %></span>- · <%= frequency_label(suggestion) %>- · <%= t("recurring_transactions.suggested.seen_count", count: suggestion.occurrence_count) %>- </p>- </div>- <div class="flex items-center gap-2 shrink-0">+ <%= render DS::ReviewRow.new do |row| %>+ <% row.with_actions do %><%= render DS::Link.new(text: t("recurring_transactions.suggested.confirm"),variant: "primary",@@ -54,8 +46,14 @@href: dismiss_recurring_transaction_path(suggestion),method: :post) %>- </div>- </div>+ <% end %>+ <p class="text-sm font-medium text-primary @md:truncate"><%= suggestion.display_name %></p>+ <p class="text-xs text-secondary">+ <span class="privacy-sensitive"><%= format_money(suggestion.amount_money.abs) %></span>+ · <%= frequency_label(suggestion) %>+ · <%= t("recurring_transactions.suggested.seen_count", count: suggestion.occurrence_count) %>+ </p>+ <% end %><% end %></div><% end %>diff --git a/test/components/DS/review_row_test.rb b/test/components/DS/review_row_test.rbnew file mode 100644index 0000000000..6f1677beec--- /dev/null+++ b/test/components/DS/review_row_test.rb@@ -0,0 +1,28 @@+require "test_helper"++class DS::ReviewRowTest < ViewComponent::TestCase+ test "renders the text and the actions in a row that queries its own width" do+ render_inline(DS::ReviewRow.new) do |row|+ row.with_actions { "<a href='/confirm'>Confirm</a>".html_safe }+ "<p>Netflix</p>".html_safe+ end++ assert_selector "div.\\@container > div.flex-col.\\@md\\:flex-row"+ assert_selector "div.min-w-0 p", text: "Netflix"+ assert_selector "div.shrink-0 a[href='/confirm']", text: "Confirm"+ end++ # An unspaced bank descriptor has a min-content width wider than a phone+ # card; without a break opportunity it scrolls the page sideways.+ test "lets an unspaced descriptor break" do+ render_inline(DS::ReviewRow.new) { "VERIZONWIRELESSPAYMENTREF1234567890" }++ assert_selector "div.min-w-0.wrap-anywhere"+ end++ test "omits the actions wrapper without actions" do+ render_inline(DS::ReviewRow.new) { "Netflix" }++ refute_selector "div.shrink-0"+ end+enddiff --git a/test/components/previews/review_row_component_preview.rb b/test/components/previews/review_row_component_preview.rbnew file mode 100644index 0000000000..de56a88f19--- /dev/null+++ b/test/components/previews/review_row_component_preview.rb@@ -0,0 +1,24 @@+class ReviewRowComponentPreview < ViewComponent::Preview+ # Below @md the buttons drop under the text; resize to see the row reflow.+ # @display container_classes max-w-[640px]+ def default+ render DS::ReviewRow.new do |row|+ row.with_actions do+ safe_join([+ render(DS::Button.new(text: "Confirm", variant: "primary")),+ render(DS::Button.new(text: "Dismiss", variant: "ghost"))+ ])+ end+ content_tag(:p, "VERIZON WIRELESS looks like a payment of Verizon", class: "text-sm text-primary @md:truncate")+ end+ end++ # An unspaced descriptor breaks instead of pushing past the card.+ # @display container_classes max-w-[320px]+ def unspaced_descriptor+ render DS::ReviewRow.new do |row|+ row.with_actions { render(DS::Button.new(text: "Confirm", variant: "primary")) }+ content_tag(:p, "POS-PURCHASE-VERIZONWIRELESS-AUTOPAY-REF1234567890", class: "text-sm text-primary @md:truncate")+ end+ end+enddiff --git a/test/system/bills_mobile_test.rb b/test/system/bills_mobile_test.rbindex 804e704d8b..4967b71757 100644--- a/test/system/bills_mobile_test.rb+++ b/test/system/bills_mobile_test.rb@@ -111,6 +111,66 @@ class BillsMobileTest < ApplicationSystemTestCaseassert_no_horizontal_scroll("the bill drawer")end+ # Bill rows padded 12px under a 16px section header, so every card had a 4px+ # step. And the review rows kept two buttons beside the text, which left a+ # phone "VERIZON …" for a question and "Neighborhood …" for a name.+ test "every list row lines up with its header and review rows read in full on a phone" do+ bill = @family.recurring_transactions.create!(+ name: "Verizon Wireless", account: accounts(:depository), amount: 95, currency: "USD",+ expected_day_of_month: Date.current.day, anchor_date: Date.current,+ last_occurrence_date: Date.current, next_expected_date: Date.current,+ status: "active", manual: true+ )+ RecurringAllocation.create!(+ recurring_occurrence: bill.recurring_occurrences.order(:due_on).first,+ state: :suggested, source: :auto_matched,+ allocated_amount: 95, currency: "USD", paid_on: Date.current+ )+ @family.recurring_transactions.create!(+ name: "Neighborhood Fitness Club", account: accounts(:depository), amount: 89.99, currency: "USD",+ expected_day_of_month: Date.current.day, anchor_date: Date.current,+ last_occurrence_date: Date.current, next_expected_date: Date.current + 1.month,+ status: "suggested", occurrence_count: 3+ )++ # Chrome will not shrink a window below ~500px, which leaves these lists+ # just past @md. Emulate the phone itself.+ page.driver.browser.execute_cdp("Emulation.setDeviceMetricsOverride", width: PHONE[0], height: PHONE[1], deviceScaleFactor: 1, mobile: true)+ visit bills_url+ question = I18n.t("bills.index.suggestion_line", entry: I18n.t("bills.index.suggestion_unknown_entry"), bill: bill.display_name)+ assert_text question+ assert_text "Neighborhood Fitness Club"++ offsets = page.evaluate_script(<<~JS)+ (() => {+ const visibleChild = (el) => [...el.children].find((c) => c.getClientRects().length > 0);+ return [...document.querySelectorAll(".\\\\@container a[href*='display=drawer']")].map((link) => {+ const header = link.closest(".\\\\@container").previousElementSibling.querySelector("p");+ return Math.round(visibleChild(link).getBoundingClientRect().left - header.getBoundingClientRect().left);+ });+ })()+ JS+ assert offsets.any?, "expected bill rows on the overview"+ assert_equal [ 0 ], offsets.uniq, "bill row content must share its section header's left edge"++ [ question, "Neighborhood Fitness Club" ].each do |text|+ layout = page.evaluate_script(<<~JS, text)+ ((text) => {+ const p = [...document.querySelectorAll("#main p")].find((el) => el.textContent.trim() === text);+ const button = p.closest(".py-3").querySelector("a, button");+ return {+ clipped: p.scrollWidth > p.clientWidth,+ below: button.getBoundingClientRect().top >= p.getBoundingClientRect().bottom+ };+ })(arguments[0])+ JS+ assert_not layout["clipped"], "#{text.inspect} is truncated"+ assert layout["below"], "the buttons for #{text.inspect} should sit under the text"+ end+ ensure+ page.driver.browser.execute_cdp("Emulation.clearDeviceMetricsOverride")+ end+# A green overflow assertion proves nothing unless it can go red, and this# one measures a property that is zero on most pages by accident. So: force# an overflow and confirm the measurement sees it.