Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

feat: add preference to disable modal close on outside click (#2226)

Neko1f036fc526fa
diff --git a/.gitignore b/.gitignore
index 19cc81a3ae..dd7707feb5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,6 +69,9 @@ coverage
.cursor/rules/structure.mdc
.cursor/rules/agent.mdc
+# Ignore Redis dump file
+dump.rdb
+
# Ignore node related files
node_modules
diff --git a/app/components/DS/dialog.rb b/app/components/DS/dialog.rb
index d1f17e3104..4a917b91ee 100644
--- a/app/components/DS/dialog.rb
+++ b/app/components/DS/dialog.rb
@@ -48,11 +48,15 @@ class DS::Dialog < DesignSystemComponent
}.freeze
VALID_HEADING_LEVELS = (1..6).freeze
- def initialize(variant: "modal", auto_open: true, reload_on_close: false, width: "md", frame: nil, disable_frame: false, content_class: nil, disable_click_outside: false, responsive: false, scrollable: true, heading_level: 2, **opts)
+ class_attribute :defaults_provider, default: nil
+
+ def initialize(variant: "modal", auto_open: true, reload_on_close: false, width: "md", frame: nil, disable_frame: false, content_class: nil, disable_click_outside: nil, responsive: false, scrollable: true, heading_level: 2, **opts)
unless heading_level.is_a?(Integer) && VALID_HEADING_LEVELS.cover?(heading_level)
raise ArgumentError, "heading_level must be an Integer between 1 and 6, got: #{heading_level.inspect}"
end
+ defaults = self.class.defaults_provider&.call || {}
+
@variant = variant.to_sym
@auto_open = auto_open
@reload_on_close = reload_on_close
@@ -60,7 +64,7 @@ class DS::Dialog < DesignSystemComponent
@frame = frame
@disable_frame = disable_frame
@content_class = content_class
- @disable_click_outside = disable_click_outside
+ @disable_click_outside = disable_click_outside.nil? ? defaults.fetch(:disable_click_outside, false) : disable_click_outside
@responsive = responsive
@scrollable = scrollable
@heading_level = heading_level
diff --git a/app/controllers/settings/appearances_controller.rb b/app/controllers/settings/appearances_controller.rb
index 51ae267392..c9a0ccbc92 100644
--- a/app/controllers/settings/appearances_controller.rb
+++ b/app/controllers/settings/appearances_controller.rb
@@ -12,6 +12,7 @@ class Settings::AppearancesController < ApplicationController
updated_prefs = (@user.preferences || {}).deep_dup
updated_prefs["show_split_grouped"] = params.dig(:user, :show_split_grouped) == "1" if params.dig(:user, :show_split_grouped)
updated_prefs["dashboard_two_column"] = params.dig(:user, :dashboard_two_column) == "1" if params.dig(:user, :dashboard_two_column)
+ updated_prefs["disable_modal_click_outside"] = params.dig(:user, :disable_modal_click_outside) == "1" if params.dig(:user, :disable_modal_click_outside)
@user.update!(preferences: updated_prefs)
end
redirect_to settings_appearance_path
diff --git a/app/models/user.rb b/app/models/user.rb
index 1955a64fbd..f1c6fbb9ac 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -387,6 +387,10 @@ class User < ApplicationRecord
preferences&.dig("dashboard_two_column") == true
end
+ def disable_modal_click_outside?
+ preferences&.dig("disable_modal_click_outside") == true
+ end
+
def preview_features_enabled?
preferences&.dig("preview_features_enabled") == true
end
diff --git a/app/views/settings/appearances/show.html.erb b/app/views/settings/appearances/show.html.erb
index 88646f8a11..230c5e92ac 100644
--- a/app/views/settings/appearances/show.html.erb
+++ b/app/views/settings/appearances/show.html.erb
@@ -49,6 +49,27 @@
</div>
<% end %>
+<%= settings_section title: t(".modals_title"), subtitle: t(".modals_subtitle") do %>
+ <div>
+ <%= form_with url: settings_appearance_path, method: :patch,
+ class: "p-3",
+ data: { controller: "auto-submit-form" } do |f| %>
+ <div class="flex cursor-pointer items-center gap-4 justify-between">
+ <div class="text-sm space-y-1">
+ <h4 class="text-primary"><%= t(".disable_modal_click_outside_title") %></h4>
+ <p class="text-secondary"><%= t(".disable_modal_click_outside_description") %></p>
+ </div>
+ <%= render DS::Toggle.new(
+ id: "user_disable_modal_click_outside",
+ name: "user[disable_modal_click_outside]",
+ checked: @user.disable_modal_click_outside?,
+ data: { auto_submit_form_target: "auto" }
+ ) %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
<%= settings_section title: t(".transactions_title"), subtitle: t(".transactions_subtitle") do %>
<div>
<%= form_with url: settings_appearance_path, method: :patch,
diff --git a/config/initializers/dialog_defaults.rb b/config/initializers/dialog_defaults.rb
new file mode 100644
index 0000000000..39f9777778
--- /dev/null
+++ b/config/initializers/dialog_defaults.rb
@@ -0,0 +1,5 @@
+Rails.application.config.after_initialize do
+ DS::Dialog.defaults_provider = -> {
+ { disable_click_outside: Current.user&.disable_modal_click_outside? || false }
+ }
+end
diff --git a/config/locales/views/settings/ca.yml b/config/locales/views/settings/ca.yml
index 9df9876737..a7db87d3ed 100644
--- a/config/locales/views/settings/ca.yml
+++ b/config/locales/views/settings/ca.yml
@@ -35,6 +35,10 @@ ca:
theme_light: Clar
theme_subtitle: Tria el tema preferit per a l'aplicació
theme_system: Sistema
+ modals_title: Modals
+ modals_subtitle: Personalitza el comportament dels modals
+ disable_modal_click_outside_title: Mantén els modals oberts en fer clic fora
+ disable_modal_click_outside_description: Evita que els modals es tanquin en fer clic fora. Útil per evitar perdre canvis no desats accidentalment.
theme_title: Tema
transactions_subtitle: Personalitza com es mostren les transaccions
transactions_title: Transaccions
diff --git a/config/locales/views/settings/de.yml b/config/locales/views/settings/de.yml
index eb17807f2b..f0fbe77084 100644
--- a/config/locales/views/settings/de.yml
+++ b/config/locales/views/settings/de.yml
@@ -46,6 +46,12 @@ de:
month_start_day: Budgetmonat beginnt am
month_start_day_hint: Lege fest, wann dein Budgetmonat beginnt (z. B. Gehaltstag)
month_start_day_warning: Deine Budgets und MTD-Berechnungen verwenden diesen benutzerdefinierten Starttag anstelle des 1. jedes Monats.
+ appearances:
+ show:
+ modals_title: Modale Fenster
+ modals_subtitle: Verhalten der modalen Fenster anpassen
+ disable_modal_click_outside_title: Modale Fenster bei Klick außerhalb geöffnet lassen
+ disable_modal_click_outside_description: Verhindert das Schließen modaler Fenster beim Klicken außerhalb. Nützlich, um ungespeicherte Änderungen nicht versehentlich zu verlieren.
profiles:
destroy:
cannot_remove_self: Du kannst dich nicht selbst aus dem Konto entfernen.
diff --git a/config/locales/views/settings/en.yml b/config/locales/views/settings/en.yml
index ee825a7d04..c5f1706d5a 100644
--- a/config/locales/views/settings/en.yml
+++ b/config/locales/views/settings/en.yml
@@ -107,6 +107,10 @@ en:
theme_dark: Dark
theme_light: Light
theme_system: System
+ modals_title: Modals
+ modals_subtitle: Customize modal behavior
+ disable_modal_click_outside_title: Keep modals open on outside click
+ disable_modal_click_outside_description: Prevent modals from closing when clicking outside. Useful to avoid accidentally losing unsaved changes.
transactions_title: Transactions
transactions_subtitle: Customize how transactions are displayed
dashboard_title: Dashboard
diff --git a/config/locales/views/settings/es.yml b/config/locales/views/settings/es.yml
index 1ff5af6508..d0db5bc13a 100644
--- a/config/locales/views/settings/es.yml
+++ b/config/locales/views/settings/es.yml
@@ -50,6 +50,12 @@ es:
preview:
title: Habilitar funciones experimentales
description: Activa las funciones en desarrollo etiquetadas como experimentales o canary.
+ appearances:
+ show:
+ modals_title: Modales
+ modals_subtitle: Personalizar el comportamiento de los modales
+ disable_modal_click_outside_title: Mantener modales abiertos al hacer clic fuera
+ disable_modal_click_outside_description: Evita que los modales se cierren al hacer clic fuera. Útil para evitar perder cambios no guardados accidentalmente.
profiles:
destroy:
cannot_remove_self: No puedes eliminarte a ti mismo de la cuenta.
diff --git a/config/locales/views/settings/fr.yml b/config/locales/views/settings/fr.yml
index 6faca441d8..5fdbf6f40c 100644
--- a/config/locales/views/settings/fr.yml
+++ b/config/locales/views/settings/fr.yml
@@ -34,6 +34,10 @@ fr:
theme_dark: Sombre
theme_light: Clair
theme_system: Système
+ modals_title: Fenêtres modales
+ modals_subtitle: Personnaliser le comportement des fenêtres modales
+ disable_modal_click_outside_title: Garder les fenêtres modales ouvertes au clic extérieur
+ disable_modal_click_outside_description: Empêche les fenêtres modales de se fermer en cliquant à l'extérieur. Utile pour éviter de perdre accidentellement des modifications non sauvegardées.
transactions_title: Transactions
transactions_subtitle: Personnalisez l'affichage des transactions
dashboard_title: Tableau de bord
diff --git a/config/locales/views/settings/hu.yml b/config/locales/views/settings/hu.yml
index b43b6cc976..583ef42a83 100644
--- a/config/locales/views/settings/hu.yml
+++ b/config/locales/views/settings/hu.yml
@@ -71,6 +71,10 @@ hu:
theme_dark: Sötét
theme_light: Világos
theme_system: Rendszer
+ modals_title: Modális ablakok
+ modals_subtitle: Modális ablakok viselkedésének testreszabása
+ disable_modal_click_outside_title: Modális ablakok nyitva tartása külső kattintáskor
+ disable_modal_click_outside_description: Megakadályozza, hogy a modális ablakok bezáródjanak külső kattintáskor. Hasznos a nem mentett változtatások véletlen elvesztésének elkerülésére.
transactions_title: Tranzakciók
transactions_subtitle: Szabd testre a tranzakciók megjelenítését
dashboard_title: Irányítópult
diff --git a/config/locales/views/settings/nb.yml b/config/locales/views/settings/nb.yml
index ed759aae69..6e7e5c9723 100644
--- a/config/locales/views/settings/nb.yml
+++ b/config/locales/views/settings/nb.yml
@@ -27,6 +27,12 @@ nb:
theme_system: System
theme_title: Tema
timezone: Tidssone
+ appearances:
+ show:
+ modals_title: Modaler
+ modals_subtitle: Tilpass oppførselen til modaler
+ disable_modal_click_outside_title: Hold modaler åpne ved klikk utenfor
+ disable_modal_click_outside_description: Forhindrer at modaler lukkes ved klikk utenfor. Nyttig for å unngå å miste ulagrede endringer ved et uhell.
profiles:
destroy:
cannot_remove_self: Du kan ikke fjerne deg selv fra din egen konto.
diff --git a/config/locales/views/settings/nl.yml b/config/locales/views/settings/nl.yml
index a74136bbe9..40361ff69c 100644
--- a/config/locales/views/settings/nl.yml
+++ b/config/locales/views/settings/nl.yml
@@ -43,6 +43,12 @@ nl:
theme_system: Systeem
theme_title: Thema
timezone: Tijdzone
+ appearances:
+ show:
+ modals_title: Modals
+ modals_subtitle: Gedrag van modals aanpassen
+ disable_modal_click_outside_title: Modals open houden bij klikken buiten
+ disable_modal_click_outside_description: Voorkomt dat modals sluiten bij klikken buiten. Handig om te voorkomen dat niet-opgeslagen wijzigingen per ongeluk verloren gaan.
profiles:
destroy:
cannot_remove_self: U kunt uzelf niet van het account verwijderen.
diff --git a/config/locales/views/settings/pl.yml b/config/locales/views/settings/pl.yml
index 8acfe17722..2ab682b8e8 100644
--- a/config/locales/views/settings/pl.yml
+++ b/config/locales/views/settings/pl.yml
@@ -34,6 +34,10 @@ pl:
theme_dark: Ciemny
theme_light: Jasny
theme_system: Systemowy
+ modals_title: Okna modalne
+ modals_subtitle: Dostosuj zachowanie okien modalnych
+ disable_modal_click_outside_title: Utrzymuj okna modalne otwarte po kliknięciu poza nimi
+ disable_modal_click_outside_description: Zapobiega zamykaniu okien modalnych po kliknięciu poza nimi. Przydatne, aby uniknąć przypadkowej utraty niezapisanych zmian.
transactions_title: Transakcje
transactions_subtitle: Dostosuj sposób wyświetlania transakcji
dashboard_title: Pulpit
diff --git a/config/locales/views/settings/pt-BR.yml b/config/locales/views/settings/pt-BR.yml
index 65962871b9..7b5bd4f357 100644
--- a/config/locales/views/settings/pt-BR.yml
+++ b/config/locales/views/settings/pt-BR.yml
@@ -34,6 +34,10 @@ pt-BR:
theme_dark: Escuro
theme_light: Claro
theme_system: Sistema
+ modals_title: Modais
+ modals_subtitle: Personalizar o comportamento dos modais
+ disable_modal_click_outside_title: Manter modais abertos ao clicar fora
+ disable_modal_click_outside_description: Impede que os modais fechem ao clicar fora deles. Útil para evitar perder alterações não salvas acidentalmente.
transactions_title: Transações
transactions_subtitle: Personalize como as transações são exibidas
dashboard_title: Painel
diff --git a/config/locales/views/settings/ro.yml b/config/locales/views/settings/ro.yml
index 758bb7d5cf..96a82a4810 100644
--- a/config/locales/views/settings/ro.yml
+++ b/config/locales/views/settings/ro.yml
@@ -43,6 +43,12 @@ ro:
theme_system: Sistem
theme_title: Temă
timezone: Fus orar
+ appearances:
+ show:
+ modals_title: Ferestre modale
+ modals_subtitle: Personalizați comportamentul ferestrelor modale
+ disable_modal_click_outside_title: Mențineți ferestrele modale deschise la clic exterior
+ disable_modal_click_outside_description: Previne închiderea ferestrelor modale la clic în afara lor. Util pentru a evita pierderea accidentală a modificărilor nesalvate.
profiles:
destroy:
cannot_remove_self: Nu te poți elimina singur din cont.
diff --git a/config/locales/views/settings/tr.yml b/config/locales/views/settings/tr.yml
index 7ad52df99a..217cc98880 100644
--- a/config/locales/views/settings/tr.yml
+++ b/config/locales/views/settings/tr.yml
@@ -27,6 +27,12 @@ tr:
theme_system: Sistem
theme_title: Tema
timezone: Zaman dilimi
+ appearances:
+ show:
+ modals_title: Modaller
+ modals_subtitle: Modal davranışını özelleştir
+ disable_modal_click_outside_title: Dışarı tıklandığında modalleri açık tut
+ disable_modal_click_outside_description: Modalların dışına tıklandığında kapanmasını engeller. Kaydedilmemiş değişiklikleri yanlışlıkla kaybetmemek için kullanışlıdır.
profiles:
destroy:
cannot_remove_self: Kendinizi hesaptan çıkaramazsınız.
diff --git a/config/locales/views/settings/vi.yml b/config/locales/views/settings/vi.yml
index a5ac5f5e1b..a0ac7956fe 100644
--- a/config/locales/views/settings/vi.yml
+++ b/config/locales/views/settings/vi.yml
@@ -107,6 +107,10 @@ vi:
theme_dark: Tối
theme_light: Sáng
theme_system: Hệ thống
+ modals_title: Hộp thoại
+ modals_subtitle: Tùy chỉnh hành vi hộp thoại
+ disable_modal_click_outside_title: Giữ hộp thoại mở khi nhấp bên ngoài
+ disable_modal_click_outside_description: Ngăn hộp thoại đóng khi nhấp bên ngoài. Hữu ích để tránh vô tình mất các thay đổi chưa lưu.
transactions_title: Giao dịch
transactions_subtitle: Tùy chỉnh cách hiển thị giao dịch
dashboard_title: Bảng điều khiển
diff --git a/config/locales/views/settings/zh-CN.yml b/config/locales/views/settings/zh-CN.yml
index 296573b349..af218042f7 100644
--- a/config/locales/views/settings/zh-CN.yml
+++ b/config/locales/views/settings/zh-CN.yml
@@ -107,6 +107,10 @@ zh-CN:
theme_dark: 深色
theme_light: 浅色
theme_system: 跟随系统
+ modals_title: 模态框
+ modals_subtitle: 自定义模态框行为
+ disable_modal_click_outside_title: 点击外部时保持模态框打开
+ disable_modal_click_outside_description: 防止点击外部时关闭模态框。有助于避免意外丢失未保存的更改。
transactions_title: 交易
transactions_subtitle: 自定义交易的显示方式
dashboard_title: 仪表盘
diff --git a/config/locales/views/settings/zh-TW.yml b/config/locales/views/settings/zh-TW.yml
index 4d544f4797..a3ac0fae11 100644
--- a/config/locales/views/settings/zh-TW.yml
+++ b/config/locales/views/settings/zh-TW.yml
@@ -43,6 +43,12 @@ zh-TW:
theme_system: 系統設定
theme_title: 主題
timezone: 時區
+ appearances:
+ show:
+ modals_title: 模態視窗
+ modals_subtitle: 自訂模態視窗行為
+ disable_modal_click_outside_title: 點擊外部時保持模態視窗開啟
+ disable_modal_click_outside_description: 防止點擊外部時關閉模態視窗。有助於避免意外遺失未儲存的變更。
profiles:
destroy:
cannot_remove_self: 您無法將自己從帳號中移除。