The personal finance app for everyone (by everyone)
Ruby
Space a letter currency symbol from the amount in dashboard charts (#5714)
alexbazua39c7ddb926c
diff --git a/app/javascript/controllers/sankey_chart_controller.js b/app/javascript/controllers/sankey_chart_controller.jsindex b2be3d6255..6dd2be2925 100644--- a/app/javascript/controllers/sankey_chart_controller.js+++ b/app/javascript/controllers/sankey_chart_controller.js@@ -715,6 +715,9 @@ export default class extends Controller {minimumFractionDigits: 2,maximumFractionDigits: 2,});- return this.currencySymbolValue + formatted;+ // Symbols written with letters (Lei, kr, CHF, Bs.) need a space before the+ // number; "$" and "€" stay attached.+ const space = /[\p{L}.]$/u.test(this.currencySymbolValue) ? "\u00a0" : "";+ return this.currencySymbolValue + space + formatted;}}diff --git a/app/views/pages/dashboard/_outflows_donut.html.erb b/app/views/pages/dashboard/_outflows_donut.html.erbindex 07f993314f..e7fa50cbe5 100644--- a/app/views/pages/dashboard/_outflows_donut.html.erb+++ b/app/views/pages/dashboard/_outflows_donut.html.erb@@ -32,7 +32,7 @@<p class="text-sm text-secondary"><%= category[:name] %></p><p data-donut-chart-target="amount" class="text-3xl font-medium text-primary privacy-sensitive whitespace-nowrap">- <%= outflows_data[:currency_symbol] %><%= number_with_delimiter(category[:amount], delimiter: ",") %>+ <%= outflows_data[:currency_symbol] %><%= "\u00A0" if outflows_data[:currency_symbol].match?(/[\p{L}.]\z/) %><%= number_with_delimiter(category[:amount], delimiter: ",") %></p><p class="text-sm text-secondary privacy-sensitive"><%= category[:percentage] %>%</p>diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rbindex d018c656fd..f209939741 100644--- a/test/controllers/pages_controller_test.rb+++ b/test/controllers/pages_controller_test.rb@@ -472,6 +472,18 @@ class PagesControllerTest < ActionDispatch::IntegrationTestassert sankey_data.fetch("nodes").any? { |node| node.fetch("id").start_with?("expense_") }end+ test "dashboard donut separates a letter currency symbol from the amount" do+ @family.update!(currency: "RON")+ account = @family.accounts.create!(name: "RON account", balance: 0, currency: "RON", accountable: Depository.new)+ category = @family.categories.create!(name: "Shopping", color: "#FF5733")+ create_transaction(account: account, name: "Shopping trip", amount: 1234.56, currency: "RON", category: category)++ get root_path++ assert_response :ok+ assert_select "#segment_#{category.id} [data-donut-chart-target='amount']", text: "Lei\u00A01,234.56"+ end+test "dashboard sankey shows investment contributions as invested when they are not spending" do@family.update!(investment_contributions_as_spending: false)category = @family.categories.create!(name: "Shopping", color: "#FF5733")