From ff2d2add3eeeaf99a4332e127f00d56973048d13 Mon Sep 17 00:00:00 2001 From: Alessio Cappa Date: Wed, 21 Jan 2026 23:08:16 +0100 Subject: [PATCH] feat: Category breakdown table UI --- app/views/reports/_breakdown_table.html.erb | 139 ++++++-------------- app/views/reports/_category_row.html.erb | 50 +++++++ 2 files changed, 90 insertions(+), 99 deletions(-) create mode 100644 app/views/reports/_category_row.html.erb diff --git a/app/views/reports/_breakdown_table.html.erb b/app/views/reports/_breakdown_table.html.erb index 7fb9df17f..4d456317f 100644 --- a/app/views/reports/_breakdown_table.html.erb +++ b/app/views/reports/_breakdown_table.html.erb @@ -14,107 +14,48 @@ (<%= Money.new(total, Current.family.currency).format %>) -
- - - - - - - - - - <% groups.each do |group| %> - <% percentage = total.zero? ? 0 : (group[:total].to_f / total * 100).round(1) %> - <% has_subcategories = group[:subcategories].present? && group[:subcategories].any? %> - - - - - - <%# Render subcategories if present %> - <% if has_subcategories %> - <% group[:subcategories].each do |subcategory| %> - <% sub_percentage = total.zero? ? 0 : (subcategory[:total].to_f / total * 100).round(1) %> - - - - - +
+
+
+
<%= t("reports.transactions_breakdown.table.category") %>
+
+ <%= link_to reports_path(amount_sort_params), class: "inline-flex items-center gap-1 hover:text-primary" do %> + <%= t("reports.transactions_breakdown.table.amount") %> + <% if current_sort_by == "amount" %> + <%= icon(current_sort_direction == "desc" ? "chevron-down" : "chevron-up", class: "w-3 h-3") %> <% end %> <% end %> +
+
<%= t("reports.transactions_breakdown.table.percentage") %>
+
+ +
+ <% groups.each_with_index do |group, idx| %> + <%= render "reports/category_row", + item: group, + total: total, + color_class: color_class, + level: :category + %> + <% if idx < group.size - 1 %> + <%= render "shared/ruler", classes: "mx-3 lg:mx-4" %> + <% end %> + <%# Render subcategories if present %> + <% if group[:subcategories].present? && group[:subcategories].any? %> + <% group[:subcategories].each_with_index do |subcategory, idx| %> + <%= render "reports/category_row", + item: subcategory, + total: total, + color_class: color_class, + level: :subcategory + %> + <% end %> + <% if idx < group.size - 1 %> + <%= render "shared/ruler", classes: "mx-3 lg:mx-4" %> + <% end %> + <% end %> <% end %> -
-
<%= t("reports.transactions_breakdown.table.category") %> - <%= link_to reports_path(amount_sort_params), class: "inline-flex items-center gap-1 hover:text-primary" do %> - <%= t("reports.transactions_breakdown.table.amount") %> - <% if current_sort_by == "amount" %> - <%= icon(current_sort_direction == "desc" ? "chevron-down" : "chevron-up", class: "w-3 h-3") %> - <% end %> - <% end %> - <%= t("reports.transactions_breakdown.table.percentage") %>
-
- <% if group[:category_icon] %> -
- <%= icon(group[:category_icon], color: "current", size: "sm") %> -
- <% else %> - <%= render DS::FilledIcon.new( - variant: :text, - hex_color: group[:category_color], - text: group[:category_name], - size: "md", - rounded: true - ) %> - <% end %> - <%= group[:category_name] %> - (<%= t("reports.transactions_breakdown.table.entries", count: group[:count]) %>) -
-
- - <%= Money.new(group[:total], Current.family.currency).format %> - - - - <%= percentage %>% - -
-
- <% if subcategory[:category_icon] %> -
- <%= icon "corner-down-right" %> -
-
- <%= icon(subcategory[:category_icon], color: "current", size: "sm") %> -
- <% else %> - <%= render DS::FilledIcon.new( - variant: :text, - hex_color: subcategory[:category_color], - text: subcategory[:category_name], - size: "md", - rounded: true - ) %> - <% end %> - <%= subcategory[:category_name] %> - (<%= t("reports.transactions_breakdown.table.entries", count: subcategory[:count]) %>) -
-
- - <%= Money.new(subcategory[:total], Current.family.currency).format %> - - - - <%= sub_percentage %>% - -
+
+ diff --git a/app/views/reports/_category_row.html.erb b/app/views/reports/_category_row.html.erb new file mode 100644 index 000000000..e08ef92e9 --- /dev/null +++ b/app/views/reports/_category_row.html.erb @@ -0,0 +1,50 @@ +<% + percentage = total.zero? ? 0 : (item[:total].to_f / total * 100).round(1) + is_sub = level == :subcategory +%> + +
"> +
+ <% if is_sub %> +
+ <%= icon "corner-down-right" %> +
+ <% end %> + <% if item[:category_icon] %> +
+ <%= icon(item[:category_icon], color: "current", size: "sm") %> +
+ <% else %> + <%= render DS::FilledIcon.new( + variant: :text, + hex_color: item[:category_color], + text: item[:category_name], + size: "md", + rounded: true + ) %> + <% end %> + + <%= item[:category_name] %> + + + (<%= t("reports.transactions_breakdown.table.entries", count: item[:count]) %>) + +
+ +
+ + <%= Money.new(item[:total], Current.family.currency).format %> + +
+ +
+ + <%= percentage %>% + +
+