Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add DS::Table and move four hand-built tables onto it (#3805)

Guillem Arias Fausteb6ba9c57eb9b
diff --git a/app/components/DS/table.html.erb b/app/components/DS/table.html.erb
new file mode 100644
index 0000000000..51d9b75d15
--- /dev/null
+++ b/app/components/DS/table.html.erb
@@ -0,0 +1,25 @@
+<%= tag.div class: container_classes, **container_opts do %>
+ <%= tag.div class: scroll_classes, **scroll_opts do %>
+ <%# Separate borders, drawn by the cells. With the collapsing model
+ (Tailwind's default for tables) a sticky header's rule stays behind
+ in the table grid and is gone once the body scrolls. %>
+ <table class="w-full border-separate border-spacing-0 text-sm text-primary">
+ <thead>
+ <tr>
+ <% columns.each do |column| %>
+ <%= column %>
+ <% end %>
+ </tr>
+ </thead>
+ <tbody>
+ <% rows.each_with_index do |row, index| %>
+ <%= tag.tr class: row_classes(row) do %>
+ <% columns.each do |column| %>
+ <%= column.cell(row, index) %>
+ <% end %>
+ <% end %>
+ <% end %>
+ </tbody>
+ </table>
+ <% end %>
+<% end %>
diff --git a/app/components/DS/table.rb b/app/components/DS/table.rb
new file mode 100644
index 0000000000..4a378c4427
--- /dev/null
+++ b/app/components/DS/table.rb
@@ -0,0 +1,76 @@
+class DS::Table < DesignSystemComponent
+ # A data table: the card, horizontal scroll, header row, cell padding and row
+ # rules in one place. Extracted because 25 views hand-built <table> markup in
+ # five competing patterns, each with its own padding, dividers and header
+ # style. The table renders every cell from its column definitions, so a
+ # column's alignment is declared once, for its header and its cells, and
+ # padding and borders can't drift from one table to the next.
+ #
+ # <%= render DS::Table.new(rows: payments) do |table| %>
+ # <% table.with_column(t(".date")) { |payment| l(payment.date, format: :long) } %>
+ # <% table.with_column(t(".amount"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.amount) } %>
+ # <% end %>
+ #
+ # A column's block is called with each row and its index. It has to output
+ # markup or return a String: Rails' `capture` drops any other return value,
+ # so a bare Integer renders as an empty cell (call `to_s` on it).
+ renders_many :columns, ->(header, **options, &cell) do
+ DS::Table::Column.new(header, cell: cell, sticky: sticky_header, **options)
+ end
+
+ attr_reader :rows, :inset, :sticky_header, :label, :row_class, :opts
+
+ # @param rows [Enumerable] the records, one table row each
+ # @param inset [Boolean] frame the table in container-inset, for a table that
+ # sits inside a card the way a list group does. A table on the page
+ # background is a card of its own.
+ # @param sticky_header [Boolean] cap the height and keep the header row in view
+ # while the body scrolls under it, for long tables such as a loan schedule
+ # @param label [String, nil] accessible name for the scroll area. Makes it a
+ # focusable region so a keyboard user can scroll a table that overflows;
+ # pass one whenever the table can scroll, including sideways on a narrow
+ # screen.
+ # @param row_class [Proc, nil] called with each row, returns extra classes for
+ # its <tr>, e.g. the tint on a loan's past payments
+ # @param opts [Hash] forwarded to the outer element; :class merges with the base classes
+ def initialize(rows:, inset: false, sticky_header: false, label: nil, row_class: nil, **opts)
+ @rows = rows
+ @inset = inset
+ @sticky_header = sticky_header
+ @label = label
+ @row_class = row_class
+ @opts = opts
+ end
+
+ def container_classes
+ class_names(("rounded-xl bg-container-inset p-1" if inset), opts[:class])
+ end
+
+ # Caller options minus :class, which container_classes has already merged.
+ def container_opts
+ opts.except(:class)
+ end
+
+ # `table-scroll` shows edge shadows while a wide table has more to scroll.
+ # Its cover gradients default to container-inset, so scroll_opts points them
+ # at the card's own background. Inside the inset frame the card takes the
+ # frame's inner radius (xl less the 4px padding is lg); on its own it takes
+ # DS::Card's.
+ def scroll_classes
+ class_names(
+ "table-scroll shadow-border-xs",
+ inset ? "rounded-lg" : "rounded-xl",
+ ("max-h-128 overflow-y-auto" if sticky_header),
+ ("focus-ring" if label)
+ )
+ end
+
+ def scroll_opts
+ attrs = { style: "--table-scroll-bg: var(--color-container)" }
+ label ? attrs.merge(role: "region", tabindex: 0, aria: { label: label }) : attrs
+ end
+
+ def row_classes(row)
+ row_class&.call(row)
+ end
+end
diff --git a/app/components/DS/table/column.rb b/app/components/DS/table/column.rb
new file mode 100644
index 0000000000..10b7719f61
--- /dev/null
+++ b/app/components/DS/table/column.rb
@@ -0,0 +1,66 @@
+class DS::Table::Column < DesignSystemComponent
+ # One column of a DS::Table: its header cell, and how to render its cell in
+ # each row. Declared with `table.with_column`; the table renders it.
+ ALIGNS = %i[left right].freeze
+
+ attr_reader :header
+
+ # @param header [String] the column heading
+ # @param cell [Proc] renders the cell for a row, given the row and its index
+ # @param sticky [Boolean] set by the table when its header row is sticky
+ # @param align [Symbol] :left (default) or :right, for the header and the cells
+ # @param numeric [Boolean] a column of figures: right-aligned, tabular digits,
+ # never wrapped mid-number. Implies align: :right.
+ # @param row_header [Boolean] render the cells as <th scope="row">, for the
+ # column that names each row
+ # @param class [String, nil] extra classes for the body cells, e.g. "text-secondary"
+ # or "privacy-sensitive"
+ def initialize(header, cell:, sticky: false, align: :left, numeric: false, row_header: false, class: nil)
+ @header = header
+ @cell = cell
+ @sticky = sticky
+ @numeric = numeric
+ # to_s first so a nil or unrecognized value falls back instead of raising.
+ candidate = align.to_s.to_sym
+ @align = numeric ? :right : (ALIGNS.include?(candidate) ? candidate : :left)
+ @row_header = row_header
+ @cell_class = binding.local_variable_get(:class)
+ end
+
+ # The header cell. Its rule is the table's only full-weight line, left to do
+ # the one job a line is good at, separating the labels from the data; the
+ # rows use the subdued rule between them.
+ def call
+ tag.th header, scope: "col", class: class_names(
+ "px-4 py-3 border-b border-divider text-xs uppercase font-medium text-secondary",
+ alignment_classes,
+ # z-10 so a privacy-blurred amount, which paints in a layer of its own,
+ # doesn't show through the header as it scrolls under it.
+ ("sticky top-0 z-10 bg-container" if @sticky)
+ )
+ end
+
+ # The cell for one row. The first row has no top rule: the header's is right above it.
+ def cell(row, index)
+ content_tag(
+ @row_header ? :th : :td,
+ @cell&.call(row, index),
+ scope: ("row" if @row_header),
+ class: class_names(
+ "px-4 py-3",
+ ("border-t border-subdued" if index.positive?),
+ ("font-medium" if @row_header),
+ alignment_classes,
+ @cell_class
+ )
+ )
+ end
+
+ private
+ def alignment_classes
+ class_names(
+ @align == :right ? "text-right" : "text-left",
+ ("tabular-nums whitespace-nowrap" if @numeric)
+ )
+ end
+end
diff --git a/app/views/admin/system_health/_background_jobs.html.erb b/app/views/admin/system_health/_background_jobs.html.erb
index ccf45adbef..26ac7fcd6e 100644
--- a/app/views/admin/system_health/_background_jobs.html.erb
+++ b/app/views/admin/system_health/_background_jobs.html.erb
@@ -78,26 +78,13 @@
<% if breakdown.empty? %>
<p class="text-sm text-secondary"><%= t("admin.system_health.show.values.no_queues") %></p>
<% else %>
- <table class="w-full text-sm">
- <thead>
- <tr class="text-left text-secondary border-b border-primary">
- <th class="py-2 font-medium"><%= t("admin.system_health.show.labels.queue") %></th>
- <th class="py-2 font-medium"><%= t("admin.system_health.show.labels.size") %></th>
- <th class="py-2 font-medium"><%= t("admin.system_health.show.labels.latency") %></th>
- </tr>
- </thead>
- <tbody class="divide-y divide-primary">
- <% breakdown.each do |name, size, latency| %>
- <tr>
- <td class="py-2 text-primary"><%= name %></td>
- <td class="py-2 text-primary"><%= number_with_delimiter(size) %></td>
- <td class="py-2 text-primary">
- <%= t("admin.system_health.show.values.seconds", seconds: number_with_precision(latency, precision: 1)) %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
+ <%= render DS::Table.new(rows: breakdown, inset: true, label: t("admin.system_health.show.queues_section_title")) do |table| %>
+ <% table.with_column(t("admin.system_health.show.labels.queue")) { |(name)| name } %>
+ <% table.with_column(t("admin.system_health.show.labels.size"), numeric: true) { |(_name, size)| number_with_delimiter(size) } %>
+ <% table.with_column(t("admin.system_health.show.labels.latency"), numeric: true) do |(_name, _size, latency)| %>
+ <%= t("admin.system_health.show.values.seconds", seconds: number_with_precision(latency, precision: 1)) %>
+ <% end %>
+ <% end %>
<% end %>
</div>
<% if push_notification_test %>
diff --git a/app/views/admin/system_health/_push_notifications.html.erb b/app/views/admin/system_health/_push_notifications.html.erb
index e28a50babd..18c328cee4 100644
--- a/app/views/admin/system_health/_push_notifications.html.erb
+++ b/app/views/admin/system_health/_push_notifications.html.erb
@@ -27,27 +27,20 @@
<% if latest_test %>
<div class="space-y-3">
<p class="text-sm text-secondary"><%= t("admin.system_health.push_notifications.result_help") %></p>
- <div class="overflow-x-auto">
- <table class="w-full text-sm text-left">
- <thead>
- <tr class="border-b border-primary text-secondary">
- <% %w[device environment status checked_at].each do |column| %>
- <th scope="col" class="py-2 font-medium"><%= t("admin.system_health.push_notifications.columns.#{column}") %></th>
- <% end %>
- </tr>
- </thead>
- <tbody>
- <% results.each_with_index do |result, index| %>
- <tr class="border-b border-primary text-primary">
- <th scope="row" class="py-2 font-medium"><%= t("admin.system_health.push_notifications.device", number: index + 1) %></th>
- <td class="py-2"><%= t("admin.system_health.push_notifications.environments.#{result[:environment]}") %></td>
- <td class="py-2"><%= t("admin.system_health.push_notifications.statuses.#{result[:status]}") %></td>
- <td class="py-2"><%= result[:checked_at] ? l(result[:checked_at], format: :long) : t("admin.system_health.push_notifications.pending") %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
+ <%= render DS::Table.new(rows: results, inset: true, label: t("admin.system_health.push_notifications.results_label")) do |table| %>
+ <% table.with_column(t("admin.system_health.push_notifications.columns.device"), row_header: true) do |_result, index| %>
+ <%= t("admin.system_health.push_notifications.device", number: index + 1) %>
+ <% end %>
+ <% table.with_column(t("admin.system_health.push_notifications.columns.environment")) do |result| %>
+ <%= t("admin.system_health.push_notifications.environments.#{result[:environment]}") %>
+ <% end %>
+ <% table.with_column(t("admin.system_health.push_notifications.columns.status")) do |result| %>
+ <%= t("admin.system_health.push_notifications.statuses.#{result[:status]}") %>
+ <% end %>
+ <% table.with_column(t("admin.system_health.push_notifications.columns.checked_at")) do |result| %>
+ <%= result[:checked_at] ? l(result[:checked_at], format: :long) : t("admin.system_health.push_notifications.pending") %>
+ <% end %>
+ <% end %>
<%= render DS::Button.new(
href: admin_system_health_path(tab: "background_jobs", anchor: "push-notifications"), method: :get,
variant: :outline, size: :sm, icon: "refresh-cw",
diff --git a/app/views/bills/all.html.erb b/app/views/bills/all.html.erb
index ab1dff122d..7783179558 100644
--- a/app/views/bills/all.html.erb
+++ b/app/views/bills/all.html.erb
@@ -132,76 +132,54 @@
<% end %>
</div>
- <div class="hidden @3xl:block bg-container rounded-lg shadow-border-xs overflow-x-auto">
- <table class="w-full">
- <thead>
- <%# The one rule on these pages that stays at full weight. Row
- dividers dropped to `subdued` so the content carries the
- structure, which leaves the header rule free to do the one job a
- line is actually good at: separating the labels from the data. %>
- <tr class="text-xs uppercase font-medium text-secondary border-b border-divider">
- <th class="text-left py-3 px-3"><%= t(".col_name") %></th>
- <th class="text-left py-3 px-2"><%= t(".col_type") %></th>
- <th class="text-left py-3 px-2"><%= t(".col_frequency") %></th>
- <th class="text-right py-3 px-2"><%= t(".col_amount") %></th>
- <th class="text-left py-3 px-2"><%= t(".col_next") %></th>
- <th class="text-left py-3 px-2"><%= t(".col_status") %></th>
- <th class="text-right py-3 px-3"><%= t(".col_actions") %></th>
- </tr>
- </thead>
- <tbody class="divide-y divide-subdued">
- <% @all_series.each do |series| %>
- <tr>
- <td class="py-3 px-3">
- <%= link_to series.display_name, bill_path(series),
- class: "text-sm font-medium text-primary hover:underline" %>
- </td>
- <td class="py-3 px-2 text-sm text-secondary"><%= t(".types.#{series.bill_type}") %></td>
- <td class="py-3 px-2 text-sm text-secondary"><%= frequency_label(series) %></td>
- <td class="py-3 px-2 text-sm text-primary text-right privacy-sensitive">
- <% amount = Money.new(series.amount.abs, series.currency) %>
- <% monthly = series.monthly_equivalent_amount.abs %>
- <%= format_money(amount) %>
- <%# A monthly bill's monthly equivalent is its own amount, so the
- second line said "$5.99" under "$5.99". It only carries
- information for the other cadences. %>
- <% if monthly != amount %>
- <p class="text-xs text-secondary"><%= t(".monthly_equivalent", amount: format_money(monthly)) %></p>
- <% end %>
- </td>
- <td class="py-3 px-2 text-sm text-secondary"><%= series.next_expected_date ? bills_upcoming_date(series.next_expected_date) : "–" %></td>
- <td class="py-3 px-2 text-sm">
- <%= render DS::Pill.new(label: t("recurring_transactions.status.#{series.status}"), tone: recurring_status_pill_tone(series.status), marker: false) %>
- </td>
- <td class="py-3 px-3 text-right">
- <%= render DS::Menu.new do |menu| %>
- <% menu.with_item(
- variant: "link",
- text: t("recurring_transactions.edit.trigger_label"),
- icon: "pencil",
- href: edit_recurring_transaction_path(series),
- data: { turbo_frame: :modal }) %>
- <% 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 %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
+ <%= 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" %>
+ <% 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) } %>
+ <% table.with_column(t(".col_amount"), numeric: true, class: "privacy-sensitive") do |series| %>
+ <% amount = Money.new(series.amount.abs, series.currency) %>
+ <% monthly = series.monthly_equivalent_amount.abs %>
+ <%= format_money(amount) %>
+ <%# A monthly bill's monthly equivalent is its own amount, so the
+ second line said "$5.99" under "$5.99". It only carries
+ information for the other cadences. %>
+ <% if monthly != amount %>
+ <p class="text-xs text-secondary"><%= t(".monthly_equivalent", amount: format_money(monthly)) %></p>
+ <% end %>
+ <% end %>
+ <% table.with_column(t(".col_next"), class: "text-secondary") do |series| %>
+ <%= series.next_expected_date ? bills_upcoming_date(series.next_expected_date) : "–" %>
+ <% end %>
+ <% table.with_column(t(".col_status")) do |series| %>
+ <%= render DS::Pill.new(label: t("recurring_transactions.status.#{series.status}"), tone: recurring_status_pill_tone(series.status), marker: false) %>
+ <% end %>
+ <% table.with_column(t(".col_actions"), align: :right) do |series| %>
+ <%= render DS::Menu.new do |menu| %>
+ <% menu.with_item(
+ variant: "link",
+ text: t("recurring_transactions.edit.trigger_label"),
+ icon: "pencil",
+ href: edit_recurring_transaction_path(series),
+ data: { turbo_frame: :modal }) %>
+ <% 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 %>
+ <% end %>
+ <% end %>
</div>
<% end %>
diff --git a/app/views/loans/tabs/_schedule.html.erb b/app/views/loans/tabs/_schedule.html.erb
index 3ab5fc4935..7811d2e9a5 100644
--- a/app/views/loans/tabs/_schedule.html.erb
+++ b/app/views/loans/tabs/_schedule.html.erb
@@ -47,32 +47,17 @@
<p class="text-sm text-secondary"><%= t(".variable_rate_notice") %></p>
<% end %>
- <div class="rounded-xl bg-container shadow-xs border border-alpha-black-25 overflow-hidden">
- <div class="max-h-[32rem] overflow-y-auto overflow-x-auto">
- <table class="w-full text-sm">
- <thead class="sticky top-0 bg-container border-b border-alpha-black-25">
- <tr class="text-secondary text-left">
- <th scope="col" class="font-medium px-4 py-3"><%= t(".number") %></th>
- <th scope="col" class="font-medium px-4 py-3"><%= t(".date") %></th>
- <th scope="col" class="font-medium px-4 py-3 text-right"><%= t(".payment") %></th>
- <th scope="col" class="font-medium px-4 py-3 text-right"><%= t(".principal") %></th>
- <th scope="col" class="font-medium px-4 py-3 text-right"><%= t(".interest") %></th>
- <th scope="col" class="font-medium px-4 py-3 text-right"><%= t(".remaining_balance") %></th>
- </tr>
- </thead>
- <tbody>
- <% payments.each do |payment| %>
- <tr class="border-b border-alpha-black-25 last:border-0 <%= "bg-container-inset" if payment.date <= today %>">
- <td class="px-4 py-3 text-secondary tabular-nums"><%= payment.number %></td>
- <td class="px-4 py-3 text-primary"><%= l payment.date, format: :long %></td>
- <td class="px-4 py-3 text-right text-primary tabular-nums privacy-sensitive"><%= format_money payment.payment %></td>
- <td class="px-4 py-3 text-right text-primary tabular-nums privacy-sensitive"><%= format_money payment.principal %></td>
- <td class="px-4 py-3 text-right text-secondary tabular-nums privacy-sensitive"><%= format_money payment.interest %></td>
- <td class="px-4 py-3 text-right text-primary tabular-nums privacy-sensitive"><%= format_money payment.ending_balance %></td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
- </div>
+ <%= render DS::Table.new(
+ rows: payments,
+ sticky_header: true,
+ label: t("accounts.show.tabs.schedule"),
+ row_class: ->(payment) { "bg-container-inset" if payment.date <= today }
+ ) do |table| %>
+ <% table.with_column(t(".number"), class: "text-secondary tabular-nums") { |payment| payment.number.to_s } %>
+ <% table.with_column(t(".date")) { |payment| l(payment.date, format: :long) } %>
+ <% table.with_column(t(".payment"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.payment) } %>
+ <% table.with_column(t(".principal"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.principal) } %>
+ <% table.with_column(t(".interest"), numeric: true, class: "text-secondary privacy-sensitive") { |payment| format_money(payment.interest) } %>
+ <% table.with_column(t(".remaining_balance"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.ending_balance) } %>
+ <% end %>
</div>
diff --git a/config/locales/views/admin/system_health/ca.yml b/config/locales/views/admin/system_health/ca.yml
index a060d54abc..b6c670b201 100644
--- a/config/locales/views/admin/system_health/ca.yml
+++ b/config/locales/views/admin/system_health/ca.yml
@@ -8,6 +8,7 @@ ca:
title: Notificacions push
requested_at: Última prova sol·licitada el %{time}
result_help: Que APNs l'accepti no confirma que s'hagi lliurat al dispositiu. Actualitza per veure els resultats del worker. Els resultats es conserven durant 24 hores.
+ results_label: Resultats de la prova
device: Dispositiu %{number}
pending: Pendent
refresh: Actualitza els resultats
diff --git a/config/locales/views/admin/system_health/de.yml b/config/locales/views/admin/system_health/de.yml
index 0fc2e69353..5bc30757dd 100644
--- a/config/locales/views/admin/system_health/de.yml
+++ b/config/locales/views/admin/system_health/de.yml
@@ -8,6 +8,7 @@ de:
title: "Push-Benachrichtigungen"
requested_at: "Letzter Test angefordert am %{time}"
result_help: "Die Annahme durch APNs bestätigt nicht die Zustellung auf deinem Gerät. Aktualisiere die Ergebnisse, um den Worker-Status zu sehen. Ergebnisse werden 24 Stunden gespeichert."
+ results_label: "Testergebnisse"
device: "Gerät %{number}"
pending: "Ausstehend"
refresh: "Ergebnisse aktualisieren"
diff --git a/config/locales/views/admin/system_health/en.yml b/config/locales/views/admin/system_health/en.yml
index 6526f7aad8..455acd7611 100644
--- a/config/locales/views/admin/system_health/en.yml
+++ b/config/locales/views/admin/system_health/en.yml
@@ -8,6 +8,7 @@ en:
title: "Push notifications"
requested_at: "Latest test requested at %{time}"
result_help: "APNs acceptance does not confirm delivery to your device. Refresh to see worker results. Results are retained for 24 hours."
+ results_label: "Test results"
device: "Device %{number}"
pending: "Pending"
refresh: "Refresh results"
diff --git a/config/locales/views/admin/system_health/fr.yml b/config/locales/views/admin/system_health/fr.yml
index b259fbb2c6..3469dc4816 100644
--- a/config/locales/views/admin/system_health/fr.yml
+++ b/config/locales/views/admin/system_health/fr.yml
@@ -8,6 +8,7 @@ fr:
title: "Notifications push"
requested_at: "Dernier test demandé le %{time}"
result_help: "L’acceptation par APNs ne confirme pas la réception sur votre appareil. Actualisez pour voir les résultats du worker. Les résultats sont conservés pendant 24 heures."
+ results_label: "Résultats du test"
device: "Appareil %{number}"
pending: "En attente"
refresh: "Actualiser les résultats"
diff --git a/config/locales/views/admin/system_health/pt-PT.yml b/config/locales/views/admin/system_health/pt-PT.yml
index c692162463..443e1f3054 100644
--- a/config/locales/views/admin/system_health/pt-PT.yml
+++ b/config/locales/views/admin/system_health/pt-PT.yml
@@ -8,6 +8,7 @@ pt-PT:
title: "Notificações push"
requested_at: "Último teste pedido em %{time}"
result_help: "A aceitação pelo APNs não confirma a entrega no dispositivo. Atualize para ver os resultados do worker. Os resultados são guardados durante 24 horas."
+ results_label: "Resultados do teste"
device: "Dispositivo %{number}"
pending: "Pendente"
refresh: "Atualizar resultados"
diff --git a/config/locales/views/admin/system_health/ru.yml b/config/locales/views/admin/system_health/ru.yml
index 4b5bf4859e..c57a564427 100644
--- a/config/locales/views/admin/system_health/ru.yml
+++ b/config/locales/views/admin/system_health/ru.yml
@@ -8,6 +8,7 @@ ru:
title: Push-уведомления
requested_at: 'Последний тест запрошен: %{time}'
result_help: Принятие APNs не подтверждает доставку на ваше устройство. Обновите страницу, чтобы увидеть результаты воркера. Результаты хранятся 24 часа.
+ results_label: Результаты теста
device: Устройство %{number}
pending: Ожидание
refresh: Обновить результаты
diff --git a/config/locales/views/admin/system_health/tr.yml b/config/locales/views/admin/system_health/tr.yml
index 7086e6d821..ab501e8ef1 100644
--- a/config/locales/views/admin/system_health/tr.yml
+++ b/config/locales/views/admin/system_health/tr.yml
@@ -8,6 +8,7 @@ tr:
title: Anlık bildirimler
requested_at: Son test isteği %{time}
result_help: APNs tarafından kabul edilmesi, bildirimin cihazınıza ulaştığını doğrulamaz. Çalışan sonuçlarını görmek için yenileyin. Sonuçlar 24 saat saklanır.
+ results_label: Test sonuçları
device: Cihaz %{number}
pending: Beklemede
refresh: Sonuçları yenile
diff --git a/config/locales/views/admin/system_health/uk.yml b/config/locales/views/admin/system_health/uk.yml
index 810ff39ac4..a9c145f285 100644
--- a/config/locales/views/admin/system_health/uk.yml
+++ b/config/locales/views/admin/system_health/uk.yml
@@ -8,6 +8,7 @@ uk:
title: Push-сповіщення
requested_at: Останній тест запитано %{time}
result_help: Прийняття APNs не підтверджує доставку на ваш пристрій. Оновіть сторінку, щоб побачити результати воркера. Результати зберігаються 24 години.
+ results_label: Результати тесту
device: Пристрій %{number}
pending: Очікується
refresh: Оновити результати
diff --git a/docs/llm-guides/design-system.md b/docs/llm-guides/design-system.md
index 4548f3f78c..b2bb8536a4 100644
--- a/docs/llm-guides/design-system.md
+++ b/docs/llm-guides/design-system.md
@@ -20,3 +20,25 @@ and existing [`DS::*` components](../../app/components/DS/) before building UI.
For templates, Hotwire, Stimulus and localization guidance, see the
[UI guide](ui.md).
+
+## Tables
+
+Render data tables with [`DS::Table`](../../app/components/DS/table.rb), not
+hand-written `<table>` markup. Declare each column once; the table renders the
+header and every cell with the standard padding, header style and row rules.
+
+```erb
+<%= render DS::Table.new(rows: payments) do |table| %>
+ <% table.with_column(t(".date")) { |payment| l(payment.date, format: :long) } %>
+ <% table.with_column(t(".amount"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.amount) } %>
+<% end %>
+```
+
+- `numeric: true` for figures (right-aligned, tabular digits, no wrapping);
+ `align: :right` for other right-hand columns such as actions.
+- `inset: true` when the table sits inside a card. On the page background the
+ table is a card of its own.
+- `sticky_header: true` for long tables.
+- Pass `label:` whenever the table can scroll, including sideways on a narrow
+ screen, so keyboard users can reach it.
+- A column block must output markup or return a String; call `to_s` on numbers.
diff --git a/test/components/DS/table_test.rb b/test/components/DS/table_test.rb
new file mode 100644
index 0000000000..3366443d1d
--- /dev/null
+++ b/test/components/DS/table_test.rb
@@ -0,0 +1,108 @@
+require "test_helper"
+
+class DS::TableTest < ViewComponent::TestCase
+ ROWS = [
+ { name: "Rent", amount: "$1,500.00" },
+ { name: "Internet", amount: "$60.00" }
+ ].freeze
+
+ test "renders a header cell per column and a cell per row and column" do
+ render_table
+
+ assert_selector "thead th[scope='col'].uppercase.text-secondary.border-b.border-divider", count: 2
+ assert_selector "thead th:first-child", text: "Name"
+ assert_selector "tbody tr", count: 2
+ assert_selector "tbody tr:first-child td:first-child", text: "Rent"
+ assert_selector "tbody tr:last-child td:last-child", text: "$60.00"
+ assert_selector "tbody td.px-4.py-3", count: 4
+ end
+
+ # The header's rule separates it from the first row; every later row draws
+ # its own top rule. Borders sit on the cells because the table is border-separate.
+ test "draws the subdued rule above every row but the first" do
+ render_table
+
+ assert_selector "table.border-separate"
+ assert_no_selector "tbody tr:first-child td.border-t"
+ assert_selector "tbody tr:last-child td.border-t.border-subdued", count: 2
+ end
+
+ test "right-aligns a numeric column's header and cells with tabular digits" do
+ render_table
+
+ assert_selector "thead th:last-child.text-right.tabular-nums.whitespace-nowrap"
+ assert_selector "tbody td:last-child.text-right.tabular-nums.whitespace-nowrap", count: 2
+ assert_selector "tbody td:first-child.text-left", count: 2
+ assert_no_selector "tbody td:first-child.tabular-nums"
+ end
+
+ test "right-aligns without the numeric treatment, and falls back to left for an unknown alignment" do
+ render_inline(DS::Table.new(rows: ROWS)) do |table|
+ table.with_column("Actions", align: :right) { "…" }
+ table.with_column("Name", align: :nonsense) { |row| row[:name] }
+ end
+
+ assert_selector "thead th:first-child.text-right"
+ assert_no_selector "thead th:first-child.tabular-nums"
+ assert_selector "thead th:last-child.text-left"
+ end
+
+ test "passes each row and its index to the cell block and applies column classes to body cells only" do
+ render_inline(DS::Table.new(rows: ROWS)) do |table|
+ table.with_column("Device", row_header: true) { |_row, index| "Device #{index + 1}" }
+ table.with_column("Amount", class: "privacy-sensitive") { |row| row[:amount] }
+ end
+
+ assert_selector "tbody th[scope='row'].font-medium", text: "Device 1"
+ assert_selector "tbody th[scope='row']", text: "Device 2"
+ assert_selector "tbody td.privacy-sensitive", count: 2
+ assert_no_selector "thead .privacy-sensitive"
+ end
+
+ test "adds row classes from the row_class proc" do
+ render_inline(DS::Table.new(rows: ROWS, row_class: ->(row) { "bg-container-inset" if row[:name] == "Rent" })) do |table|
+ table.with_column("Name") { |row| row[:name] }
+ end
+
+ assert_selector "tbody tr.bg-container-inset", count: 1, text: "Rent"
+ end
+
+ test "stands alone as a card by default and sits in an inset frame on request" do
+ render_table
+ assert_selector "div.table-scroll.rounded-xl.shadow-border-xs"
+ assert_no_selector ".bg-container-inset"
+
+ render_table(inset: true)
+ assert_selector "div.rounded-xl.bg-container-inset.p-1 > div.table-scroll.rounded-lg"
+ end
+
+ test "caps the height and makes the header cells sticky" do
+ render_table(sticky_header: true)
+
+ assert_selector "div.table-scroll.max-h-128.overflow-y-auto"
+ assert_selector "thead th.sticky.top-0.z-10.bg-container", count: 2
+ end
+
+ # A scroll area needs to be focusable, and named, for a keyboard user to scroll it.
+ test "makes the scroll area a named, focusable region only when given a label" do
+ render_table
+ assert_no_selector "[role='region']"
+
+ render_table(label: "Payment schedule")
+ assert_selector "div.table-scroll.focus-ring[role='region'][tabindex='0'][aria-label='Payment schedule']"
+ end
+
+ test "merges an extra class and forwards other options to the outer element" do
+ render_table(class: "hidden @3xl:block", id: "bills-table")
+
+ assert_selector "div#bills-table.hidden > div.table-scroll"
+ end
+
+ private
+ def render_table(**options)
+ render_inline(DS::Table.new(rows: ROWS, **options)) do |table|
+ table.with_column("Name") { |row| row[:name] }
+ table.with_column("Amount", numeric: true) { |row| row[:amount] }
+ end
+ end
+end
diff --git a/test/components/previews/table_component_preview.rb b/test/components/previews/table_component_preview.rb
new file mode 100644
index 0000000000..af1a017bc6
--- /dev/null
+++ b/test/components/previews/table_component_preview.rb
@@ -0,0 +1,38 @@
+class TableComponentPreview < ViewComponent::Preview
+ BILLS = [
+ { name: "Rent", frequency: "Monthly", amount: "$1,500.00", status: "Active" },
+ { name: "Streaming", frequency: "Monthly", amount: "$15.99", status: "Active" },
+ { name: "Car insurance", frequency: "Every 6 months", amount: "$412.30", status: "Paused" }
+ ].freeze
+
+ # A table on the page background is a card of its own.
+ # @display container_classes max-w-[640px]
+ def default
+ render DS::Table.new(rows: BILLS, label: "Bills") do |table|
+ table.with_column("Name") { |bill| bill[:name] }
+ table.with_column("Frequency", class: "text-secondary") { |bill| bill[:frequency] }
+ table.with_column("Amount", numeric: true) { |bill| bill[:amount] }
+ table.with_column("Status") { |bill| bill[:status] }
+ end
+ end
+
+ # Inside a card, the table sits in an inset frame, the way a list group does.
+ # @display container_classes max-w-[640px]
+ def inset
+ render_with_template(template: "table_component_preview/inset")
+ end
+
+ # A long table caps its height and keeps the header in view. The label makes
+ # the scroll area a named region a keyboard user can focus and scroll.
+ # @display container_classes max-w-[640px]
+ def sticky_header
+ payments = (1..36).map { |number| { number: number, balance: 36_000 - number * 1_000 } }
+
+ render DS::Table.new(rows: payments, sticky_header: true, label: "Payment schedule",
+ row_class: ->(payment) { "bg-container-inset" if payment[:number] <= 6 }) do |table|
+ table.with_column("#", class: "text-secondary tabular-nums") { |payment| payment[:number].to_s }
+ table.with_column("Payment", numeric: true) { "$1,000.00" }
+ table.with_column("Remaining balance", numeric: true) { |payment| ActiveSupport::NumberHelper.number_to_currency(payment[:balance]) }
+ end
+ end
+end
diff --git a/test/components/previews/table_component_preview/inset.html.erb b/test/components/previews/table_component_preview/inset.html.erb
new file mode 100644
index 0000000000..316817f0b8
--- /dev/null
+++ b/test/components/previews/table_component_preview/inset.html.erb
@@ -0,0 +1,10 @@
+<%= render DS::Card.new do %>
+ <h2 class="text-lg font-semibold text-primary mb-1">Queues</h2>
+ <p class="text-sm text-secondary mb-4">Jobs waiting in each queue.</p>
+
+ <%= render DS::Table.new(rows: [ [ "default", 12, 0.4 ], [ "high_priority", 0, 0.0 ], [ "low_priority", 1_204, 38.2 ] ], inset: true, label: "Queues") do |table| %>
+ <% table.with_column("Queue") { |(name)| name } %>
+ <% table.with_column("Size", numeric: true) { |(_name, size)| number_with_delimiter(size) } %>
+ <% table.with_column("Latency", numeric: true) { |(_name, _size, latency)| "#{latency}s" } %>
+ <% end %>
+<% end %>
diff --git a/test/controllers/admin/system_health_controller_test.rb b/test/controllers/admin/system_health_controller_test.rb
index 4e673c4b65..f422f88aca 100644
--- a/test/controllers/admin/system_health_controller_test.rb
+++ b/test/controllers/admin/system_health_controller_test.rb
@@ -47,6 +47,9 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
assert_match(/Healthy/, response.body)
assert_select "button[role='tab']", text: "AI status"
assert_select "[data-ds--tabs-navigate-on-change-value='true']"
+ # Nothing in the queue table takes focus, so on a narrow screen the scroll
+ # area has to be a named tab stop of its own for a keyboard to scroll it.
+ assert_select "[role='region'][aria-label='Queues']"
end
test "renders degraded state with reason when Sidekiq is unhealthy" do
diff --git a/test/controllers/admin/system_health_push_notifications_test.rb b/test/controllers/admin/system_health_push_notifications_test.rb
index e9f771ae34..7f0c6698d2 100644
--- a/test/controllers/admin/system_health_push_notifications_test.rb
+++ b/test/controllers/admin/system_health_push_notifications_test.rb
@@ -36,6 +36,8 @@ class Admin::SystemHealthPushNotificationsTest < ActionDispatch::IntegrationTest
assert_select "h2", text: "Push notifications"
assert_match "Latest test requested at", response.body
assert_select "td", text: "Queued"
+ # Named for its contents: "Push notifications" already names the section.
+ assert_select "[role='region'][aria-label='Test results']"
assert_match "does not confirm delivery", response.body
end
@@ -97,7 +99,7 @@ class Admin::SystemHealthPushNotificationsTest < ActionDispatch::IntegrationTest
test "all system health locales include the notification labels and outcomes" do
%i[en de fr pt-PT].each do |locale|
- %w[title requested_at send_test messages.no_devices messages.queued statuses.accepted statuses.failed].each do |key|
+ %w[title requested_at results_label send_test messages.no_devices messages.queued statuses.accepted statuses.failed].each do |key|
assert_kind_of String, I18n.t("admin.system_health.push_notifications.#{key}", locale: locale, time: "2026-09-12", fallback: false, raise: true)
end
end
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rb
index fe94318b2c..12f58379dd 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -512,6 +512,13 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
assert_match "Alpha bill", response.body
assert_match "Beta paused", response.body
assert_match "Gamma income", response.body
+ # DS::Table renders the desktop table's cells from blocks written in this
+ # view, so their relative keys still have to resolve against bills/all.
+ assert_select "table td", text: I18n.t("bills.all.types.bill")
+ assert_select ".translation_missing", false
+ # Seven columns can overflow just above @3xl, where the table replaces the
+ # cards: the scroll area is named, so a keyboard can reach the columns.
+ assert_select "[role=region][aria-label=?]", I18n.t("bills.views.all")
get bills_url(view: "all", q: { status: "paused" })
assert_match "Beta paused", response.body