Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add expandable dialog for debug log table (#3051)

Juan José Mata47525d7a733a
diff --git a/app/components/DS/dialog.rb b/app/components/DS/dialog.rb
index 4a917b91ee..60a5226715 100644
--- a/app/components/DS/dialog.rb
+++ b/app/components/DS/dialog.rb
@@ -40,11 +40,23 @@ class DS::Dialog < DesignSystemComponent
attr_reader :variant, :auto_open, :reload_on_close, :width, :disable_frame, :content_class, :disable_click_outside, :opts, :responsive, :scrollable, :heading_level, :title_id
VARIANTS = %w[modal drawer].freeze
+ # `expanded` is the "give this cramped thing the whole screen" shape used by
+ # expand-on-hover affordances (the dashboard cashflow chart, the debug log
+ # table). It keeps a sliver of viewport margin — unlike `full` — and caps out
+ # so wide tables and charts don't stretch unreadably on ultrawide displays.
+ #
+ # The 96vw only applies from `lg`, where `dialog_inner_classes` drops the
+ # `mx-3` gutter. Below that, a viewport-relative width is the wrong tool:
+ # `vw` counts the scrollbar but the dialog's own box does not, so 96vw + the
+ # 24px gutter overflows a phone by ~11px per side (measured 320–390px), and
+ # flex-shrink cannot absorb it once nowrap content raises the panel's
+ # min-content width. Below `lg` the base `w-full` + `mx-3` already fits.
WIDTHS = {
sm: "lg:max-w-[300px]",
md: "lg:max-w-[550px]",
lg: "lg:max-w-[700px]",
- full: "lg:max-w-full"
+ full: "lg:max-w-full",
+ expanded: "lg:!w-[96vw] max-w-[1650px]"
}.freeze
VALID_HEADING_LEVELS = (1..6).freeze
diff --git a/app/javascript/controllers/expandable_controller.js b/app/javascript/controllers/expandable_controller.js
new file mode 100644
index 0000000000..6ad4b48840
--- /dev/null
+++ b/app/javascript/controllers/expandable_controller.js
@@ -0,0 +1,24 @@
+import { Controller } from "@hotwired/stimulus";
+
+// Connects to data-controller="expandable"
+//
+// Reopens a cramped card (a chart, a wide table) in a roomier modal, mirroring
+// the dashboard cashflow expand button. The trigger lives outside the <dialog>,
+// so it is out of scope for the DS--dialog controller's own actions — this thin
+// wrapper bridges the two.
+//
+// Native <dialog> tracks the previously focused element across showModal() /
+// close(), so focus returns to the expand button on its own.
+export default class extends Controller {
+ static targets = ["dialog"];
+
+ open() {
+ const dialog = this.hasDialogTarget
+ ? this.dialogTarget
+ : this.element.querySelector("dialog");
+
+ if (!dialog || dialog.open) return;
+
+ dialog.showModal();
+ }
+}
diff --git a/app/views/pages/dashboard/_cashflow_sankey.html.erb b/app/views/pages/dashboard/_cashflow_sankey.html.erb
index fa244cd61a..876162e361 100644
--- a/app/views/pages/dashboard/_cashflow_sankey.html.erb
+++ b/app/views/pages/dashboard/_cashflow_sankey.html.erb
@@ -4,7 +4,7 @@
<div class="w-full h-96">
<%= render "pages/dashboard/cashflow_sankey_chart", sankey_data: sankey_data, period: period %>
</div>
- <%= render DS::Dialog.new(id: "cashflow-expanded-dialog", auto_open: false, width: "custom", disable_frame: true, content_class: "!w-[96vw] max-w-[1650px]", data: { action: "close->cashflow-expand#restore" }) do |dialog| %>
+ <%= render DS::Dialog.new(id: "cashflow-expanded-dialog", auto_open: false, width: "expanded", disable_frame: true, data: { action: "close->cashflow-expand#restore" }) do |dialog| %>
<% dialog.with_header(title: t("pages.dashboard.cashflow_sankey.title")) %>
<% dialog.with_body do %>
<div class="w-full h-[85dvh] max-h-[90dvh] overflow-y-auto overscroll-contain">
diff --git a/app/views/settings/debugs/_log_table.html.erb b/app/views/settings/debugs/_log_table.html.erb
new file mode 100644
index 0000000000..ec48ce7d56
--- /dev/null
+++ b/app/views/settings/debugs/_log_table.html.erb
@@ -0,0 +1,46 @@
+<%# Rendered twice: inline in the settings card, and again inside the expanded
+ dialog where it gets the full viewport width. The sticky header only has a
+ scroll container to stick to in the expanded copy; inline it is inert. %>
+<table class="w-full">
+ <thead class="bg-surface border-b border-primary sticky top-0 z-10">
+ <tr>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.time") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.level") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.category") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.source") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.message") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.context") %></th>
+ <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t("settings.debugs.show.table.metadata") %></th>
+ </tr>
+ </thead>
+ <tbody class="divide-y divide-alpha-black-200 theme-dark:divide-alpha-white-200">
+ <% entries.each do |entry| %>
+ <tr>
+ <td class="px-4 py-3 text-sm text-primary whitespace-nowrap align-top"><%= l(entry.created_at, format: :long) %></td>
+ <td class="px-4 py-3 text-sm text-primary whitespace-nowrap align-top"><%= entry.level %></td>
+ <td class="px-4 py-3 text-sm text-primary whitespace-nowrap align-top"><%= entry.category %></td>
+ <td class="px-4 py-3 text-sm text-primary font-mono align-top"><%= entry.source %></td>
+ <td class="px-4 py-3 text-sm text-primary align-top"><%= entry.message %></td>
+ <td class="px-4 py-3 text-xs text-secondary font-mono whitespace-nowrap align-top">
+ <div><%= t("settings.debugs.show.context.provider", value: entry.provider_key.presence || t("settings.debugs.show.missing_value")) %></div>
+ <div><%= t("settings.debugs.show.context.family", value: entry.family_id || t("settings.debugs.show.missing_value")) %></div>
+ <div><%= t("settings.debugs.show.context.account", value: entry.account_id || t("settings.debugs.show.missing_value")) %></div>
+ <div><%= t("settings.debugs.show.context.user", value: entry.user_id || t("settings.debugs.show.missing_value")) %></div>
+ <div><%= t("settings.debugs.show.context.account_provider", value: entry.account_provider_id || t("settings.debugs.show.missing_value")) %></div>
+ </td>
+ <td class="px-4 py-3 text-xs text-secondary align-top">
+ <% if entry.metadata.present? %>
+ <%= render DS::Disclosure.new(variant: :inline) do |disclosure| %>
+ <% disclosure.with_summary_content do %>
+ <span class="text-xs text-secondary"><%= t("settings.debugs.show.table.view_metadata") %></span>
+ <% end %>
+ <pre class="whitespace-pre-wrap break-words"><%= JSON.pretty_generate(entry.metadata) %></pre>
+ <% end %>
+ <% else %>
+ <%= t("settings.debugs.show.missing_value") %>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
diff --git a/app/views/settings/debugs/show.html.erb b/app/views/settings/debugs/show.html.erb
index 921171a14f..3fce47e0b8 100644
--- a/app/views/settings/debugs/show.html.erb
+++ b/app/views/settings/debugs/show.html.erb
@@ -50,53 +50,44 @@
<% end %>
<% end %>
- <div class="bg-container rounded-xl shadow-border-xs overflow-hidden">
+ <%# Seven columns of long-form diagnostics stay cramped however wide the
+ settings page gets, so the whole table can be reopened in a near
+ full-width dialog — same pattern as the dashboard cashflow chart. %>
+ <div class="bg-container rounded-xl shadow-border-xs overflow-hidden group" data-controller="expandable">
<% if @debug_log_entries.any? %>
+ <%# Never hover-only: pointer hover, keyboard focus, and always shown on
+ coarse pointers, where there is no hover to reveal it. Viewport width
+ is the wrong proxy for that — a large tablet is touch-only well past
+ `lg`. Same shape as the dashboard insights feed's row controls. %>
+ <div class="flex items-center justify-end px-4 py-2 border-b border-primary">
+ <%= render DS::Button.new(
+ variant: "icon",
+ size: :sm,
+ icon: "maximize-2",
+ title: t("global.expand"),
+ aria_label: t("global.expand"),
+ class: "opacity-0 group-hover:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100 transition-opacity",
+ data: { action: "click->expandable#open" }
+ ) %>
+ </div>
+
<div class="overflow-x-auto">
- <table class="w-full">
- <thead class="bg-surface border-b border-primary">
- <tr>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.time") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.level") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.category") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.source") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.message") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.context") %></th>
- <th class="px-4 py-3 text-left text-xs font-medium text-secondary uppercase"><%= t(".table.metadata") %></th>
- </tr>
- </thead>
- <tbody class="divide-y divide-alpha-black-200 theme-dark:divide-alpha-white-200">
- <% @debug_log_entries.each do |entry| %>
- <tr>
- <td class="px-4 py-3 text-sm text-primary whitespace-nowrap"><%= l(entry.created_at, format: :long) %></td>
- <td class="px-4 py-3 text-sm text-primary whitespace-nowrap"><%= entry.level %></td>
- <td class="px-4 py-3 text-sm text-primary whitespace-nowrap"><%= entry.category %></td>
- <td class="px-4 py-3 text-sm text-primary font-mono"><%= entry.source %></td>
- <td class="px-4 py-3 text-sm text-primary"><%= entry.message %></td>
- <td class="px-4 py-3 text-xs text-secondary font-mono whitespace-nowrap align-top">
- <div><%= t(".context.provider", value: entry.provider_key.presence || t(".missing_value")) %></div>
- <div><%= t(".context.family", value: entry.family_id || t(".missing_value")) %></div>
- <div><%= t(".context.account", value: entry.account_id || t(".missing_value")) %></div>
- <div><%= t(".context.user", value: entry.user_id || t(".missing_value")) %></div>
- <div><%= t(".context.account_provider", value: entry.account_provider_id || t(".missing_value")) %></div>
- </td>
- <td class="px-4 py-3 text-xs text-secondary align-top">
- <% if entry.metadata.present? %>
- <%= render DS::Disclosure.new(variant: :inline) do |disclosure| %>
- <% disclosure.with_summary_content do %>
- <span class="text-xs text-secondary"><%= t(".table.view_metadata") %></span>
- <% end %>
- <pre class="whitespace-pre-wrap break-words"><%= JSON.pretty_generate(entry.metadata) %></pre>
- <% end %>
- <% else %>
- <%= t(".missing_value") %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
+ <%= render "settings/debugs/log_table", entries: @debug_log_entries %>
</div>
+
+ <%= render DS::Dialog.new(
+ auto_open: false,
+ disable_frame: true,
+ width: "expanded",
+ data: { expandable_target: "dialog" }
+ ) do |dialog| %>
+ <% dialog.with_header(title: t(".title"), subtitle: t(".subtitle")) %>
+ <% dialog.with_body do %>
+ <div class="max-h-[75dvh] overflow-auto overscroll-contain">
+ <%= render "settings/debugs/log_table", entries: @debug_log_entries %>
+ </div>
+ <% end %>
+ <% end %>
<% else %>
<div class="p-8 text-center text-secondary"><%= t(".empty") %></div>
<% end %>
diff --git a/test/controllers/settings/debugs_controller_test.rb b/test/controllers/settings/debugs_controller_test.rb
index 7179738b83..23ca351604 100644
--- a/test/controllers/settings/debugs_controller_test.rb
+++ b/test/controllers/settings/debugs_controller_test.rb
@@ -27,6 +27,31 @@ class Settings::DebugsControllerTest < ActionDispatch::IntegrationTest
assert_match @entry.message, response.body
end
+ test "the log table can be expanded into a larger dialog" do
+ sign_in users(:sure_support_staff)
+
+ get settings_debug_url
+
+ assert_response :success
+ assert_select "[data-controller=expandable]", 1
+ assert_select "button[data-action=?]", "click->expandable#open", count: 1
+
+ # The expanded copy is the same table, so both render every entry.
+ assert_select "table tbody tr", 2
+ assert_select "dialog[data-expandable-target=dialog] table tbody tr", 1
+ end
+
+ test "no expand trigger is rendered when there are no entries" do
+ sign_in users(:sure_support_staff)
+ DebugLogEntry.delete_all
+
+ get settings_debug_url
+
+ assert_response :success
+ assert_select "button[data-action=?]", "click->expandable#open", count: 0
+ assert_select "dialog[data-expandable-target=dialog]", 0
+ end
+
test "non super admins are redirected" do
sign_in users(:family_admin)