Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Lay out the bills header and switcher like Transactions (#4094)

Guillem Arias Fausteae68b1f95112
diff --git a/app/views/bills/_view_switcher.html.erb b/app/views/bills/_view_switcher.html.erb
index 12444d8045..55edc15d3c 100644
--- a/app/views/bills/_view_switcher.html.erb
+++ b/app/views/bills/_view_switcher.html.erb
@@ -5,19 +5,18 @@
<%# Both halves are addable from every view, but only the one this view is
about earns a header button: Add income on the Income plan, Add bill
everywhere else. The other half and the AI review live in the overflow
- menu, so the header carries one action instead of a toolbar of three. %>
+ menu, so the header carries one action instead of a toolbar of three.
+ Laid out the way Transactions lays out New transaction: the menu first,
+ the primary action last, and a round + in its place on a phone. A display
+ class makes DS::Link drop its own inline-flex row, so the button brings
+ items-center gap-1 back or its + touches the label. %>
<% income_first = active == "paycheck" %>
+<% add_text = income_first ? t("bills.index.add_income") : t("bills.index.add_bill") %>
+<% add_href = income_first ? new_recurring_transaction_path(income: true) : new_recurring_transaction_path %>
<header class="flex justify-between items-center gap-2 text-primary font-medium">
<h1 class="text-xl"><%= t("bills.index.title") %></h1>
<div class="flex items-center gap-2 shrink-0">
- <%= render DS::Link.new(
- text: income_first ? t("bills.index.add_income") : t("bills.index.add_bill"),
- icon: "plus",
- variant: "primary",
- href: income_first ? new_recurring_transaction_path(income: true) : new_recurring_transaction_path,
- frame: :modal
- ) %>
<%= render DS::Menu.new do |menu| %>
<% menu.with_item(
variant: "link",
@@ -39,10 +38,31 @@
data: { action: "app-layout#openRightSidebar" }) %>
<% end %>
<% end %>
+
+ <%= render DS::Link.new(
+ text: add_text,
+ icon: "plus",
+ variant: "primary",
+ href: add_href,
+ frame: :modal,
+ class: "hidden md:inline-flex items-center gap-1"
+ ) %>
+ <%= render DS::Link.new(
+ icon: "plus",
+ variant: "icon-inverse",
+ href: add_href,
+ frame: :modal,
+ class: "rounded-full md:hidden",
+ aria: { label: add_text }
+ ) %>
</div>
</header>
-<%= render DS::SegmentedControl.new(aria_label: t("bills.views.aria_label")) do |control| %>
+<%# The control's own track is the page's colour in light mode, so on the
+ page it showed only the selected pill and loose words. surface-inset is the
+ track DS::Tabs gives Transactions' view switch, and the budgets owner
+ switcher already overrides it the same way. %>
+<%= render DS::SegmentedControl.new(aria_label: t("bills.views.aria_label"), class: "bg-surface-inset") do |control| %>
<% control.with_segment(t("bills.views.overview"), active: active == "overview", href: bills_path) %>
<% control.with_segment(t("bills.views.calendar"), active: active == "calendar", href: bills_path(view: "calendar")) %>
<% control.with_segment(t("bills.views.paycheck"), active: active == "paycheck", href: bills_path(view: "paycheck")) %>
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index c11af400e0..0d0ca8bf31 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -119,6 +119,24 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
end
end
+ # Laid out like Transactions: the overflow menu, then the primary action,
+ # which a phone shows as a round + that keeps the action's name.
+ test "the bills header lays out its actions like Transactions" do
+ { bills_url => [ I18n.t("bills.index.add_bill"), new_recurring_transaction_path ],
+ bills_url(view: "paycheck") => [ I18n.t("bills.index.add_income"), new_recurring_transaction_path(income: true) ] }.each do |url, (name, href)|
+ get url
+ assert_response :success
+
+ assert_select "main header [data-controller~='DS--menu'] ~ a[href='#{href}']", count: 2
+ assert_select "main header a[class~='hidden'][class~='md:inline-flex'][href='#{href}']", text: name
+ assert_select "main header a[class~='md:hidden'][class~='rounded-full'][aria-label='#{name}'][href='#{href}']"
+ end
+
+ # The switcher's track is drawn on the page, not in the page's own colour.
+ get bills_url
+ assert_select "main [role=group].segmented-control.bg-surface-inset a[aria-current=true]", text: I18n.t("bills.views.overview")
+ end
+
test "index lists a bill" do
bill = create_bill(name: "Rent", amount: 1200)