The personal finance app for everyone (by everyone)
Ruby
feat: Add category icons in report table
Alessio Cappa9fd29f14c191
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rbindex 763dd68f2a..8dfea80eed 100644--- a/app/controllers/reports_controller.rb+++ b/app/controllers/reports_controller.rb@@ -374,13 +374,13 @@ class ReportsController < ApplicationControllerfamily_currency = Current.family.currency# Helper to initialize a category group hash- init_category_group = ->(id, name, color, type) do- { category_id: id, category_name: name, category_color: color, type: type, total: 0, count: 0, subcategories: {} }+ init_category_group = ->(id, name, color, icon, type) do+ { category_id: id, category_name: name, category_color: color, category_icon: icon, type: type, total: 0, count: 0, subcategories: {} }end# Helper to initialize a subcategory hashinit_subcategory = ->(category) do- { category_id: category.id, category_name: category.name, category_color: category.color, total: 0, count: 0 }+ { category_id: category.id, category_name: category.name, category_color: category.color, category_icon: category.lucide_icon, total: 0, count: 0 }end# Helper to process an entry (transaction or trade)@@ -392,16 +392,16 @@ class ReportsController < ApplicationController# Uncategorized or Other Investments (for trades)if is_tradeparent_key = [ :other_investments, type ]- grouped_data[parent_key] ||= init_category_group.call(:other_investments, Category.other_investments_name, Category::OTHER_INVESTMENTS_COLOR, type)+ grouped_data[parent_key] ||= init_category_group.call(:other_investments, Category.other_investments.name, Category.other_investments.color, Category.other_investments.lucide_icon, type)elseparent_key = [ :uncategorized, type ]- grouped_data[parent_key] ||= init_category_group.call(:uncategorized, Category.uncategorized_name, Category::UNCATEGORIZED_COLOR, type)+ grouped_data[parent_key] ||= init_category_group.call(:uncategorized, Category.uncategorized.name, Category.uncategorized.color, Category.uncategorized.lucide_icon, type)endelsif category.parent_id.present?# This is a subcategory - group under parentparent = category.parentparent_key = [ parent.id, type ]- grouped_data[parent_key] ||= init_category_group.call(parent.id, parent.name, parent.color || Category::UNCATEGORIZED_COLOR, type)+ grouped_data[parent_key] ||= init_category_group.call(parent.id, parent.name, parent.color || Category::UNCATEGORIZED_COLOR, parent.lucide_icon, type)# Add to subcategorygrouped_data[parent_key][:subcategories][category.id] ||= init_subcategory.call(category)@@ -410,7 +410,7 @@ class ReportsController < ApplicationControllerelse# This is a root category (no parent)parent_key = [ category.id, type ]- grouped_data[parent_key] ||= init_category_group.call(category.id, category.name, category.color || Category::UNCATEGORIZED_COLOR, type)+ grouped_data[parent_key] ||= init_category_group.call(category.id, category.name, category.color || Category::UNCATEGORIZED_COLOR, category.lucide_icon, type)endgrouped_data[parent_key][:count] += 1diff --git a/app/views/reports/_breakdown_table.html.erb b/app/views/reports/_breakdown_table.html.erbindex 83d15350dc..7fb9df17fe 100644--- a/app/views/reports/_breakdown_table.html.erb+++ b/app/views/reports/_breakdown_table.html.erb@@ -37,7 +37,23 @@<tr class="border-b border-tertiary hover:bg-surface-inset"><td class="py-3 pr-4"><div class="flex items-center gap-2">- <span class="w-3 h-3 rounded-full flex-shrink-0" style="background-color: <%= group[:category_color] %>"></span>+ <% if group[:category_icon] %>+ <div class="h-7 w-7 flex-shrink-0 group-hover:scale-105 transition-all duration-300 rounded-full flex justify-center items-center"+ style="+ background-color: color-mix(in oklab, <%= group[:category_color] %> 10%, transparent);+ border-color: color-mix(in oklab, <%= group[:category_color] %> 10%, transparent);+ color: <%= group[:category_color] %>;">+ <%= icon(group[:category_icon], color: "current", size: "sm") %>+ </div>+ <% else %>+ <%= render DS::FilledIcon.new(+ variant: :text,+ hex_color: group[:category_color],+ text: group[:category_name],+ size: "md",+ rounded: true+ ) %>+ <% end %><span class="font-medium text-primary"><%= group[:category_name] %></span><span class="text-xs text-tertiary whitespace-nowrap">(<%= t("reports.transactions_breakdown.table.entries", count: group[:count]) %>)</span></div>@@ -58,9 +74,28 @@<% group[:subcategories].each do |subcategory| %><% sub_percentage = total.zero? ? 0 : (subcategory[:total].to_f / total * 100).round(1) %><tr class="border-b border-tertiary hover:bg-surface-inset bg-surface-inset/30">- <td class="py-2 pr-4 pl-6">+ <td class="p-2 pl-3"><div class="flex items-center gap-2">- <span class="w-2 h-2 rounded-full flex-shrink-0" style="background-color: <%= subcategory[:category_color] %>"></span>+ <% if subcategory[:category_icon] %>+ <div class="flex items-center justify-center text-subdued">+ <%= icon "corner-down-right" %>+ </div>+ <div class="h-7 w-7 flex-shrink-0 group-hover:scale-105 transition-all duration-300 rounded-full flex justify-center items-center"+ style="+ background-color: color-mix(in oklab, <%= subcategory[:category_color] %> 10%, transparent);+ border-color: color-mix(in oklab, <%= subcategory[:category_color] %> 10%, transparent);+ color: <%= subcategory[:category_color] %>;">+ <%= icon(subcategory[:category_icon], color: "current", size: "sm") %>+ </div>+ <% else %>+ <%= render DS::FilledIcon.new(+ variant: :text,+ hex_color: subcategory[:category_color],+ text: subcategory[:category_name],+ size: "md",+ rounded: true+ ) %>+ <% end %><span class="text-sm text-secondary"><%= subcategory[:category_name] %></span><span class="text-xs text-tertiary whitespace-nowrap">(<%= t("reports.transactions_breakdown.table.entries", count: subcategory[:count]) %>)</span></div>diff --git a/app/views/reports/index.html.erb b/app/views/reports/index.html.erbindex 31856fdb8a..6688994fc0 100644--- a/app/views/reports/index.html.erb+++ b/app/views/reports/index.html.erb@@ -18,7 +18,7 @@<%# Period Navigation Tabs %><div class="flex items-center justify-between gap-4">- <div class="flex items-center gap-2 overflow-x-auto pb-2">+ <div class="flex items-center gap-2 overflow-x-auto no-scrollbar"><%= render DS::Link.new(text: t("reports.index.periods.monthly"),variant: @period_type == :monthly ? "secondary" : "ghost",