Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fold the bill's page into its drawer (#3981)

Guillem Arias Fauste3ffcb0458fde
diff --git a/app/components/DS/disclosure.html.erb b/app/components/DS/disclosure.html.erb
index 007b09ac98..5b10224f14 100644
--- a/app/components/DS/disclosure.html.erb
+++ b/app/components/DS/disclosure.html.erb
@@ -17,9 +17,12 @@
</div>
<% end %>
<% else %>
+ <%# The chevrons follow their own <details>, not `group-open:`, which
+ matches any open ancestor group: a disclosure inside an open one
+ would show open while closed. %>
<div class="flex items-center gap-3">
<% if align == :left %>
- <%= helpers.icon "chevron-right", class: "group-open:rotate-90 motion-safe:transition-transform motion-safe:duration-150" %>
+ <%= helpers.icon "chevron-right", class: "[details[open]>summary_&]:rotate-90 motion-safe:transition-transform motion-safe:duration-150" %>
<% end %>
<%= tag.span class: class_names("font-medium", align == :left ? "text-sm text-primary" : "text-xs uppercase text-secondary") do %>
@@ -28,7 +31,7 @@
</div>
<% if align == :right %>
- <%= helpers.icon "chevron-down", class: "group-open:rotate-180 motion-safe:transition-transform motion-safe:duration-150" %>
+ <%= helpers.icon "chevron-down", class: "[details[open]>summary_&]:rotate-180 motion-safe:transition-transform motion-safe:duration-150" %>
<% end %>
<% end %>
<% end %>
diff --git a/app/controllers/bills_controller.rb b/app/controllers/bills_controller.rb
index 03172d728d..f7f463ab5f 100644
--- a/app/controllers/bills_controller.rb
+++ b/app/controllers/bills_controller.rb
@@ -137,16 +137,41 @@ class BillsController < ApplicationController
end
# One bill's complete story: current state, history, what is coming, cost.
+ # It lives in the drawer, the way a transaction or a budget category does.
def show
@series = Current.family.recurring_transactions
.accessible_by(Current.user)
.includes(:merchant)
.find(params[:id])
- # The drawer names the cycle its row was opened from; the bill's own page
- # has no cycle in mind and asks the series. Looked up through the series, so
- # an id from another bill resolves to nothing rather than to someone else's
- # occurrence.
+ # Outside a frame (a new tab, a pasted link, a notification) there is
+ # nothing to open the drawer into, so the overview renders around it and
+ # the layout's drawer frame loads the bill. A redirect back to this same
+ # URL (Pause on any drawer opened since) refreshes the list, not the bill.
+ unless turbo_frame_request?
+ unless came_from?(request.path)
+ @drawer_src = bill_path(@series, display: "drawer", occurrence: params[:occurrence].presence)
+ end
+ index
+ render :index unless performed?
+ return
+ end
+
+ # The deep part loads into a lazy frame inside the drawer, so opening a
+ # bill costs no more than its summary, and the aggregates behind the chart
+ # and the per-year totals run only once it is scrolled to.
+ if params[:display] == "history"
+ @history = @series.recurring_occurrences.closed.order(due_on: :desc).limit(12).includes(allocations: :entry)
+ @upcoming = @series.schedule.occurrences_between(Date.current + 1, Date.current + 400).first(3)
+ @analytics = paid_analytics
+ load_deep_extras
+ render :history, layout: false
+ return
+ end
+
+ # The drawer names the cycle its row was opened from; anything else asks
+ # the series. Looked up through the series, so an id from another bill
+ # resolves to nothing rather than to someone else's occurrence.
@current_occurrence =
if params[:occurrence].present?
@series.recurring_occurrences.find_by(id: params[:occurrence]) || @series.current_occurrence
@@ -154,47 +179,10 @@ class BillsController < ApplicationController
@series.current_occurrence
end
- @history = @series.recurring_occurrences.closed.order(due_on: :desc).limit(12).includes(:allocations)
- @upcoming = @series.schedule.occurrences_between(Date.current + 1, Date.current + 400).first(3)
-
- # What each settled cycle actually cost. The frozen `expected_amount` is an
- # estimate, so reading it here would report averages of estimates beside the
- # per-year totals below, which are sums of real payments.
- paid_amounts = RecurringAllocation.confirmed
- .joins(:recurring_occurrence)
- .where(recurring_occurrences: {
- recurring_transaction_id: @series.id,
- status: "paid"
- })
- .group(:recurring_occurrence_id)
- .sum(:allocated_amount)
- .values
- @analytics = if paid_amounts.any?
- {
- average: Money.new(paid_amounts.sum / paid_amounts.size, @series.currency),
- lowest: Money.new(paid_amounts.min, @series.currency),
- highest: Money.new(paid_amounts.max, @series.currency),
- annualized: @series.monthly_equivalent_amount * 12,
- ytd: Money.new(ytd_paid_total, @series.currency)
- }
- end
-
- load_summary_extras
-
- # Outside a frame (a new tab, a pasted link) there is nothing to open the
- # dialog into, so the same URL is the bill's page.
- if params[:display] == "drawer" && turbo_frame_request?
- # A pending suggestion is the one thing that changes what the drawer
- # should offer, so it is worth the one query.
- @drawer_suggestion = @current_occurrence&.allocations&.suggested&.first
- render :drawer, layout: false
- return
- end
-
- # Only the bill's own page carries the deep material, so only it pays for
- # the aggregates behind it.
- load_deep_extras
- render
+ # A pending suggestion is the one thing that changes what the drawer
+ # should offer, so it is worth the one query.
+ @drawer_suggestion = @current_occurrence&.allocations&.suggested&.first
+ render :drawer, layout: false
end
private
@@ -233,10 +221,28 @@ class BillsController < ApplicationController
end
helper_method :paycheck_income_plans?
- # What the drawer needs: the handful of payments that actually settled
- # this bill lately. Cheap enough to run on every row someone opens.
- def load_summary_extras
- @recent_allocations = confirmed_allocations.includes(:entry).order(paid_on: :desc, created_at: :desc).limit(6)
+ # What each settled cycle actually cost. The frozen `expected_amount` is an
+ # estimate, so reading it here would report averages of estimates beside the
+ # per-year totals, which are sums of real payments.
+ def paid_analytics
+ paid_amounts = RecurringAllocation.confirmed
+ .joins(:recurring_occurrence)
+ .where(recurring_occurrences: {
+ recurring_transaction_id: @series.id,
+ status: "paid"
+ })
+ .group(:recurring_occurrence_id)
+ .sum(:allocated_amount)
+ .values
+ return if paid_amounts.empty?
+
+ {
+ average: Money.new(paid_amounts.sum / paid_amounts.size, @series.currency),
+ lowest: Money.new(paid_amounts.min, @series.currency),
+ highest: Money.new(paid_amounts.max, @series.currency),
+ annualized: @series.monthly_equivalent_amount * 12,
+ ytd: Money.new(ytd_paid_total, @series.currency)
+ }
end
# The bill's financial story: a year of payments by month, per-year totals,
diff --git a/app/controllers/concerns/recurring_feature_guardable.rb b/app/controllers/concerns/recurring_feature_guardable.rb
index 9961c97979..4c067be922 100644
--- a/app/controllers/concerns/recurring_feature_guardable.rb
+++ b/app/controllers/concerns/recurring_feature_guardable.rb
@@ -33,4 +33,10 @@ module RecurringFeatureGuardable
rescue URI::InvalidURIError
fallback
end
+
+ # Whether the request was made from `path` on this host. Compared by path,
+ # so /bills/1 matches whatever query string the referer carried.
+ def came_from?(path)
+ (back = url_from(request.referer)) && URI(back).path == path
+ end
end
diff --git a/app/controllers/recurring_transactions_controller.rb b/app/controllers/recurring_transactions_controller.rb
index acf21d47f0..c7d8653aa1 100644
--- a/app/controllers/recurring_transactions_controller.rb
+++ b/app/controllers/recurring_transactions_controller.rb
@@ -243,7 +243,12 @@ class RecurringTransactionsController < ApplicationController
end
flash[:notice] = t(income ? "recurring_transactions.deleted_income" : "recurring_transactions.deleted")
- redirect_back_or_to bills_path
+ # Back to a visited /bills/:id would reopen, or 404 on, what was just removed.
+ if came_from?(bill_path(@recurring_transaction))
+ redirect_to bills_path
+ else
+ redirect_back_or_to bills_path
+ end
end
protected
diff --git a/app/views/bills/_detail.html.erb b/app/views/bills/_detail.html.erb
index 9b8ec2d2a2..85cb5a20f0 100644
--- a/app/views/bills/_detail.html.erb
+++ b/app/views/bills/_detail.html.erb
@@ -1,159 +1,129 @@
-<%# locals: (series:, current_occurrence:, history:, upcoming:, analytics:,
- payment_history:, yearly_metrics:, last_account:,
- recent_allocations:, dense: false) %>
+<%# locals: (series:, history:, upcoming:, analytics:, payment_history:,
+ yearly_metrics:, last_account:) %>
-<%# The single definition of what a bill's detail *is*.
-
- The inline expansion and the drawer were two templates over one controller
- action, so they drifted: open a bill from the Overview and you got the
- matching rules, the twelve-month chart and its recent payments; open the
- same bill from All bills and you got upcoming dates, notes and the
- averages instead. Same bill, different facts, decided by which list you
- happened to click from.
-
- They stay two presentations, because an inline row and a drawer want
- different widths, but only one of them decides what a bill consists of.
- `dense` picks the layout; it never picks the content. %>
-
-<% columns = dense ? "" : "md:grid-cols-2 md:divide-x md:divide-y-0" %>
+<%# The sections under bills/_summary in a bill's drawer, collapsible like a
+ transaction's or a budget category's: why it matches and what it has
+ cost, what is coming, what settled and what paid it, and the notes. The
+ summary already states the current cycle and the subscription state, so
+ none of that repeats here. %>
<div class="space-y-4">
- <%= render "bills/cancelled_notice", series: series %>
-
- <%# What is owed right now leads the page above this partial. With no open
- cycle there is nothing for that card to say, so the expectation is
- stated here instead. %>
- <% unless current_occurrence %>
- <div class="bg-container-inset rounded-lg p-3">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.next_payment") %></p>
- <p class="text-lg font-medium text-primary privacy-sensitive">
- <%= "~" if series.has_amount_variance? %><%= format_money(Money.new(series.amount.abs, series.currency)) %>
- </p>
- <% if series.next_expected_date.present? %>
- <p class="text-xs text-secondary"><%= t("bills.detail.around", date: bills_upcoming_date(series.next_expected_date)) %></p>
- <% end %>
- </div>
- <% end %>
-
- <%# Subscription state: a trial about to convert, a renewal date, a
- cancellation already recorded. These lived only on the Subscriptions
- tab, which meant they were invisible from every other route to the
- same bill. %>
- <%= render "bills/state_chips", series: series %>
-
- <%# Why this bill matches what it matches, in words rather than engine terms. %>
- <div class="space-y-1.5">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.rules") %></p>
- <div class="flex flex-wrap gap-1.5">
- <%= render DS::Pill.new(label: t("bills.detail.rule_named", name: series.merchant&.name.presence || series.name), tone: :neutral, marker: false) %>
- <% amount_label = series.has_amount_variance? ?
- t("bills.detail.rule_amount_range", min: format_money(series.expected_amount_min_money), max: format_money(series.expected_amount_max_money)) :
- format_money(Money.new(series.amount.abs, series.currency)) %>
- <span class="privacy-sensitive"><%= render DS::Pill.new(label: amount_label, tone: :neutral, marker: false) %></span>
- <%= render DS::Pill.new(label: frequency_label(series), tone: :neutral, marker: false) %>
- <% if series.account %>
- <%= render DS::Pill.new(label: series.account.name, tone: :neutral, marker: false) %>
- <% end %>
- </div>
-
- <%# What the app has learned from corrections, prepared by
- BillsHelper#bills_matcher_hints. %>
- <% hints = bills_matcher_hints(series) %>
- <% if hints[:aliases].any? %>
- <p class="text-xs text-secondary">
- <%= t("bills.detail.rule_aliases", names: hints[:aliases].to_sentence) %>
- </p>
- <% end %>
- <% if hints[:learned_pct].positive? %>
- <p class="text-xs text-secondary">
- <%= t("bills.detail.rule_learned_tolerance", percent: number_to_percentage(hints[:learned_pct], precision: 1, format: "%n%")) %>
- </p>
- <% end %>
- </div>
+ <%= render DS::Disclosure.new(title: t("bills.detail.overview"), open: true) do %>
+ <div class="space-y-4">
+ <%# Why this bill matches what it matches, in words rather than engine terms. %>
+ <div class="space-y-1.5">
+ <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.rules") %></p>
+ <div class="flex flex-wrap gap-1.5">
+ <%= render DS::Pill.new(label: t("bills.detail.rule_named", name: series.merchant&.name.presence || series.name), tone: :neutral, marker: false) %>
+ <% amount_label = series.has_amount_variance? ?
+ t("bills.detail.rule_amount_range", min: format_money(series.expected_amount_min_money), max: format_money(series.expected_amount_max_money)) :
+ format_money(Money.new(series.amount.abs, series.currency)) %>
+ <span class="privacy-sensitive"><%= render DS::Pill.new(label: amount_label, tone: :neutral, marker: false) %></span>
+ <%= render DS::Pill.new(label: frequency_label(series), tone: :neutral, marker: false) %>
+ <% if series.account %>
+ <%= render DS::Pill.new(label: series.account.name, tone: :neutral, marker: false) %>
+ <% end %>
+ </div>
- <%# What it has actually cost: the shape over twelve months, then the figures. %>
- <div class="border border-subdued rounded-lg grid <%= columns %> divide-y divide-subdued">
- <div class="px-3 py-3 flex flex-col justify-center">
- <p class="text-xs font-medium text-secondary uppercase pb-1"><%= t("bills.detail.history_title") %></p>
- <%= render DS::Sparkline.new(series: payment_history, aria_label: t("bills.detail.history_aria")) %>
- </div>
+ <%# What the app has learned from corrections, prepared by
+ BillsHelper#bills_matcher_hints. %>
+ <% hints = bills_matcher_hints(series) %>
+ <% if hints[:aliases].any? %>
+ <p class="text-xs text-secondary">
+ <%= t("bills.detail.rule_aliases", names: hints[:aliases].to_sentence) %>
+ </p>
+ <% end %>
+ <% if hints[:learned_pct].positive? %>
+ <p class="text-xs text-secondary">
+ <%= t("bills.detail.rule_learned_tolerance", percent: number_to_percentage(hints[:learned_pct], precision: 1, format: "%n%")) %>
+ </p>
+ <% end %>
+ </div>
- <div class="px-3 py-3 space-y-2">
- <% if analytics %>
- <div class="grid grid-cols-3 gap-2">
- <div>
- <p class="text-xs text-secondary"><%= t("bills.detail.average") %></p>
- <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:average]) %></p>
- <p class="text-xs text-subdued privacy-sensitive">
- <%= t("bills.detail.range", min: format_money(analytics[:lowest]), max: format_money(analytics[:highest])) %>
- </p>
- </div>
- <div>
- <p class="text-xs text-secondary"><%= t("bills.detail.annualized") %></p>
- <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:annualized]) %></p>
- </div>
- <div>
- <p class="text-xs text-secondary"><%= t("bills.detail.ytd") %></p>
- <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:ytd]) %></p>
- </div>
+ <%# What it has actually cost: the shape over twelve months, then the figures. %>
+ <div class="border border-subdued rounded-lg divide-y divide-subdued">
+ <div class="px-3 py-3 flex flex-col justify-center">
+ <p class="text-xs font-medium text-secondary uppercase pb-1"><%= t("bills.detail.history_title") %></p>
+ <%= render DS::Sparkline.new(series: payment_history, aria_label: t("bills.detail.history_aria")) %>
</div>
- <% end %>
- <%# Per-year totals are reference material rather than something you read
- every time, so they sit one click away instead of adding a table to
- every bill you open. %>
- <% if yearly_metrics.any? %>
- <%= render DS::Disclosure.new(title: t("bills.detail.key_metrics"), align: "left") do %>
- <div class="divide-y divide-subdued pt-1">
- <div class="grid grid-cols-3 text-xs text-secondary pb-1">
- <p><%= t("bills.detail.year") %></p>
- <p class="text-right"><%= t("bills.detail.spent_per_year") %></p>
- <p class="text-right"><%= t("bills.detail.avg_payment") %></p>
+ <div class="px-3 py-3 space-y-2">
+ <% if analytics %>
+ <div class="grid grid-cols-3 gap-2">
+ <div>
+ <p class="text-xs text-secondary"><%= t("bills.detail.average") %></p>
+ <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:average]) %></p>
+ <p class="text-xs text-subdued privacy-sensitive">
+ <%= t("bills.detail.range", min: format_money(analytics[:lowest]), max: format_money(analytics[:highest])) %>
+ </p>
+ </div>
+ <div>
+ <p class="text-xs text-secondary"><%= t("bills.detail.annualized") %></p>
+ <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:annualized]) %></p>
+ </div>
+ <div>
+ <p class="text-xs text-secondary"><%= t("bills.detail.ytd") %></p>
+ <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:ytd]) %></p>
+ </div>
</div>
- <% yearly_metrics.each do |row| %>
- <div class="grid grid-cols-3 py-1.5 text-sm">
- <p class="text-secondary"><%= row[:year] %></p>
- <p class="text-right text-primary privacy-sensitive"><%= format_money(row[:total]) %></p>
- <p class="text-right text-primary privacy-sensitive"><%= format_money(row[:average]) %></p>
+ <% end %>
+
+ <%# Per-year totals are reference material rather than something you read
+ every time, so they sit one click away instead of adding a table to
+ every bill you open. %>
+ <% if yearly_metrics.any? %>
+ <%= render DS::Disclosure.new(title: t("bills.detail.key_metrics"), align: "left") do %>
+ <div class="divide-y divide-subdued pt-1">
+ <div class="grid grid-cols-3 text-xs text-secondary pb-1">
+ <p><%= t("bills.detail.year") %></p>
+ <p class="text-right"><%= t("bills.detail.spent_per_year") %></p>
+ <p class="text-right"><%= t("bills.detail.avg_payment") %></p>
+ </div>
+ <% yearly_metrics.each do |row| %>
+ <div class="grid grid-cols-3 py-1.5 text-sm">
+ <p class="text-secondary"><%= row[:year] %></p>
+ <p class="text-right text-primary privacy-sensitive"><%= format_money(row[:total]) %></p>
+ <p class="text-right text-primary privacy-sensitive"><%= format_money(row[:average]) %></p>
+ </div>
+ <% end %>
</div>
<% end %>
- </div>
- <% end %>
- <% end %>
+ <% end %>
- <% if last_account %>
- <div class="flex items-center justify-between gap-3">
- <p class="text-xs text-secondary"><%= t("bills.detail.last_account") %></p>
- <p class="text-sm text-primary truncate"><%= last_account.name %></p>
+ <% if last_account %>
+ <div class="flex items-center justify-between gap-3">
+ <p class="text-xs text-secondary"><%= t("bills.detail.last_account") %></p>
+ <p class="text-sm text-primary truncate"><%= last_account.name %></p>
+ </div>
+ <% end %>
</div>
- <% end %>
- </div>
- </div>
+ </div>
- <%# What it used to cost. The twelve-month chart above shows the shape; this
- names the moment it changed and by how much. %>
- <% changes = series.recent_price_changes %>
- <% if changes.any? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.price_changes") %></p>
- <div class="bg-container-inset rounded-lg divide-y divide-subdued">
- <% changes.each do |change| %>
- <div class="flex items-center justify-between gap-3 px-3 py-2">
- <p class="text-sm text-primary"><%= l(change.effective_on, format: :long) %></p>
- <p class="text-sm privacy-sensitive <%= change.new_amount > change.previous_amount ? "text-warning" : "text-success" %>">
- <%= t("bills.detail.price_change_line",
- from: format_money(change.previous_amount_money),
- to: format_money(change.new_amount_money)) %>
- </p>
+ <%# What it used to cost. The twelve-month chart above shows the shape; this
+ names the moment it changed and by how much. %>
+ <% changes = series.recent_price_changes %>
+ <% if changes.any? %>
+ <div class="space-y-1">
+ <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.price_changes") %></p>
+ <div class="bg-container-inset rounded-lg divide-y divide-subdued">
+ <% changes.each do |change| %>
+ <div class="flex items-center justify-between gap-3 px-3 py-2">
+ <p class="text-sm text-primary"><%= l(change.effective_on, format: :long) %></p>
+ <p class="text-sm privacy-sensitive <%= change.new_amount > change.previous_amount ? "text-warning" : "text-success" %>">
+ <%= t("bills.detail.price_change_line",
+ from: format_money(change.previous_amount_money),
+ to: format_money(change.new_amount_money)) %>
+ </p>
+ </div>
+ <% end %>
</div>
- <% end %>
- </div>
+ </div>
+ <% end %>
</div>
<% end %>
<% if upcoming.any? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.upcoming") %></p>
+ <%= render DS::Disclosure.new(title: t("bills.detail.upcoming")) do %>
<div class="bg-container-inset rounded-lg divide-y divide-subdued">
<% upcoming.each do |date| %>
<div class="flex items-center justify-between px-3 py-2">
@@ -164,59 +134,41 @@
</div>
<% end %>
</div>
- </div>
- <% end %>
-
- <%# Individual payments, which is the answer to "what actually paid this". %>
- <% if recent_allocations.any? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.recent_payments") %></p>
- <div class="bg-container-inset rounded-lg divide-y divide-subdued">
- <% recent_allocations.each do |allocation| %>
- <div class="flex items-center justify-between gap-3 px-3 py-2">
- <div class="min-w-0">
- <p class="text-sm text-primary truncate"><%= allocation.entry&.name.presence || t("bills.detail.manual_payment") %></p>
- <% if allocation.paid_on %>
- <p class="text-xs text-secondary"><%= l(allocation.paid_on, format: :short_with_year) %></p>
- <% end %>
- </div>
- <p class="text-sm text-primary privacy-sensitive shrink-0"><%= format_money(allocation.allocated_amount_money) %></p>
- </div>
- <% end %>
- </div>
- </div>
+ <% end %>
<% end %>
- <%# Settled cycles, which answers "did I pay it that month" rather than
- "which transaction paid it". %>
+ <%# Settled cycles with what paid them: "did I pay it that month" and "which
+ transaction paid it" in one list, rather than a cycle list and a payment
+ list that mostly repeat each other. %>
<% if history.any? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.history") %></p>
+ <%= render DS::Disclosure.new(title: t("bills.detail.history")) do %>
<div class="bg-container-inset rounded-lg divide-y divide-subdued">
<% history.each do |occurrence| %>
- <div class="flex items-center justify-between px-3 py-2">
- <div>
+ <% payments = occurrence.allocations.select(&:allocation_confirmed?) %>
+ <div class="flex items-center justify-between gap-3 px-3 py-2">
+ <div class="min-w-0">
<p class="text-sm text-primary"><%= l(occurrence.due_on, format: :long) %></p>
- <p class="text-xs text-secondary">
+ <p class="text-xs text-secondary truncate">
<%= t("recurring_occurrences.history_status.#{occurrence.status}") %>
- <% if occurrence.allocations.size > 1 %>
- &middot; <%= t("bills.detail.payment_count", count: occurrence.allocations.size) %>
+ <% if payments.size > 1 %>
+ &middot; <%= t("bills.detail.payment_count", count: payments.size) %>
+ <% elsif (payment = payments.first) %>
+ &middot; <%= payment.entry&.name.presence || t("bills.detail.manual_payment") %>
<% end %>
</p>
</div>
- <p class="text-sm text-primary privacy-sensitive">
+ <p class="text-sm text-primary privacy-sensitive shrink-0">
<%= format_money(occurrence.confirmed_allocated_money) %>
</p>
</div>
<% end %>
</div>
- </div>
+ <% end %>
<% end %>
<% if series.notes.present? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.notes") %></p>
- <p class="text-sm text-primary"><%= series.notes %></p>
- </div>
+ <%= render DS::Disclosure.new(title: t("bills.detail.notes")) do %>
+ <p class="text-sm text-primary px-3"><%= series.notes %></p>
+ <% end %>
<% end %>
</div>
diff --git a/app/views/bills/_notice.html.erb b/app/views/bills/_notice.html.erb
index ba077ee9f8..33e8743bb0 100644
--- a/app/views/bills/_notice.html.erb
+++ b/app/views/bills/_notice.html.erb
@@ -24,6 +24,8 @@
text: t("bills.manage"),
variant: :default,
href: bill_path(notice.series),
+ frame: :drawer,
+ data: { turbo_prefetch: false },
class: "text-xs shrink-0"
) %>
</div>
diff --git a/app/views/bills/_paycheck_bridge.html.erb b/app/views/bills/_paycheck_bridge.html.erb
index 4c30a5d697..dc402be98e 100755
--- a/app/views/bills/_paycheck_bridge.html.erb
+++ b/app/views/bills/_paycheck_bridge.html.erb
@@ -29,7 +29,8 @@
<% period.items_due.each do |item| %>
<div class="flex items-baseline justify-between gap-3 text-xs">
<%= link_to item.occurrence.recurring_transaction.display_name,
- bill_path(item.occurrence.recurring_transaction),
+ bill_path(item.occurrence.recurring_transaction, occurrence: item.occurrence.id),
+ data: { turbo_frame: "drawer", turbo_prefetch: false },
class: "text-secondary hover:text-primary truncate" %>
<span class="text-secondary tabular-nums privacy-sensitive shrink-0">
<%= format_money(Money.new(item.share, currency)) %>
diff --git a/app/views/bills/_paycheck_income.html.erb b/app/views/bills/_paycheck_income.html.erb
index a9558e3c6c..4d44e990fe 100644
--- a/app/views/bills/_paycheck_income.html.erb
+++ b/app/views/bills/_paycheck_income.html.erb
@@ -30,7 +30,7 @@
<div class="flex items-center justify-between gap-3 py-2">
<div class="min-w-0">
<p class="text-sm text-primary truncate">
- <%= link_to series.display_name, bill_path(series), class: "hover:underline" %>
+ <%= link_to series.display_name, bill_path(series), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "hover:underline" %>
</p>
<p class="text-xs text-secondary truncate">
<%= frequency_label(series) %>
diff --git a/app/views/bills/_paycheck_shortfall.html.erb b/app/views/bills/_paycheck_shortfall.html.erb
index bdf1a75572..df77fed081 100644
--- a/app/views/bills/_paycheck_shortfall.html.erb
+++ b/app/views/bills/_paycheck_shortfall.html.erb
@@ -28,7 +28,7 @@
<% if largest.present? %>
<p class="text-xs text-secondary">
<%= t("bills.paycheck.shortfall_largest") %>
- <%= link_to bill_path(largest.occurrence.recurring_transaction), class: "text-primary hover:underline" do %>
+ <%= link_to bill_path(largest.occurrence.recurring_transaction, occurrence: largest.occurrence.id), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "text-primary hover:underline" do %>
<%= largest.occurrence.recurring_transaction.display_name %>
&middot; <span class="tabular-nums privacy-sensitive"><%= format_money(Money.new(largest.remaining_total, currency)) %></span>
<% end %>
diff --git a/app/views/bills/_summary.html.erb b/app/views/bills/_summary.html.erb
index f01528016a..1a3e305185 100644
--- a/app/views/bills/_summary.html.erb
+++ b/app/views/bills/_summary.html.erb
@@ -1,13 +1,9 @@
-<%# locals: (series:, current_occurrence:, analytics:, recent_allocations:, suggestion: nil) %>
+<%# locals: (series:, current_occurrence:, suggestion: nil) %>
-<%# INSPECT. What is going on with this bill?
+<%# INSPECT. What is going on with this bill, and what to do about it?
- Not "everything about this bill" -- that is the bill's own page, and this
- partial exists because the expansion and the drawer had become two
- renderings of one enormous detail view. The twelve-month chart, the
- per-year table, the price history, the upcoming dates and the settled
- cycles all moved to the page. What is left is the answer to one question,
- plus the way to act on it. %>
+ The top of the bill's drawer. Its sections (Overview, Coming up, History
+ and Notes) follow it in bills/_detail, loaded lazily. %>
<div class="space-y-4">
<%= render "bills/cancelled_notice", series: series %>
@@ -52,6 +48,10 @@
<%# Schedule, on one line rather than as a stack of labelled fields. %>
<p class="text-xs text-secondary">
<%= frequency_label(series) %>
+ <% if (progress = bills_installment_progress(series)) %>
+ &middot; <%= progress %>
+ <% end %>
+ <% unless series.active? %>&middot; <%= t("recurring_transactions.status.#{series.status}") %><% end %>
<% if series.account %>&middot; <%= series.account.name %><% end %>
<% if (autopay = bills_autopay_label(series)) %>&middot; <%= autopay %><% end %>
</p>
@@ -59,35 +59,6 @@
<%# Subscription state is state, not depth, so it stays here. %>
<%= render "bills/state_chips", series: series %>
- <%# What has actually paid this lately. %>
- <% if recent_allocations.any? %>
- <div class="space-y-1">
- <p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.recent_payments") %></p>
- <div class="bg-container-inset rounded-lg divide-y divide-subdued">
- <% recent_allocations.first(3).each do |allocation| %>
- <div class="flex items-center justify-between gap-3 px-3 py-2">
- <div class="min-w-0">
- <p class="text-sm text-primary truncate"><%= allocation.entry&.name.presence || t("bills.detail.manual_payment") %></p>
- <% if allocation.paid_on %>
- <p class="text-xs text-secondary"><%= l(allocation.paid_on, format: :short_with_year) %></p>
- <% end %>
- </div>
- <p class="text-sm text-primary privacy-sensitive shrink-0"><%= format_money(allocation.allocated_amount_money) %></p>
- </div>
- <% end %>
- </div>
- </div>
- <% end %>
-
- <%# Two figures, not a dashboard. The rest of the cost story is on the page. %>
- <% if analytics %>
- <p class="text-xs text-secondary privacy-sensitive">
- <%= t("bills.summary.cost_line",
- average: format_money(analytics[:average]),
- annualized: format_money(analytics[:annualized])) %>
- </p>
- <% end %>
-
<%# The next step, spelled out. The row shows it only when the bill needs you
now, and never on a phone. Here it is always present, settled occurrences
included, because the drawer is the only route in the app to unlinking a
@@ -100,50 +71,5 @@
<%# Pay and Add link keep a home here, so the portal never leaves Bills
just because the row got quieter. %>
<%= render "recurring_transactions/pay_action", recurring_transaction: series %>
-
- <div class="ml-auto flex items-center gap-2">
- <%= render DS::Link.new(
- text: t("bills.view_full_bill"),
- variant: "default",
- href: bill_path(series),
- data: { turbo_frame: "_top" }
- ) %>
-
- <%# Edit, pause and remove stayed two clicks from the Overview rather
- than moving to the page and becoming four. Pause and remove answer
- with the whole page, so they leave the drawer's frame. %>
- <%= render DS::Menu.new do |menu| %>
- <% menu.with_item(
- variant: "link",
- text: t("bills.show.edit"),
- icon: "pencil",
- href: edit_recurring_transaction_path(series),
- data: { turbo_frame: :modal }) %>
- <% if bills_one_shot_ai_available? %>
- <% menu.with_item(
- variant: "link",
- text: t("bills.smart_configurations.show.trigger"),
- icon: "sparkles",
- href: smart_configuration_bill_path(series),
- data: { turbo_frame: :modal }) %>
- <% end %>
- <% menu.with_item(
- variant: "button",
- text: series.active? ? t("recurring_transactions.actions.pause") : t("recurring_transactions.actions.resume"),
- icon: series.active? ? "pause" : "play",
- href: toggle_status_recurring_transaction_path(series),
- method: :post,
- frame: "_top") %>
- <% menu.with_item(
- variant: "button",
- text: t("recurring_transactions.actions.delete"),
- icon: "trash-2",
- href: recurring_transaction_path(series),
- method: :delete,
- destructive: true,
- frame: "_top",
- confirm: t(series.typed_income? ? "recurring_transactions.confirm_delete_income" : "recurring_transactions.confirm_delete", name: series.display_name)) %>
- <% end %>
- </div>
</div>
</div>
diff --git a/app/views/bills/all.html.erb b/app/views/bills/all.html.erb
index 7783179558..aa3b3f61bf 100644
--- a/app/views/bills/all.html.erb
+++ b/app/views/bills/all.html.erb
@@ -84,7 +84,7 @@
<div class="@3xl:hidden bg-container rounded-lg shadow-border-xs divide-y divide-subdued">
<% @all_series.each do |series| %>
<div class="flex items-center gap-3 p-3">
- <%= link_to bill_path(series), class: "flex items-center gap-3 min-w-0 flex-1 group" do %>
+ <%= link_to bill_path(series), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "flex items-center gap-3 min-w-0 flex-1 group" do %>
<div class="min-w-0 flex-1">
<p class="text-sm font-medium text-primary truncate group-hover:underline"><%= series.display_name %></p>
<p class="text-xs text-secondary truncate">
@@ -134,7 +134,7 @@
<%= render DS::Table.new(rows: @all_series, label: t("bills.views.all"), class: "hidden @3xl:block") do |table| %>
<% table.with_column(t(".col_name")) do |series| %>
- <%= link_to series.display_name, bill_path(series), class: "font-medium hover:underline" %>
+ <%= link_to series.display_name, bill_path(series), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "font-medium hover:underline" %>
<% end %>
<% table.with_column(t(".col_type"), class: "text-secondary") { |series| t(".types.#{series.bill_type}") } %>
<% table.with_column(t(".col_frequency"), class: "text-secondary") { |series| frequency_label(series) } %>
diff --git a/app/views/bills/drawer.html.erb b/app/views/bills/drawer.html.erb
index 1a0a9b97a2..37d7ed286d 100644
--- a/app/views/bills/drawer.html.erb
+++ b/app/views/bills/drawer.html.erb
@@ -1,22 +1,72 @@
-<%# Opened from a row, over the list, the way a transaction or a budget
- category opens. The list stays where it was, so closing this lands back
- on the same row. %>
+<%# Everything about one bill, in the drawer, the way a transaction or a
+ budget category opens. Opened from a row, the list stays where it was, so
+ closing this lands back on the same row. There is no separate bill page:
+ a direct visit renders the overview with this drawer already open. %>
<%= render DS::Dialog.new(variant: :drawer) do |dialog| %>
- <% dialog.with_header(title: @series.display_name) do %>
- <% if @series.category %>
- <%= render "categories/badge", category: @series.category %>
- <% end %>
+ <% dialog.with_header(custom_header: true) do %>
+ <div class="flex items-start justify-between gap-2">
+ <div class="min-w-0 space-y-1.5">
+ <% if @series.category %>
+ <%= render "categories/badge", category: @series.category %>
+ <% end %>
+ <h2 id="<%= dialog.title_id %>" class="text-lg font-medium text-primary"><%= @series.display_name %></h2>
+ </div>
+
+ <div class="flex items-center gap-1 shrink-0">
+ <%# Pause and remove answer with the whole page, so they leave the
+ drawer's frame. Edit and AI open as modals over the drawer. %>
+ <%= render DS::Menu.new do |menu| %>
+ <% menu.with_item(
+ variant: "link",
+ text: t("bills.show.edit"),
+ icon: "pencil",
+ href: edit_recurring_transaction_path(@series),
+ data: { turbo_frame: :modal }) %>
+ <% if bills_one_shot_ai_available? %>
+ <% menu.with_item(
+ variant: "link",
+ text: t("bills.smart_configurations.show.trigger"),
+ icon: "sparkles",
+ href: smart_configuration_bill_path(@series),
+ data: { turbo_frame: :modal }) %>
+ <% end %>
+ <% menu.with_item(
+ variant: "button",
+ text: @series.active? ? t("recurring_transactions.actions.pause") : t("recurring_transactions.actions.resume"),
+ icon: @series.active? ? "pause" : "play",
+ href: toggle_status_recurring_transaction_path(@series),
+ method: :post,
+ frame: "_top") %>
+ <% menu.with_item(
+ variant: "button",
+ text: t("recurring_transactions.actions.delete"),
+ icon: "trash-2",
+ href: recurring_transaction_path(@series),
+ method: :delete,
+ destructive: true,
+ frame: "_top",
+ confirm: t(@series.typed_income? ? "recurring_transactions.confirm_delete_income" : "recurring_transactions.confirm_delete", name: @series.display_name)) %>
+ <% end %>
+ <%= dialog.close_button %>
+ </div>
+ </div>
<% end %>
<% dialog.with_body do %>
- <%# What is going on with this bill, and what to do about it. Everything
- deeper -- the chart, the per-year totals, the price history, the
- upcoming dates, the settled cycles -- lives on the bill's page. %>
- <%= render "bills/summary",
- series: @series,
- current_occurrence: @current_occurrence,
- analytics: @analytics,
- recent_allocations: @recent_allocations,
- suggestion: @drawer_suggestion %>
+ <div class="space-y-4">
+ <%= render "bills/summary",
+ series: @series,
+ current_occurrence: @current_occurrence,
+ suggestion: @drawer_suggestion %>
+
+ <%# The collapsible sections: Overview, Coming up, History and Notes.
+ Lazy, so opening a bill costs no more than its summary;
+ refresh: :morph, or a morph refresh would empty it. %>
+ <%= turbo_frame_tag dom_id(@series, :history),
+ src: bill_path(@series, display: "history"),
+ loading: :lazy,
+ refresh: :morph,
+ class: "block" %>
+ </div>
<% end %>
<% end %>
diff --git a/app/views/bills/history.html.erb b/app/views/bills/history.html.erb
new file mode 100644
index 0000000000..e42b272d5e
--- /dev/null
+++ b/app/views/bills/history.html.erb
@@ -0,0 +1,10 @@
+<%= turbo_frame_tag dom_id(@series, :history) do %>
+ <%= render "bills/detail",
+ series: @series,
+ history: @history,
+ upcoming: @upcoming,
+ analytics: @analytics,
+ payment_history: @payment_history,
+ yearly_metrics: @yearly_metrics,
+ last_account: @last_account %>
+<% end %>
diff --git a/app/views/bills/show.html.erb b/app/views/bills/show.html.erb
deleted file mode 100644
index 1559f65c63..0000000000
--- a/app/views/bills/show.html.erb
+++ /dev/null
@@ -1,107 +0,0 @@
-<%= content_for :page_title, @series.display_name %>
-
-<%# DEEP DIVE. Show me everything, and let me configure it.
-
- This used to be a drawer dialog floating over an empty settings layout,
- which meant the app had three renderings of a bill's detail and no page.
- It is a page now, so the chart, the history and the configuration have
- somewhere to live that is not the drawer. %>
-
-<div class="space-y-4 pb-6 lg:pb-12">
- <header class="flex items-start justify-between gap-3">
- <div class="min-w-0 space-y-1.5">
- <% if @series.category %>
- <%= render "categories/badge", category: @series.category %>
- <% end %>
- <h1 class="text-xl font-medium text-primary"><%= @series.display_name %></h1>
- <p class="text-sm text-secondary">
- <%= frequency_label(@series) %>
- <% if (progress = bills_installment_progress(@series)) %>
- &middot; <%= progress %>
- <% end %>
- &middot; <%= t("recurring_transactions.status.#{@series.status}") %>
- </p>
- </div>
-
- <div class="flex items-center gap-2 shrink-0">
- <%= render "recurring_transactions/pay_action", recurring_transaction: @series %>
-
- <%= render DS::Menu.new do |menu| %>
- <% menu.with_item(
- variant: "link",
- text: t("bills.show.edit"),
- icon: "pencil",
- href: edit_recurring_transaction_path(@series),
- data: { turbo_frame: :modal }) %>
- <% if bills_one_shot_ai_available? %>
- <% menu.with_item(
- variant: "link",
- text: t("bills.smart_configurations.show.trigger"),
- icon: "sparkles",
- href: smart_configuration_bill_path(@series),
- data: { turbo_frame: :modal }) %>
- <% end %>
- <% menu.with_item(
- variant: "button",
- text: @series.active? ? t("recurring_transactions.actions.pause") : t("recurring_transactions.actions.resume"),
- icon: @series.active? ? "pause" : "play",
- href: toggle_status_recurring_transaction_path(@series),
- method: :post) %>
- <% menu.with_item(
- variant: "button",
- text: t("recurring_transactions.actions.delete"),
- icon: "trash-2",
- href: recurring_transaction_path(@series),
- method: :delete,
- destructive: true,
- confirm: t(@series.typed_income? ? "recurring_transactions.confirm_delete_income" : "recurring_transactions.confirm_delete", name: @series.display_name)) %>
- <% end %>
- </div>
- </header>
-
- <%# The current obligation, and the way to resolve it. Unconditional: a
- settled cycle still needs a route to unlinking a payment or reopening it,
- and the drawer is the only place in the app that offers either. %>
- <% if @current_occurrence %>
- <div class="bg-container rounded-xl shadow-border-xs p-4 flex flex-wrap items-center justify-between gap-3">
- <div class="min-w-0 space-y-0.5">
- <p class="text-lg font-medium text-primary privacy-sensitive">
- <% if @current_occurrence.paid? %>
- <%= t("bills.summary.paid_headline", amount: format_money(@current_occurrence.confirmed_allocated_money)) %>
- <% else %>
- <%= t("bills.summary.remaining", amount: format_money(@current_occurrence.remaining_amount_money)) %>
- <% end %>
- </p>
- <p class="text-xs <%= @current_occurrence.overdue? ? "text-destructive" : "text-secondary" %>">
- <span class="privacy-sensitive">
- <%= t("bills.partial_progress",
- paid: format_money(@current_occurrence.confirmed_allocated_money),
- expected: format_money(@current_occurrence.resolved_expected_amount_money)) %>
- </span>
- &middot; <%= occurrence_due_label(@current_occurrence) %>
- </p>
- </div>
-
- <%= render DS::Link.new(
- text: @current_occurrence.scheduled? ? t("bills.resolve") : t("bills.manage_payments"),
- variant: "primary",
- href: recurring_occurrence_path(@current_occurrence),
- frame: :drawer
- ) %>
- </div>
- <% end %>
-
- <div class="bg-container rounded-xl shadow-border-xs p-4">
- <%= render "bills/detail",
- series: @series,
- current_occurrence: @current_occurrence,
- history: @history,
- upcoming: @upcoming,
- analytics: @analytics,
- payment_history: @payment_history,
- yearly_metrics: @yearly_metrics,
- last_account: @last_account,
- recent_allocations: @recent_allocations,
- dense: false %>
- </div>
-</div>
diff --git a/app/views/layouts/shared/_htmldoc.html.erb b/app/views/layouts/shared/_htmldoc.html.erb
index 8f8600e218..03ec939ecd 100644
--- a/app/views/layouts/shared/_htmldoc.html.erb
+++ b/app/views/layouts/shared/_htmldoc.html.erb
@@ -24,7 +24,14 @@
<% end %>
<%= turbo_frame_tag "modal" %>
- <%= turbo_frame_tag "drawer" %>
+ <%# A controller can open the drawer on arrival by setting @drawer_src
+ (bills#show visited directly renders a bills view around the bill),
+ whichever template renders the page. %>
+ <% if @drawer_src %>
+ <%= turbo_frame_tag "drawer", src: @drawer_src, refresh: :morph %>
+ <% else %>
+ <%= turbo_frame_tag "drawer" %>
+ <% end %>
<%# Custom overrides for browser's confirm API %>
<%= render "layouts/shared/confirm_dialog" %>
diff --git a/app/views/recurring_occurrences/show.html.erb b/app/views/recurring_occurrences/show.html.erb
index b1688f9fe5..090eb47e83 100644
--- a/app/views/recurring_occurrences/show.html.erb
+++ b/app/views/recurring_occurrences/show.html.erb
@@ -7,7 +7,7 @@
This is the ACT surface: it answers "what do I need to do about this bill
right now", which is a different question from "what is this bill", and it
- is why it opens in the drawer while the bill's own story lives on its page.
+ is why it is its own drawer, one link away from the bill's.
frame: "drawer", responsive: true matches every other detail surface in the
app -- a centred card on a phone, a right-hand drawer from lg up. The close
@@ -304,8 +304,9 @@
<%= render DS::Link.new(
text: t(".view_bill"),
variant: "default",
- href: bill_path(series),
- data: { turbo_frame: "_top" }
+ href: bill_path(series, occurrence: @occurrence.id),
+ frame: :drawer,
+ data: { turbo_prefetch: false }
) %>
<%= render "recurring_transactions/pay_action", recurring_transaction: series, show_add: false %>
</div>
diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erb
index 271f1c3b26..dd848b9cb9 100644
--- a/app/views/transactions/show.html.erb
+++ b/app/views/transactions/show.html.erb
@@ -408,9 +408,9 @@
<div class="flex items-center justify-between gap-2 text-sm">
<div>
<%= link_to occurrence.recurring_transaction.display_name,
- bill_path(occurrence.recurring_transaction),
+ bill_path(occurrence.recurring_transaction, occurrence: occurrence.id),
class: "text-primary font-medium hover:underline",
- data: { turbo_frame: "_top" } %>
+ data: { turbo_frame: "drawer", turbo_prefetch: false } %>
<p class="text-secondary text-xs privacy-sensitive">
<%= t(".applied_to_detail",
amount: format_money(allocation.allocated_amount_money),
diff --git a/config/locales/views/bills/ca.yml b/config/locales/views/bills/ca.yml
index 9aa102decd..4706734520 100644
--- a/config/locales/views/bills/ca.yml
+++ b/config/locales/views/bills/ca.yml
@@ -37,6 +37,7 @@ ca:
current: Actual
next_payment: Proper pagament
around: cap al %{date}
+ overview: Resum
rules: Com s'identifica aquesta factura
rule_named: '%{name}'
rule_amount_range: de %{min} a %{max}
@@ -54,7 +55,6 @@ ca:
ytd: Pagat aquest any
last_account: Últim compte utilitzat
upcoming: Properament
- recent_payments: Pagaments recents
manual_payment: Pagament manual
history: Historial
payment_count:
@@ -85,7 +85,6 @@ ca:
summary:
remaining: '%{amount} pendents'
paid_headline: '%{amount} pagats'
- cost_line: Una mitjana de %{average} per pagament, uns %{annualized} l'any
add_bill: Afegeix una factura
manage: Gestiona
find_payment: Cerca el pagament
@@ -93,7 +92,6 @@ ca:
review_match: Revisa la coincidència
resolve: Resol
manage_payments: Gestiona els pagaments
- view_full_bill: Mostra la factura completa
match:
same_merchant: Mateix comerç
name_matches: El nom coincideix
diff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.yml
index b1c590b50e..e6a684d511 100644
--- a/config/locales/views/bills/en.yml
+++ b/config/locales/views/bills/en.yml
@@ -37,6 +37,7 @@ en:
current: Current
next_payment: Next payment
around: "around %{date}"
+ overview: Overview
rules: How this bill is matched
rule_named: "%{name}"
rule_amount_range: "from %{min} to %{max}"
@@ -54,7 +55,6 @@ en:
ytd: Paid this year
last_account: Last account used
upcoming: Coming up
- recent_payments: Recent payments
manual_payment: Manual payment
history: History
payment_count:
@@ -87,7 +87,6 @@ en:
summary:
remaining: "%{amount} remaining"
paid_headline: "%{amount} paid"
- cost_line: "Averages %{average} a payment, about %{annualized} a year"
add_bill: Add bill
manage: Manage
find_payment: Find payment
@@ -95,7 +94,6 @@ en:
review_match: Review match
resolve: Resolve
manage_payments: Manage payments
- view_full_bill: View full bill
match:
same_merchant: Same merchant
name_matches: Name matches
diff --git a/config/locales/views/bills/fr.yml b/config/locales/views/bills/fr.yml
index 7cee577f0f..641ad4107a 100644
--- a/config/locales/views/bills/fr.yml
+++ b/config/locales/views/bills/fr.yml
@@ -79,13 +79,13 @@ fr:
manual_payment: Paiement manuel
next_payment: Prochain paiement
notes: Remarques
+ overview: Aperçu
payment_count:
one: 1 paiement
other: "%{count} paiements"
price_change_line: "%{from} → %{to}"
price_changes: Changements de prix
range: de %{min} à %{max}
- recent_payments: Paiements récents
renews_chip: Renouvellement le %{date}
rule_aliases: Correspond aussi à %{names}
rule_amount_range: de %{min} à %{max}
@@ -300,10 +300,8 @@ fr:
trigger: Laisser l'IA configurer
uncategorized: Sans catégorie
summary:
- cost_line: En moyenne %{average} par paiement, soit environ %{annualized} par an
paid_headline: "%{amount} payés"
remaining: "%{amount} restants"
- view_full_bill: Voir la facture complète
views:
all: Toutes les factures
aria_label: Vues des factures
diff --git a/config/locales/views/bills/pl.yml b/config/locales/views/bills/pl.yml
index 187629eecb..2c2f5dbfef 100644
--- a/config/locales/views/bills/pl.yml
+++ b/config/locales/views/bills/pl.yml
@@ -82,6 +82,7 @@ pl:
manual_payment: Płatność ręczna
next_payment: Następna płatność
notes: Notatki
+ overview: Przegląd
payment_count:
few: "%{count} płatności"
many: "%{count} płatności"
@@ -90,7 +91,6 @@ pl:
price_change_line: "%{from} → %{to}"
price_changes: Zmiany cen
range: od %{min} do %{max}
- recent_payments: Ostatnie płatności
renews_chip: Odnawia się %{date}
rule_aliases: Pasuje też do %{names}
rule_amount_range: od %{min} do %{max}
@@ -367,10 +367,8 @@ pl:
trigger: Pozwól AI skonfigurować
uncategorized: Bez kategorii
summary:
- cost_line: Średnio %{average} za płatność, około %{annualized} rocznie
paid_headline: Zapłacono %{amount}
remaining: Pozostało %{amount}
- view_full_bill: Zobacz pełny rachunek
views:
all: Wszystkie rachunki
aria_label: Widoki rachunków
diff --git a/config/locales/views/bills/ru.yml b/config/locales/views/bills/ru.yml
index 57559c47af..c66f83388d 100644
--- a/config/locales/views/bills/ru.yml
+++ b/config/locales/views/bills/ru.yml
@@ -39,6 +39,7 @@ ru:
current: Текущий
next_payment: Следующий платёж
around: около %{date}
+ overview: Обзор
rules: Как распознаётся этот платёж
rule_named: «%{name}»
rule_amount_range: от %{min} до %{max}
@@ -56,7 +57,6 @@ ru:
ytd: Оплачено с начала года
last_account: Последний использованный счёт
upcoming: Предстоящие
- recent_payments: Последние оплаты
manual_payment: Оплата вручную
history: История
payment_count:
@@ -93,7 +93,6 @@ ru:
summary:
remaining: Осталось %{amount}
paid_headline: Оплачено %{amount}
- cost_line: В среднем %{average} за платёж, около %{annualized} в год
add_bill: Добавить платёж
manage: Управлять
find_payment: Найти оплату
@@ -101,7 +100,6 @@ ru:
review_match: Проверить совпадение
resolve: Решить
manage_payments: Управлять оплатами
- view_full_bill: Открыть платёж полностью
match:
same_merchant: Тот же продавец
name_matches: Совпадает название
diff --git a/config/locales/views/bills/tr.yml b/config/locales/views/bills/tr.yml
index a6dc244e8b..4a844933ec 100644
--- a/config/locales/views/bills/tr.yml
+++ b/config/locales/views/bills/tr.yml
@@ -37,6 +37,7 @@ tr:
current: Güncel
next_payment: Sonraki ödeme
around: '%{date} civarı'
+ overview: Genel Bakış
rules: Bu fatura nasıl eşleştirilir
rule_named: '%{name}'
rule_amount_range: '%{min} ile %{max} arası'
@@ -54,7 +55,6 @@ tr:
ytd: Bu yıl ödenen
last_account: Son kullanılan hesap
upcoming: Yaklaşanlar
- recent_payments: Son ödemeler
manual_payment: Manuel ödeme
history: Geçmiş
payment_count:
@@ -85,7 +85,6 @@ tr:
summary:
remaining: '%{amount} kaldı'
paid_headline: '%{amount} ödendi'
- cost_line: Ödeme başına ortalama %{average}, yılda yaklaşık %{annualized}
add_bill: Fatura ekle
manage: Yönet
find_payment: Ödeme bul
@@ -93,7 +92,6 @@ tr:
review_match: Eşleşmeyi incele
resolve: Düzelt
manage_payments: Ödemeleri yönet
- view_full_bill: Faturanın tamamını görüntüle
match:
same_merchant: Aynı satıcı
name_matches: Ad eşleşiyor
diff --git a/config/locales/views/bills/uk.yml b/config/locales/views/bills/uk.yml
index 1ad2afefdb..1406ed1704 100644
--- a/config/locales/views/bills/uk.yml
+++ b/config/locales/views/bills/uk.yml
@@ -39,6 +39,7 @@ uk:
current: Поточний
next_payment: Наступна оплата
around: приблизно %{date}
+ overview: Огляд
rules: Як розпізнається цей платіж
rule_named: '%{name}'
rule_amount_range: від %{min} до %{max}
@@ -56,7 +57,6 @@ uk:
ytd: Сплачено з початку року
last_account: Останній використаний рахунок
upcoming: Найближчі
- recent_payments: Останні оплати
manual_payment: Оплата вручну
history: Історія
payment_count:
@@ -93,7 +93,6 @@ uk:
summary:
remaining: Залишилося %{amount}
paid_headline: Сплачено %{amount}
- cost_line: У середньому %{average} за оплату, приблизно %{annualized} на рік
add_bill: Додати платіж
manage: Керувати
find_payment: Знайти оплату
@@ -101,7 +100,6 @@ uk:
review_match: Перевірити зіставлення
resolve: Вирішити
manage_payments: Керувати оплатами
- view_full_bill: Переглянути платіж повністю
match:
same_merchant: Той самий продавець
name_matches: Назва збігається
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index b66b74dd19..020ab8568d 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -262,7 +262,8 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
frequency = ApplicationController.helpers.frequency_label(bill)
- assert_select "p", text: /\A#{Regexp.escape(frequency)}\s*·\s*#{Regexp.escape(bill.account.name)}\z/
+ status = I18n.t("recurring_transactions.status.#{bill.status}")
+ assert_select "p", text: /\A#{Regexp.escape(frequency)}\s*·\s*#{Regexp.escape(status)}\s*·\s*#{Regexp.escape(bill.account.name)}\z/
end
# Rows after this month said "Snoozed until …". The rail that replaced that
@@ -695,21 +696,16 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
overdue_phrase = I18n.t("bills.due_label.overdue", count: days,
date: I18n.l(occurrence.effective_due_on, format: :short))
- get bill_url(bill)
- assert_response :success
- assert_match overdue_phrase, response.body, "the page states the status"
-
get_bill_drawer(bill)
assert_response :success
- assert_match overdue_phrase, response.body, "and the drawer must state the same one"
+ assert_match overdue_phrase, response.body, "the drawer states the status"
assert_no_match I18n.t("bills.detail.next_payment"), response.body,
"an overdue bill is not a next payment"
end
- # A bill's own page is where the depth lives now. It used to be a drawer
- # dialog rendered over an empty settings layout, which is how the app ended
- # up with three renderings of a bill's detail and no page at all.
- test "show renders the bill page with history and analytics" do
+ # The depth loads lazily inside the drawer, so opening a bill costs no more
+ # than its summary.
+ test "the drawer loads the bill's history and analytics lazily" do
bill = create_bill(name: "Power Co", amount: 80)
past = bill.recurring_occurrences.create!(
family: @family, original_due_on: 2.months.ago.to_date, due_on: 2.months.ago.to_date,
@@ -718,35 +714,39 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
RecurringTransaction::Allocator.new(past).allocate!(amount: "78.50")
past.reload
- get bill_url(bill)
+ get_bill_drawer(bill)
+ assert_response :success
+ assert_select "turbo-frame[loading=lazy][src=?]", bill_path(bill, display: "history")
+ assert_no_match I18n.t("bills.detail.ytd"), response.body, "the aggregates wait for the frame"
+ get_bill_history(bill)
assert_response :success
- assert_select "main h1", text: "Power Co"
+ assert_select "turbo-frame##{ActionView::RecordIdentifier.dom_id(bill, :history)}"
assert_match I18n.t("bills.detail.history"), response.body
assert_match I18n.t("bills.detail.ytd"), response.body
assert_match "$78.50", response.body
end
- # The drawer slot belongs to resolving a payment. If a bill's page claimed it
- # too, the page and the payment surface would compete for one frame id and
- # whichever lost would render nothing at all.
- test "the bill page leaves the drawer frame to the payment surface" do
+ # There is no bill page: everything about a bill is in its drawer, and its
+ # actions sit in the drawer's header.
+ test "the drawer is the whole bill, actions included" do
bill = create_bill(name: "Power Co", amount: 80)
- get bill_url(bill)
+ get_bill_drawer(bill)
assert_response :success
- assert_equal 1, response.body.scan(/<turbo-frame[^>]*id="drawer"/).size,
- "only the layout's own empty drawer frame"
- assert_match recurring_occurrence_path(bill.recurring_occurrences.order(:due_on).first), response.body,
- "and the page still offers the way in to it"
+ assert_select "dialog header", text: /Power Co/
+ assert_select "dialog header form[action=?]", toggle_status_recurring_transaction_path(bill)
+ assert_select "dialog header form[action=?] [data-turbo-frame=_top]", recurring_transaction_path(bill)
+ assert_select "dialog header a[href=?]", edit_recurring_transaction_path(bill)
+ assert_select "a[href=?]", bill_path(bill), count: 0
end
# The average sat beside per-year totals that are sums of real payments, so
# reading estimates here put two disagreeing numbers about the same money in
# one panel. Expected $80 twice, really charged $76 and $78: the average is
# $77, a figure that appears nowhere if the estimates are averaged instead.
- test "drawer analytics average what was charged, not what was expected" do
+ test "bill analytics average what was charged, not what was expected" do
bill = create_bill(name: "Power Co", amount: 80)
[ [ 3, 76 ], [ 2, 78 ] ].each do |months_ago, charged|
@@ -757,7 +757,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert occurrence.reload.paid?, "each charge is inside tolerance and should settle the cycle"
end
- get_bill_drawer(bill)
+ get_bill_history(bill)
assert_response :success
assert_match "$77.00", response.body
@@ -1262,16 +1262,17 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_select "turbo-frame#drawer dialog h2", text: "Rent"
- assert_match I18n.t("bills.detail.recent_payments"), response.body
- assert_match "WATSON PROPERTY", response.body
+ assert_no_match(/<html/, response.body, "the drawer renders frame-only, no layout")
- # The drawer answers "what is going on with this bill" and stops there.
- # The matching rules and the per-year table are configuration and
- # reference material, and they belong to the bill's page.
- assert_no_match I18n.t("bills.detail.rules"), response.body,
- "the drawer is not a second detail view"
+ # The drawer answers "what is going on with this bill" up front. Its
+ # sections, the matching rules and the per-year table among them, load
+ # into the lazy frame below, and History names the payment next to the
+ # cycle it paid.
+ assert_no_match I18n.t("bills.detail.rules"), response.body
assert_no_match I18n.t("bills.detail.key_metrics"), response.body
- assert_no_match(/<html/, response.body, "the drawer renders frame-only, no layout")
+
+ get_bill_history(bill)
+ assert_match "WATSON PROPERTY", response.body
end
# A match waiting on a decision is the one thing that changes what the
@@ -1305,16 +1306,53 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
end
end
- # The row is a real link, so a cmd-click or a pasted URL arrives with no frame
- # to render into. A bare dialog with no page around it never opens, which
- # would leave a blank tab.
- test "a drawer link opened outside the drawer lands on the bill's page" do
+ # The row is a real link, so a cmd-click, a pasted URL or a notification
+ # arrives with no frame to render into. A bare dialog with no page around it
+ # never opens, so the overview renders and its drawer frame loads the bill.
+ test "a bill visited directly opens over the overview" do
+ bill = create_bill(name: "Power Co", amount: 80)
+ occurrence = bill.recurring_occurrences.order(:due_on).first
+
+ get bill_url(bill, display: "drawer", occurrence: occurrence.id)
+
+ assert_response :success
+ assert_select "turbo-frame#drawer[src=?]", bill_path(bill, display: "drawer", occurrence: occurrence.id)
+ assert_select "dialog#drawer, turbo-frame#drawer dialog", count: 0
+ assert_match I18n.t("bills.index.title"), response.body
+ end
+
+ test "a bill visited directly opens over whichever bills view it names" do
+ bill = create_bill(name: "Power Co", amount: 80)
+ occurrence = bill.recurring_occurrences.order(:due_on).first
+
+ %w[all calendar paycheck].each do |view|
+ get bill_url(bill, view: view, occurrence: occurrence.id)
+
+ assert_response :success
+ assert_select "turbo-frame#drawer[src=?]", bill_path(bill, display: "drawer", occurrence: occurrence.id)
+ end
+ end
+
+ # Pause from any drawer opened since redirects back to the visited URL. That
+ # refresh is for the list; opening the visited bill again would swap the
+ # drawer someone was using for one they had already closed.
+ test "a redirect back to a visited bill's URL does not reopen it" do
bill = create_bill(name: "Power Co", amount: 80)
- get bill_url(bill, display: "drawer")
+ get bill_url(bill), headers: { "HTTP_REFERER" => bill_url(bill) }
assert_response :success
- assert_select "main h1", text: "Power Co"
+ assert_select "turbo-frame#drawer[src]", count: 0
+ end
+
+ test "a bill from another family is not found, even directly" do
+ other = families(:empty).recurring_transactions.create!(
+ name: "Elsewhere", amount: 10, currency: "USD", expected_day_of_month: 1,
+ last_occurrence_date: 1.month.ago.to_date, next_expected_date: Date.current, status: "active"
+ )
+
+ get bill_url(other)
+ assert_response :not_found
end
test "the paycheck view lists declared income with an edit affordance" do
@@ -1379,20 +1417,18 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
)
# Trial and renewal are STATE: they change what you might do about the bill
- # today, so both routes to it must say so. Price history is the record of
- # how it got here, which is the page's job.
- { "page" => -> { get bill_url(sub) }, "drawer" => -> { get_bill_drawer(sub) } }.each do |label, request|
- request.call
- assert_response :success
- assert_match I18n.t("bills.detail.trial_chip", date: I18n.l(Date.current + 5, format: :short)),
- response.body, "the #{label} lost the trial chip"
- assert_match I18n.t("bills.detail.renews_chip", date: I18n.l(Date.current + 30, format: :short)),
- response.body, "the #{label} lost the renewal date"
- end
+ # today, so the drawer's summary says so. Price history is the record of
+ # how it got here, which is the lazy history's job.
+ get_bill_drawer(sub)
+ assert_response :success
+ assert_match I18n.t("bills.detail.trial_chip", date: I18n.l(Date.current + 5, format: :short)),
+ response.body, "the drawer lost the trial chip"
+ assert_match I18n.t("bills.detail.renews_chip", date: I18n.l(Date.current + 30, format: :short)),
+ response.body, "the drawer lost the renewal date"
- get bill_url(sub)
+ get_bill_history(sub)
assert_match I18n.t("bills.detail.price_changes"), response.body,
- "the bill's page keeps the price history"
+ "the history keeps the price history"
end
test "notices surface trials, renewals and price changes" do
@@ -1502,7 +1538,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
cancelled_on: 3.days.ago.to_date)
assert bill.cancelled_on.present? && bill.active?, "premise: cancelled yet still running"
- get bill_url(bill)
+ get_bill_drawer(bill)
assert_response :success
assert_includes response.body,
I18n.t("bills.cancelled_still_scheduled", date: I18n.l(bill.cancelled_on, format: :short))
@@ -1512,7 +1548,7 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
test "a paused bill does not repeat the cancellation notice" do
bill = create_bill(name: "Streamly", amount: 15, bill_type: "subscription",
cancelled_on: 3.days.ago.to_date, status: "paused")
- get bill_url(bill)
+ get_bill_drawer(bill)
assert_response :success
refute_includes response.body,
I18n.t("bills.cancelled_still_scheduled", date: I18n.l(bill.cancelled_on, format: :short))
@@ -1619,16 +1655,11 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Dismissed", I18n.t("recurring_transactions.status.ended")
end
- # The row expansion and the old drawer used to be two templates over one
- # action, so they drifted, and the fix made them render the SAME partial --
- # which traded a disagreement for a duplication: two surfaces answering one
- # question.
- #
- # They now answer different ones. What has to stay true is that nothing was
- # lost on the way, and that the shallower surface never quietly grows into
- # the deeper one again. So: the drawer is a strict subset of the page, and
- # every section the old shared partial rendered still exists somewhere.
- test "the drawer is a subset of the bill's page, and nothing was dropped" do
+ # The bill's page folded into its drawer: the summary on top, the sections
+ # in a lazy frame below. Every section the page had must still be in one of
+ # the two, and none in both, or the drawer says the same thing twice. The
+ # page's recent payments went into History, next to the cycles they paid.
+ test "the drawer and its history keep every section, once" do
bill = create_bill(name: "Power Co", amount: 80, notes: "Account 4821")
past = bill.recurring_occurrences.create!(
family: @family, original_due_on: 2.months.ago.to_date,
@@ -1644,31 +1675,62 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
currency: "USD", source: "detected"
)
- get bill_url(bill)
- assert_response :success
- page = response.body
-
get_bill_drawer(bill)
assert_response :success
drawer = response.body
- # Every section the shared partial used to render still has a home.
- everything = %w[rules history_title average annualized ytd upcoming
- recent_payments history notes last_account key_metrics
+ get_bill_history(bill)
+ assert_response :success
+ history = response.body
+
+ everything = %w[overview rules history_title average annualized ytd
+ upcoming history notes last_account key_metrics
price_changes]
- homeless = everything.reject { |key| page.include?(I18n.t("bills.detail.#{key}")) }
- assert_empty homeless, "relocating the detail must not delete any of it"
+ homeless = everything.reject { |key| (drawer + history).include?(I18n.t("bills.detail.#{key}")) }
+ assert_empty homeless, "folding the page in must not delete any of it"
+
+ twice = everything.select { |key| drawer.include?(I18n.t("bills.detail.#{key}")) && history.include?(I18n.t("bills.detail.#{key}")) }
+ assert_empty twice, "the summary and the history must not repeat each other"
- # And the drawer adds nothing of its own that the page lacks.
- shown_in_drawer = everything.select { |key| drawer.include?(I18n.t("bills.detail.#{key}")) }
- assert_equal shown_in_drawer, shown_in_drawer & everything.select { |key| page.include?(I18n.t("bills.detail.#{key}")) },
- "the drawer must stay a subset, never a second detail view"
+ assert_includes history, "POWER CO AUTOPAY"
+ assert_includes history, "$78.50"
+ assert_includes history, "Account 4821"
- [ "POWER CO AUTOPAY", "$78.50" ].each do |fact|
- assert_includes page, fact, "the page is missing #{fact}"
- assert_includes drawer, fact, "the drawer is missing #{fact}"
+ # Collapsible, like a transaction's or a budget category's drawer: the
+ # overview opens, the rest wait for a click.
+ assert_select "details[open] > summary", text: I18n.t("bills.detail.overview")
+ %w[upcoming history notes].each do |key|
+ assert_select "details:not([open]) > summary", text: I18n.t("bills.detail.#{key}")
end
- assert_includes page, "Account 4821", "notes belong to the page"
+ end
+
+ # History names what paid each cycle: the payment when there was one, a
+ # count when it took several. A match still waiting on review paid nothing,
+ # so it is neither named nor counted.
+ test "history names what paid each settled cycle" do
+ bill = create_bill(name: "Power Co", amount: 80)
+ single, split = [ 3, 2 ].map do |months_ago|
+ due = months_ago.months.ago.to_date
+ bill.recurring_occurrences.create!(family: @family, original_due_on: due, due_on: due, currency: "USD")
+ end
+ autopay = create_transaction_entry(name: "POWER CO AUTOPAY", amount: 80, date: single.due_on)
+ RecurringTransaction::Allocator.new(single).allocate!(amount: "80", entry: autopay)
+ single.allocations.create!(
+ entry: create_transaction_entry(name: "POWER CO REFUND", amount: 80, date: single.due_on),
+ allocated_amount: 80, currency: "USD", state: "suggested", source: "auto_matched"
+ )
+ 2.times { RecurringTransaction::Allocator.new(split).allocate!(amount: "40") }
+ assert [ single, split ].all? { |occurrence| occurrence.reload.paid? }, "both cycles must be settled to be history"
+
+ get_bill_history(bill)
+
+ # The cycle's own line, since the overview's "Also matches" names the
+ # payee too.
+ assert_response :success
+ paid = I18n.t("recurring_occurrences.history_status.paid")
+ assert_select "p", text: /\A#{paid}\s*·\s*POWER CO AUTOPAY\z/
+ assert_select "p", text: /\A#{paid}\s*·\s*#{I18n.t("bills.detail.payment_count", count: 2)}\z/
+ assert_no_match "POWER CO REFUND", response.body, "a pending match paid nothing"
end
# "Something changed" is only useful if the thing you can still act on is
@@ -1941,16 +2003,16 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_no_match I18n.t("bills.index.review_with_ai"), response.body
end
- test "the bill page offers smart configure only when AI is available" do
+ test "the bill drawer offers smart configure only when AI is available" do
bill = create_bill(name: "Power Co", amount: 80)
Provider::Registry.stubs(:preferred_llm_provider).returns(Object.new)
- get bill_url(bill)
+ get_bill_drawer(bill)
assert_response :success
assert_match smart_configuration_bill_path(bill), response.body
Provider::Registry.stubs(:preferred_llm_provider).returns(nil)
- get bill_url(bill)
+ get_bill_drawer(bill)
assert_response :success
assert_no_match smart_configuration_bill_path(bill), response.body
end
@@ -2214,6 +2276,11 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
get bill_url(bill, display: "drawer", **params), headers: { "Turbo-Frame" => "drawer" }
end
+ # What the drawer's lazy frame fetches once it is scrolled to.
+ def get_bill_history(bill)
+ get bill_url(bill, display: "history"), headers: { "Turbo-Frame" => ActionView::RecordIdentifier.dom_id(bill, :history) }
+ end
+
def create_bill(name:, amount:, **overrides)
@family.recurring_transactions.create!({
account: accounts(:depository),
diff --git a/test/controllers/recurring_occurrences_controller_test.rb b/test/controllers/recurring_occurrences_controller_test.rb
index a1fd857bb8..d434a6ea94 100644
--- a/test/controllers/recurring_occurrences_controller_test.rb
+++ b/test/controllers/recurring_occurrences_controller_test.rb
@@ -16,8 +16,8 @@ class RecurringOccurrencesControllerTest < ActionDispatch::IntegrationTest
end
# Resolving a payment is the ACT surface, so it owns the drawer slot -- the
- # same one transactions, trades and transfers use. The bill's own story moved
- # to its own page, so nothing competes for it.
+ # same one transactions, trades and transfers use. The bill opens in that
+ # same slot, so View bill swaps one for the other instead of stacking two.
test "show renders the occurrence dialog in a single drawer frame" do
get recurring_occurrence_url(@occurrence), headers: { "Turbo-Frame" => "drawer" }
@@ -25,8 +25,8 @@ class RecurringOccurrencesControllerTest < ActionDispatch::IntegrationTest
assert_equal 1, response.body.scan(/<turbo-frame[^>]*id="drawer"/).size
end
- # Turbo caches the page as it was left, so a drawer still open when "View
- # full bill" navigated away would come back from Back as a stray dialog.
+ # Turbo caches the page as it was left, so a drawer still open when the user
+ # navigated away would come back from Back as a stray dialog.
# Visited directly, the dialog is the page, and Back has to restore it.
test "the dialog is left out of Turbo's page cache in the drawer, not on a direct visit" do
get recurring_occurrence_url(@occurrence), headers: { "Turbo-Frame" => "drawer" }
@@ -48,6 +48,14 @@ class RecurringOccurrencesControllerTest < ActionDispatch::IntegrationTest
assert_select "form[action=?] button[data-turbo-frame=_top]", toggle_status_recurring_transaction_path(@series)
end
+ # Like every other link into the bill's drawer, a hover doesn't render the
+ # bill ahead of a click that may never come.
+ test "View bill swaps to the bill's drawer without a hover prefetch" do
+ get recurring_occurrence_url(@occurrence), headers: { "Turbo-Frame" => "drawer" }
+
+ assert_select "a[href=?][data-turbo-frame=drawer][data-turbo-prefetch=false]", bill_path(@series, occurrence: @occurrence.id)
+ end
+
test "recurring occurrence feedback is localized in German" do
@user.update!(locale: "de")
diff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rb
index 55101b5bb8..0a0f4374dc 100644
--- a/test/controllers/recurring_transactions_controller_test.rb
+++ b/test/controllers/recurring_transactions_controller_test.rb
@@ -297,6 +297,20 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTest
assert Entry.exists?(entry.id), "removing a bill must never delete ledger entries"
end
+ # A bill visited at its own URL opens in the drawer over the overview, so
+ # going back there after removing it would reopen it, or 404 on it.
+ test "deleting a bill from its own URL lands on the overview" do
+ bill = @family.recurring_transactions.create!(
+ name: "City Water", account: accounts(:depository), amount: 45, currency: "USD",
+ expected_day_of_month: 5, last_occurrence_date: 1.month.ago.to_date,
+ next_expected_date: Date.current, status: "active", manual: true
+ )
+
+ delete recurring_transaction_url(bill), headers: { "HTTP_REFERER" => bill_url(bill) }
+
+ assert_redirected_to bills_url
+ end
+
# Which kind this is was settled by the entry point that opened the dialog.
# The checkbox asked it again, and ticking it reshaped nothing: you filled in
# bill-shaped labels, pressed Save bill, and got an income record.
diff --git a/test/system/bill_drawer_test.rb b/test/system/bill_drawer_test.rb
index 75c5b01efe..90964207cb 100644
--- a/test/system/bill_drawer_test.rb
+++ b/test/system/bill_drawer_test.rb
@@ -11,7 +11,7 @@ class BillDrawerTest < ApplicationSystemTestCase
# Overdue, so its row and its drawer offer Find payment, and so its row is
# the only link to this cycle: Next up lists nothing already past due.
due = 6.days.ago.to_date
- bill = @user.family.recurring_transactions.create!(
+ @bill = bill = @user.family.recurring_transactions.create!(
name: "City Water", account: accounts(:depository), amount: 80, currency: "USD",
expected_day_of_month: due.day, last_occurrence_date: 2.months.ago.to_date,
next_expected_date: due, status: "active"
@@ -54,22 +54,26 @@ class BillDrawerTest < ApplicationSystemTestCase
page.driver.browser.manage.window.resize_to(1400, 1400)
end
- # Turbo caches the page as it was left. A drawer still open when "View full
- # bill" navigated away came back from Back as a stray, non-modal dialog.
- test "going back from the bill's page shows the list, not a leftover drawer" do
- visit bills_url
+ # A pasted link, a new tab or a notification has no list to open the drawer
+ # over, so the overview renders around it. Closing it leaves the overview.
+ test "a bill visited directly opens its drawer over the overview" do
+ visit bill_url(@bill)
- find(@row_link).click
- within("dialog[open]") { click_on I18n.t("bills.view_full_bill") }
- assert_selector "main h1", text: "City Water"
+ within("dialog[open]") do
+ assert_selector "h2", text: "City Water"
+ # The deep part arrives once scrolled to, in the same drawer.
+ scroll_to find("turbo-frame[src*='display=history']")
+ assert_text(/#{I18n.t("bills.detail.history_title")}/i)
+ click_on I18n.t("ds.dialog.close")
+ end
- page.go_back
- assert_selector @row_link
assert_no_selector "dialog[open]"
+ assert_selector @row_link
end
- # The payment drawer's "View full bill" leaves the same way.
- test "going back from the bill's page shows the list, not a leftover payment drawer" do
+ # The payment drawer's "View bill" swaps back to the bill's drawer, in the
+ # same frame, over the same list.
+ test "the payment drawer's View bill opens the bill's drawer" do
# Rows carry their verb only from @lg, and at 1400 both sidebars leave the
# list just short of it.
page.current_window.resize_to(1440, 1400)
@@ -77,8 +81,18 @@ class BillDrawerTest < ApplicationSystemTestCase
find(@find_payment_link).click
within("dialog[open]") { click_on I18n.t("recurring_occurrences.show.view_bill") }
- assert_selector "main h1", text: "City Water"
+ within("dialog[open]") do
+ assert_selector "h2", text: "City Water"
+ assert_selector "turbo-frame[src*='display=history']"
+ end
+ assert_selector @row_link
+ # Drawer swaps are frame visits, so Back leaves the overview. Turbo's
+ # cached copy of it must not bring the closed drawer back open.
+ page.send_keys(:escape)
+ assert_no_selector "dialog[open]"
+ click_on I18n.t("layouts.application.nav.transactions"), match: :first
+ assert_current_path transactions_path
page.go_back
assert_selector @row_link
assert_no_selector "dialog[open]"
diff --git a/test/system/bills_mobile_test.rb b/test/system/bills_mobile_test.rb
index 4967b71757..677e17b4c8 100644
--- a/test/system/bills_mobile_test.rb
+++ b/test/system/bills_mobile_test.rb
@@ -78,10 +78,18 @@ class BillsMobileTest < ApplicationSystemTestCase
assert_no_horizontal_scroll("the #{view} view")
end
- # The bill's own page: chart, history and configuration in one column.
+ # A bill visited directly: its drawer over the overview, with the chart and
+ # the per-year totals loaded into it. Every section opened, or a closed one
+ # would hide whatever it pushes sideways.
visit bill_url(bill)
- assert_text bill.display_name
- assert_no_horizontal_scroll("the bill page")
+ within("dialog[open]") do
+ assert_selector "h2", text: bill.display_name
+ scroll_to find("turbo-frame[src*='display=history']")
+ assert_text(/#{I18n.t("bills.detail.history_title")}/i)
+ all("details:not([open]) > summary").each(&:click)
+ assert_text bill.notes
+ end
+ assert_no_horizontal_scroll("the bill drawer")
# The control for the reflow above: given its width back, the container
# query must bring the table back, or the check proved only that a table