Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add "logo" variant in account dropdown on transfer form (#1241)

Alessio Cappaddf1c732d32c
diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb
index e1fdac825e..239f7d9f99 100644
--- a/app/controllers/transfers_controller.rb
+++ b/app/controllers/transfers_controller.rb
@@ -6,6 +6,13 @@ class TransfersController < ApplicationController
def new
@transfer = Transfer.new
@from_account_id = params[:from_account_id]
+
+ @accounts = Current.family.accounts
+ .alphabetically
+ .includes(
+ :account_providers,
+ logo_attachment: :blob
+ )
end
def show
diff --git a/app/views/transfers/_form.html.erb b/app/views/transfers/_form.html.erb
index aff9d0675a..8c3bc5edba 100644
--- a/app/views/transfers/_form.html.erb
+++ b/app/views/transfers/_form.html.erb
@@ -14,8 +14,9 @@
<% account_ids << params[:to_account_id] if params[:to_account_id].present? %>
<% account_ids << transfer.from_account_id if transfer.respond_to?(:from_account_id) && transfer.from_account_id.present? %>
<% account_ids << transfer.to_account_id if transfer.respond_to?(:to_account_id) && transfer.to_account_id.present? %>
+ <% selected_accounts = @accounts.select { |a| account_ids.include?(a.id) } %>
- <% if account_ids.any? && Current.family.accounts.where(id: account_ids).any? { |a| a.investment? || a.crypto? } %>
+ <% if selected_accounts.any? { |a| a.investment? || a.crypto? } %>
<% show_type_tabs = false %>
<% end %>
@@ -26,8 +27,8 @@
<% end %>
<section class="space-y-2">
- <%= f.collection_select :from_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".from"), selected: @from_account_id }, required: true %>
- <%= f.collection_select :to_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".to") }, required: true %>
+ <%= f.collection_select :from_account_id, @accounts, :id, :name, { prompt: t(".select_account"), label: t(".from"), selected: @from_account_id, variant: :logo }, required: true %>
+ <%= f.collection_select :to_account_id, @accounts, :id, :name, { prompt: t(".select_account"), label: t(".to"), variant: :logo }, required: true %>
<%= f.number_field :amount, label: t(".amount"), required: true, min: 0, placeholder: "100", step: 0.00000001 %>
<%= f.date_field :date, value: transfer.inflow_transaction&.entry&.date || Date.current, label: t(".date"), required: true, max: Date.current %>
</section>
diff --git a/test/system/transfers_test.rb b/test/system/transfers_test.rb
index db6717ea44..6fbd81928b 100644
--- a/test/system/transfers_test.rb
+++ b/test/system/transfers_test.rb
@@ -7,8 +7,6 @@ class TransfersTest < ApplicationSystemTestCase
end
test "can create a transfer" do
- checking_name = accounts(:depository).name
- savings_name = accounts(:credit_card).name
transfer_date = Date.current
click_on "New transaction"
@@ -16,8 +14,8 @@ class TransfersTest < ApplicationSystemTestCase
assert_text "New transfer"
# Select accounts using DS::Select
- select_ds("From", checking_name)
- select_ds("To", savings_name)
+ select_ds("From", accounts(:depository))
+ select_ds("To", accounts(:credit_card))
fill_in "transfer[amount]", with: 500
fill_in "Date", with: transfer_date
@@ -31,7 +29,7 @@ class TransfersTest < ApplicationSystemTestCase
private
- def select_ds(label_text, option_text)
+ def select_ds(label_text, record)
field_label = find("label", exact_text: label_text)
container = field_label.ancestor("div.relative")
@@ -40,13 +38,13 @@ class TransfersTest < ApplicationSystemTestCase
# If searchable, type in the search input
if container.has_selector?("input[type='search']", visible: true)
- container.find("input[type='search']", visible: true).set(option_text)
+ container.find("input[type='search']", visible: true).set(record.name)
end
# Wait for the listbox to appear inside the relative container
listbox = container.find("[role='listbox']", visible: true)
# Click the option inside the listbox
- listbox.find("[role='option']", exact_text: option_text, visible: true).click
+ listbox.find("[role='option'][data-value='#{record.id}']", visible: true).click
end
end