Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Make a blank goal earmark read as a choice, and editable in privacy mode (#3857)

Guillem Arias Faustee16971b23ebc
diff --git a/app/javascript/controllers/goal_earmark_controller.js b/app/javascript/controllers/goal_earmark_controller.js
index 2295a27a87..5267221443 100644
--- a/app/javascript/controllers/goal_earmark_controller.js
+++ b/app/javascript/controllers/goal_earmark_controller.js
@@ -55,6 +55,10 @@ export default class extends Controller {
const claimedWhole = row.dataset.wholeAccountClaimed === "true"
const raw = input.value.trim()
+ // A number input reports text it cannot parse as "", which would read as
+ // a blank amount and claim the whole balance for what the user typed.
+ if (input.validity?.badInput) return this.#hide(warning)
+
// "whatever is left after the other earmarks" describes nothing when there
// are none — and this is where a first-time user meets the word, pointed
// at something absent. With the account to itself, say that instead.
diff --git a/app/views/goals/_form.html.erb b/app/views/goals/_form.html.erb
index e139b10fba..ddf7ad77e7 100644
--- a/app/views/goals/_form.html.erb
+++ b/app/views/goals/_form.html.erb
@@ -161,14 +161,19 @@
<p class="text-xs text-secondary tabular-nums privacy-sensitive"><%= t("goals.form.subtypes.#{row_subtype}", default: row_subtype.titleize) %> · <%= Money.new(account.balance, account.currency).format %></p>
</div>
</label>
- <%= text_field_tag "goal[allocations][#{account.id}]",
- linked_ga&.allocated_amount&.to_s("F"),
- placeholder: t("goals.form.fields.whole_balance"),
- inputmode: "decimal",
- autocomplete: "off",
- aria: { label: t("goals.form.fields.earmark_for", account: account.name) },
- data: { goal_earmark_target: "allocationInput", action: "input->goal-earmark#refresh" },
- class: "shrink-0 w-36 rounded-md border border-primary bg-container px-2.5 py-1.5 text-sm text-right tabular-nums text-primary placeholder:text-subdued focus-ring privacy-sensitive" %>
+ <%= f.fields_for :allocations do |af| %>
+ <%= af.money_field account.id,
+ label: t("goals.form.fields.earmark_for", account: account.name),
+ label_class: "sr-only",
+ placeholder: t("goals.form.fields.whole_balance"),
+ value: linked_ga&.allocated_amount,
+ currency_value_override: account.currency,
+ hide_currency: true,
+ min: 0,
+ container_class: "shrink-0 w-48",
+ input_class: "tabular-nums privacy-sensitive privacy-sensitive-interactive",
+ amount_data: { goal_earmark_target: "allocationInput", action: "input->goal-earmark#refresh" } %>
+ <% end %>
</div>
<%# Never text-destructive: none of this is an error. A goal
in progress legitimately claims more than its account
diff --git a/app/views/shared/_money_field.html.erb b/app/views/shared/_money_field.html.erb
index 399d29cfec..9e875962f6 100644
--- a/app/views/shared/_money_field.html.erb
+++ b/app/views/shared/_money_field.html.erb
@@ -13,7 +13,7 @@
<% if options[:step].present? %> data-money-field-step-value="<%= options[:step] %>"<% end %>>
<% if options[:label_tooltip] %>
<div class="form-field__header">
- <%= form.label amount_method, class: "form-field__label" do %>
+ <%= form.label amount_method, class: class_names("form-field__label", options[:label_class]) do %>
<%= options[:label] || t(".label") %>
<% if options[:required] %>
<span class="text-red-500 ml-0.5">*</span>
@@ -32,7 +32,7 @@
<div class="form-field__body">
<% unless options[:label_tooltip] %>
- <%= form.label amount_method, class: "form-field__label" do %>
+ <%= form.label amount_method, class: class_names("form-field__label", options[:label_class]) do %>
<%= options[:label] || t(".label") %>
<% if options[:required] %>
<span class="text-red-500 ml-0.5">*</span>
@@ -49,7 +49,7 @@
<%= form.number_field amount_method,
class: class_names("form-field__input", options[:input_class]),
inline: true,
- placeholder: "100",
+ placeholder: options[:placeholder] || "100",
value: if options[:value]
sprintf("%.#{options[:precision].presence || currency.default_precision}f", options[:value])
elsif form.object && form.object.respond_to?(amount_method)
diff --git a/config/locales/views/goals/ca.yml b/config/locales/views/goals/ca.yml
index ac377e9d61..8a7b1ff4a1 100644
--- a/config/locales/views/goals/ca.yml
+++ b/config/locales/views/goals/ca.yml
@@ -333,7 +333,7 @@ ca:
notes_placeholder: Un recordatori per al teu jo del futur…
funding_accounts: Comptes de finançament
funding_accounts_hint: El saldo d'aquest objectiu és el saldo (o la part reservada) d'aquests comptes.
- whole_balance: Tot el saldo
+ whole_balance: "Buit: tot el saldo"
earmark_for: Import reservat de %{account}
earmark_hint: Deixa un import en blanc per destinar-hi tot el saldo d'aquell compte.
subtypes:
diff --git a/config/locales/views/goals/de.yml b/config/locales/views/goals/de.yml
index 261af0cfb4..ae33d11c20 100644
--- a/config/locales/views/goals/de.yml
+++ b/config/locales/views/goals/de.yml
@@ -47,7 +47,7 @@ de:
notes_placeholder: Eine Erinnerung an dein späteres Ich …
target_amount: Zielbetrag
target_date: Zieldatum
- whole_balance: Ganzer Saldo
+ whole_balance: "Leer: ganzer Saldo"
save: Änderungen speichern
subtypes:
cd: Festgeld
diff --git a/config/locales/views/goals/en.yml b/config/locales/views/goals/en.yml
index cad0a8f0ea..3b917e6ecc 100644
--- a/config/locales/views/goals/en.yml
+++ b/config/locales/views/goals/en.yml
@@ -333,7 +333,7 @@ en:
notes_placeholder: A reminder for future you…
funding_accounts: Funding accounts
funding_accounts_hint: This goal's balance is the balance (or earmarked portion) of these accounts.
- whole_balance: Whole balance
+ whole_balance: "Blank: whole balance"
earmark_for: Earmark amount for %{account}
earmark_hint: Leave an amount blank to dedicate that account's whole balance.
subtypes:
diff --git a/config/locales/views/goals/es.yml b/config/locales/views/goals/es.yml
index efa28ba353..64ea1881f8 100644
--- a/config/locales/views/goals/es.yml
+++ b/config/locales/views/goals/es.yml
@@ -268,7 +268,7 @@ es:
notes_placeholder: Un recordatorio para tu yo del futuro…
funding_accounts: Cuentas de financiación
funding_accounts_hint: El saldo de este objetivo es el saldo (o la parte reservada) de estas cuentas.
- whole_balance: Saldo completo
+ whole_balance: "Vacío: todo el saldo"
earmark_for: Importe reservado para %{account}
earmark_hint: Deja un importe en blanco para dedicar todo el saldo de esa cuenta.
subtypes:
diff --git a/config/locales/views/goals/fr.yml b/config/locales/views/goals/fr.yml
index 376cdc10eb..90aac7f037 100644
--- a/config/locales/views/goals/fr.yml
+++ b/config/locales/views/goals/fr.yml
@@ -68,7 +68,7 @@ fr:
target_balance_pending: "Calculé à l'enregistrement"
target_balance_hint: "D'après vos dépenses mensuelles médianes sur le nombre de mois ci-dessus. Recalculé chaque mois."
target_date: Date cible
- whole_balance: Solde total
+ whole_balance: "Vide : tout le solde"
save: Enregistrer les modifications
subtypes:
cd: Compte à terme
diff --git a/config/locales/views/goals/it.yml b/config/locales/views/goals/it.yml
index 09beb57b86..021c3ebcd2 100644
--- a/config/locales/views/goals/it.yml
+++ b/config/locales/views/goals/it.yml
@@ -267,7 +267,7 @@ it:
notes_placeholder: Un promemoria per te in futuro…
funding_accounts: Conti di finanziamento
funding_accounts_hint: Il saldo di questo obiettivo è il saldo di questi conti.
- whole_balance: Saldo intero
+ whole_balance: "Vuoto: tutto il saldo"
earmark_for: Accantona un importo per %{account}
earmark_hint: Lascia vuoto un importo per dedicare l'intero saldo di quel conto.
subtypes:
diff --git a/config/locales/views/goals/pl.yml b/config/locales/views/goals/pl.yml
index 8a7e9fa41c..477d677164 100644
--- a/config/locales/views/goals/pl.yml
+++ b/config/locales/views/goals/pl.yml
@@ -87,7 +87,7 @@ pl:
target_months: Miesiące wydatków
target_months_hint: Przeliczane 1. dnia każdego miesiąca na podstawie mediany
Twoich miesięcznych wydatków.
- whole_balance: Całe saldo
+ whole_balance: "Puste: całe saldo"
kinds:
maintained:
hint: Saldo do utrzymania, jak fundusz awaryjny. Nigdy nie jest zamykane.
diff --git a/config/locales/views/goals/pt-PT.yml b/config/locales/views/goals/pt-PT.yml
index afccc1f0fc..d69120a14b 100644
--- a/config/locales/views/goals/pt-PT.yml
+++ b/config/locales/views/goals/pt-PT.yml
@@ -333,7 +333,7 @@ pt-PT:
notes_placeholder: Uma recordação para o seu eu do futuro…
funding_accounts: Contas de financiamento
funding_accounts_hint: O saldo deste objetivo é o saldo (ou a parte reservada) destas contas.
- whole_balance: Saldo total
+ whole_balance: "Vazio: saldo total"
earmark_for: Reservar o montante de %{account}
earmark_hint: Deixe um montante em branco para dedicar o saldo total dessa conta.
subtypes:
diff --git a/config/locales/views/goals/ru.yml b/config/locales/views/goals/ru.yml
index 7b54718846..55fd70efd0 100644
--- a/config/locales/views/goals/ru.yml
+++ b/config/locales/views/goals/ru.yml
@@ -47,7 +47,7 @@ ru:
notes_placeholder: Напоминание себе…
target_amount: Целевая сумма
target_date: Дата достижения
- whole_balance: Весь баланс
+ whole_balance: "Пусто: весь баланс"
target_mode: Как задаётся целевой баланс
target_months: Месяцев расходов
target_months_hint: Пересчитывается 1-го числа каждого месяца по медиане ваших ежемесячных расходов.
diff --git a/config/locales/views/goals/tr.yml b/config/locales/views/goals/tr.yml
index 8f376f2ca3..6f768734ad 100644
--- a/config/locales/views/goals/tr.yml
+++ b/config/locales/views/goals/tr.yml
@@ -50,7 +50,7 @@ tr:
notes_placeholder: Gelecekteki siz için bir hatırlatma…
target_amount: Hedef tutar
target_date: Hedef tarihi
- whole_balance: Tüm bakiye
+ whole_balance: "Boş: tüm bakiye"
target_mode: Hedef bakiye nasıl belirlenir
target_months: Kaç aylık gider
target_months_hint: Her ayın 1'inde medyan aylık harcamanıza göre yeniden hesaplanır.
diff --git a/config/locales/views/goals/uk.yml b/config/locales/views/goals/uk.yml
index 9f50f76495..760f1a5048 100644
--- a/config/locales/views/goals/uk.yml
+++ b/config/locales/views/goals/uk.yml
@@ -353,7 +353,7 @@ uk:
notes_placeholder: Нагадування для себе в майбутньому…
funding_accounts: Рахунки фінансування
funding_accounts_hint: Баланс цієї цілі — це баланс (або відкладена частина) цих рахунків.
- whole_balance: Весь баланс
+ whole_balance: "Порожньо: весь баланс"
earmark_for: Сума, яку відкласти з %{account}
earmark_hint: Залиште суму порожньою, щоб використати весь баланс рахунку.
subtypes:
diff --git a/config/locales/views/goals/zh-CN.yml b/config/locales/views/goals/zh-CN.yml
index fedb679258..e86bd63d8b 100644
--- a/config/locales/views/goals/zh-CN.yml
+++ b/config/locales/views/goals/zh-CN.yml
@@ -267,7 +267,7 @@ zh-CN:
notes_placeholder: 给未来自己的提醒…
funding_accounts: 资金账户
funding_accounts_hint: 此目标余额等于这些账户的余额(或预留的部分)。
- whole_balance: 全部余额
+ whole_balance: "留空即全部余额"
earmark_for: 为「%{account}」预留的金额
earmark_hint: 留空则使用该账户的全部余额。
subtypes:
diff --git a/config/locales/views/goals/zh-TW.yml b/config/locales/views/goals/zh-TW.yml
index ba2d0c8a6f..e510fcb107 100644
--- a/config/locales/views/goals/zh-TW.yml
+++ b/config/locales/views/goals/zh-TW.yml
@@ -267,7 +267,7 @@ zh-TW:
notes_placeholder: 留給未來的自己的提醒...
funding_accounts: 資金帳戶
funding_accounts_hint: 這個目標的餘額,就是這些帳戶的餘額(或其中指定的部分)。
- whole_balance: 全部餘額
+ whole_balance: "留空即全部餘額"
earmark_for: 為 %{account} 指定金額
earmark_hint: 把金額留白,就會把該帳戶的全部餘額都投入這個目標。
subtypes:
diff --git a/test/controllers/goals_controller_test.rb b/test/controllers/goals_controller_test.rb
index 6b9d2cb587..a624644092 100644
--- a/test/controllers/goals_controller_test.rb
+++ b/test/controllers/goals_controller_test.rb
@@ -992,6 +992,40 @@ class GoalsControllerTest < ActionDispatch::IntegrationTest
"the hint shown with no other claims should not mention earmarks")
end
+ # Privacy mode sets `pointer-events: none` on bare .privacy-sensitive, so
+ # the per-account amount has to opt back in or it cannot be typed into.
+ test "each account's earmark is a money field that stays editable in privacy mode" do
+ account = unclaimed_account("Earmark Pot")
+
+ get new_goal_url
+
+ assert_response :success
+ assert_select "label[for=goal_allocations_#{account.id}]", text: /#{I18n.t("goals.form.fields.earmark_for", account: "Earmark Pot")}/
+ assert_select "input#goal_allocations_#{account.id}[name='goal[allocations][#{account.id}]']", count: 1 do |inputs|
+ input = inputs.first
+ assert_includes input["class"].split, "privacy-sensitive"
+ assert_includes input["class"].split, "privacy-sensitive-interactive"
+ assert_equal I18n.t("goals.form.fields.whole_balance"), input["placeholder"]
+ assert_equal "0", input["min"]
+ assert_nil input["value"]
+ assert_equal "allocationInput", input["data-goal-earmark-target"]
+ assert_equal "amount", input["data-money-field-target"]
+ assert_includes input["data-action"], "input->goal-earmark#refresh"
+ end
+ end
+
+ test "a fixed earmark is filled back into its account's field" do
+ account = unclaimed_account("Filled Pot")
+ goal = @user.family.goals.create!(name: "Filled", target_amount: 5_000, currency: "USD") do |g|
+ g.goal_accounts.build(account: account, allocated_amount: 250)
+ end
+
+ get edit_goal_url(goal)
+
+ assert_response :success
+ assert_select "input#goal_allocations_#{account.id}[value='250.00']"
+ end
+
private
# A private account of another member, linked to the goal under test.