Highlight current month in trends insights table (#448)

* Highlight current month in trends insights table

Refactored the logic to apply special styling and label to the row representing the current month, using a date comparison instead of relying on the last index. This ensures the current month is always highlighted, regardless of its position in the data.

* Highlight current month in trends insights

Added an is_current_month flag to trends data in the controller and updated the view to use this flag for highlighting the current month. This improves clarity and avoids redundant date comparisons in the view.
This commit is contained in:
Mark Hendriksen
2025-12-13 09:45:36 +01:00
committed by GitHub
parent 101b9dac95
commit eb762eff12
2 changed files with 4 additions and 3 deletions

View File

@@ -287,6 +287,7 @@ class ReportsController < ApplicationController
trends << {
month: month_start.strftime("%b %Y"),
is_current_month: (month_start.month == Date.current.month && month_start.year == Date.current.year),
income: income,
expenses: expenses,
net: income - expenses

View File

@@ -18,11 +18,11 @@
</tr>
</thead>
<tbody>
<% trends_data.each_with_index do |trend, index| %>
<tr class="border-b border-tertiary/50 <%= index == trends_data.length - 1 ? "font-medium" : "" %>">
<% trends_data.each do |trend| %>
<tr class="border-b border-tertiary/50 <%= trend[:is_current_month] ? "font-medium" : "" %>">
<td class="py-3 pr-4 text-primary">
<%= trend[:month] %>
<% if index == trends_data.length - 1 %>
<% if trend[:is_current_month] %>
<span class="ml-2 text-xs text-tertiary">(<%= t("reports.trends.current") %>)</span>
<% end %>
</td>