The personal finance app for everyone (by everyone)
Ruby
Name the account on an account_ids filter chip (#4569)
Dov Benyomin Sohacheskicd906af9888f
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rbindex 60a9a0439f..a3e754b4df 100644--- a/app/helpers/transactions_helper.rb+++ b/app/helpers/transactions_helper.rb@@ -70,6 +70,13 @@ module TransactionsHelper@annotatable_account_ids.include?(account.id)end+ # The dashboard drill-down filters by account id, so its filter chips name+ # the account rather than print the id. Memoized per request like the above.+ def transaction_filter_account_name(account_id)+ @transaction_filter_account_names ||= Current.user.accessible_accounts.pluck(:id, :name).to_h+ @transaction_filter_account_names.fetch(account_id, account_id)+ end+# ---- Transaction extra details helpers ----# Returns a structured hash describing extra details for a transaction.# Input can be a Transaction or an Entry (responds_to :transaction).diff --git a/app/views/transactions/searches/filters/_badge.html.erb b/app/views/transactions/searches/filters/_badge.html.erbindex 53cfe595f8..c8c60ab2e2 100644--- a/app/views/transactions/searches/filters/_badge.html.erb+++ b/app/views/transactions/searches/filters/_badge.html.erb@@ -16,10 +16,11 @@<%= icon "text" %><p><%= "\"#{param_value}\"".truncate(20) %></p></div>- <% elsif param_key == "accounts" %>+ <% elsif param_key == "accounts" || param_key == "account_ids" %>+ <% account_name = param_key == "account_ids" ? transaction_filter_account_name(param_value) : param_value %><div class="flex items-center gap-2">- <div class="w-5 h-5 bg-blue-600/10 text-xs flex items-center justify-center rounded-full"><%= param_value[0].upcase %></div>- <p><%= param_value %></p>+ <div class="w-5 h-5 bg-info/10 text-xs flex items-center justify-center rounded-full"><%= account_name.first.upcase %></div>+ <p><%= account_name %></p></div><% elsif param_key == "amount" %><div class="flex items-center gap-2">diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rbindex 4a40661268..d39797fa14 100644--- a/test/controllers/transactions_controller_test.rb+++ b/test/controllers/transactions_controller_test.rb@@ -2147,6 +2147,22 @@ endassert_select "#entry_#{@entry.id}", count: 0end+ test "index names the account on an account_ids filter chip" do+ account = @entry.account++ get transactions_url(q: { account_ids: [ account.id ] })++ assert_response :success+ assert_select "#transaction-search-filters li p", text: account.name, count: 1+ assert_select "#transaction-search-filters li p", text: account.id, count: 0+ end++ test "index renders a blank account filter value without failing" do+ get transactions_url(q: { account_ids: [ "" ], accounts: [ "" ] })++ assert_response :success+ end+test "index offers the attachment filter in the filter menu" doget transactions_url