Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Make bill rows follow the transaction row recipe (#4127)

Guillem Arias Faustef508e956ac0d
diff --git a/app/components/DS/section.html.erb b/app/components/DS/section.html.erb
index 9b867dcc53..ab606dd131 100644
--- a/app/components/DS/section.html.erb
+++ b/app/components/DS/section.html.erb
@@ -12,9 +12,9 @@
</div>
<% end %>
<% card = capture do %>
- <div class="@container bg-container rounded-lg shadow-border-xs divide-y divide-subdued">
+ <%= tag.div class: card_classes do %>
<%= content %>
- </div>
+ <% end %>
<% end %>
<%= tag.section class: container_classes do %>
diff --git a/app/components/DS/section.rb b/app/components/DS/section.rb
index 81cf5000c8..e1365ca848 100644
--- a/app/components/DS/section.rb
+++ b/app/components/DS/section.rb
@@ -14,7 +14,7 @@ class DS::Section < DesignSystemComponent
# card, not the screen.
renders_one :aside
- attr_reader :title, :count, :collapsible, :persist_key, :inset
+ attr_reader :title, :count, :collapsible, :persist_key, :inset, :divided
# @param title [String] an h2, so the sections join the page's outline
# @param count [Integer] the "· N" after the title
@@ -30,12 +30,15 @@ class DS::Section < DesignSystemComponent
# card. container-inset is the page's own colour in light mode, so the shell
# vanished there: headings floated, and the cards sat 4px inside every other
# card's edge. Dark mode showed it, so the page changed shape with the theme.
- def initialize(title:, count:, collapsible: false, persist_key: nil, inset: true)
+ # @param divided [Boolean] hairline between rows. Pass false for a list that
+ # reads like the transactions list, whose rows are spaced, not ruled.
+ def initialize(title:, count:, collapsible: false, persist_key: nil, inset: true, divided: true)
@title = title
@count = count
@collapsible = collapsible
@persist_key = persist_key
@inset = inset
+ @divided = divided
raise ArgumentError, "persist_key: needs collapsible: true" if persist_key && !collapsible
end
@@ -44,6 +47,10 @@ class DS::Section < DesignSystemComponent
"rounded-xl bg-surface-inset p-1" if inset
end
+ def card_classes
+ class_names("@container bg-container rounded-lg shadow-border-xs", "divide-y divide-subdued": divided)
+ end
+
def persist_data
{ controller: "persisted-disclosure", persisted_disclosure_key_value: persist_key } if persist_key
end
diff --git a/app/views/bills/_occurrence.html.erb b/app/views/bills/_occurrence.html.erb
index 075e5bb893..0448d1c177 100644
--- a/app/views/bills/_occurrence.html.erb
+++ b/app/views/bills/_occurrence.html.erb
@@ -11,9 +11,12 @@
but it recedes so the rows that want something from you carry the weight.
It recedes through lead_tone, on the name and the amount: opacity on the
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 tint
- and the name underlining, the same cues the transaction list uses. %>
-<div class="flex items-center gap-3 @lg:gap-4 px-4 py-3 transition-colors hover:bg-surface-hover">
+<%# Same recipe as a transaction row: p-3 growing to p-4, no hover tint, the
+ name underlining under the pointer, and clickable-row sending a click on any
+ bare part of the row (padding, the empty verb slot) to the drawer link. %>
+<div class="flex items-center gap-3 @lg:gap-4 p-3 @lg:p-4"
+ data-controller="clickable-row"
+ data-action="click->clickable-row#open">
<%# The bulk of the row is the inspect control. Only the trailing verb sits
outside it, so there are no anchors inside anchors. The link has no
padding of its own, so its ring is pushed out into the row's: clear of
@@ -22,8 +25,8 @@
the series' current occurrence, so opening a settled row described the
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 %>
+ data: { turbo_frame: "drawer", turbo_prefetch: false, clickable_row_target: "link" },
+ class: "flex items-center gap-3 @lg:gap-4 min-w-0 flex-1 rounded-lg focus-ring outline-offset-4" do %>
<%# A date rail, and only a date. It used to print "Overdue" beside a
subline already reading "14 days overdue", which spent the row's one
piece of temporal context saying the same word twice. The colour still
@@ -38,7 +41,7 @@
<% if series.merchant&.logo_url.present? %>
<%= image_tag Setting.transform_brand_fetch_url(series.merchant.logo_url),
- class: "w-9 h-9 rounded-full shrink-0",
+ class: "w-9 h-9 rounded-full shrink-0 border border-secondary",
loading: "lazy" %>
<% else %>
<%= render DS::FilledIcon.new(
@@ -50,7 +53,7 @@
<% end %>
<div class="min-w-0 flex-1">
- <p class="<%= lead_tone %> text-sm font-medium truncate group-hover:underline">
+ <p class="<%= lead_tone %> text-sm font-medium truncate hover:underline">
<%= series.display_name %>
</p>
<%# Says WHY this row needs a look, when it does, among the bill's other
diff --git a/app/views/bills/_occurrence_section.html.erb b/app/views/bills/_occurrence_section.html.erb
index 60221461dd..efda4bdedc 100644
--- a/app/views/bills/_occurrence_section.html.erb
+++ b/app/views/bills/_occurrence_section.html.erb
@@ -4,7 +4,7 @@
<% markers = bills_pay_period_markers(occurrences, pay_periods) %>
<%# No shell by default: bills/index stacks the month sections in one. %>
-<%= render DS::Section.new(title: title, count: occurrences.size, inset: false) do |section| %>
+<%= render DS::Section.new(title: title, count: occurrences.size, inset: false, divided: false) do |section| %>
<% section.with_aside { tag.p(meta, class: "text-xs text-secondary privacy-sensitive shrink-0") } if meta %>
<% occurrences.each do |occurrence| %>
<%# The marker belongs to the first row of its period, so it lands
diff --git a/test/components/DS/section_test.rb b/test/components/DS/section_test.rb
index 5fbf054ac4..585cdca28b 100644
--- a/test/components/DS/section_test.rb
+++ b/test/components/DS/section_test.rb
@@ -29,6 +29,14 @@ class DS::SectionTest < ViewComponent::TestCase
assert_selector "div.bg-container.rounded-lg > p", text: "Rent"
end
+ test "rules the rows apart unless asked not to" do
+ render_inline(DS::Section.new(title: "Rent", count: 1)) { "<p>Rent</p>".html_safe }
+ assert_selector "div.divide-y.divide-subdued > p"
+
+ render_inline(DS::Section.new(title: "Rent", count: 1, divided: false)) { "<p>Rent</p>".html_safe }
+ assert_no_selector ".divide-y"
+ end
+
# With both sidebars open a list is phone-width at a desktop viewport, so
# rows size themselves against the card, not the screen.
test "makes the card the query container for its rows" do
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index 98a907ced4..9f74031415 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -146,6 +146,16 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_match "Rent", response.body
end
+ test "a bill row opens its drawer from anywhere on the row, like a transaction row" do
+ create_bill(name: "Rent", amount: 1200)
+
+ get bills_url
+ assert_response :success
+
+ assert_select "[data-controller~=clickable-row] a[data-clickable-row-target=link][data-turbo-frame=drawer]"
+ assert_select "[data-controller~=clickable-row].hover\\:bg-surface-hover", count: 0
+ end
+
# A bill is something you owe. Income is not owed, an internal transfer is not owed,
# and a paused row was explicitly set aside, so none of them belong on the list.
test "index excludes income and inactive rows but shows debt payments" do
diff --git a/test/system/bills_mobile_test.rb b/test/system/bills_mobile_test.rb
index 1f17ef66d7..1dae895f1e 100644
--- a/test/system/bills_mobile_test.rb
+++ b/test/system/bills_mobile_test.rb
@@ -119,10 +119,10 @@ class BillsMobileTest < ApplicationSystemTestCase
assert_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 rows follow the transaction recipe: 12px padding below @lg, 16px
+ # above it. Section headings keep their own 16px inset. Review rows must
+ # still show their full text and put their buttons below it on a phone.
+ test "bill rows use responsive padding 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,
@@ -149,17 +149,7 @@ class BillsMobileTest < ApplicationSystemTestCase
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("h2");
- 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"
+ assert_bill_row_padding 12
[ question, "Neighborhood Fitness Club" ].each do |text|
layout = page.evaluate_script(<<~JS, text)
@@ -175,6 +165,13 @@ class BillsMobileTest < ApplicationSystemTestCase
assert_not layout["clipped"], "#{text.inspect} is truncated"
assert layout["below"], "the buttons for #{text.inspect} should sit under the text"
end
+
+ # Give the list itself enough width to cross @lg, not just the viewport.
+ page.driver.browser.execute_cdp("Emulation.clearDeviceMetricsOverride")
+ page.driver.browser.manage.window.resize_to(1920, 1400)
+ visit bills_url
+ assert_text bill.display_name
+ assert_bill_row_padding 16
ensure
page.driver.browser.execute_cdp("Emulation.clearDeviceMetricsOverride")
end
@@ -260,6 +257,18 @@ class BillsMobileTest < ApplicationSystemTestCase
end
private
+ def assert_bill_row_padding(expected)
+ assert_selector "[data-controller~='clickable-row'] a[data-clickable-row-target='link'][href*='display=drawer']"
+ paddings = page.evaluate_script(<<~JS)
+ [...document.querySelectorAll("a[data-clickable-row-target='link'][href*='display=drawer']")].map((link) => {
+ const row = link.closest("[data-controller~='clickable-row']");
+ const style = getComputedStyle(row);
+ return [style.paddingTop, style.paddingRight, style.paddingBottom, style.paddingLeft].map(parseFloat);
+ })
+ JS
+ assert_equal [ [ expected ] * 4 ], paddings.uniq, "bill rows must use #{expected}px padding on every side"
+ end
+
# The document must never be wider than the viewport, and neither must the
# scroll container inside it. An open drawer sits outside #main, in a scroll
# container of its own.