Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix statement Turbo frame navigation and split view/edit actions (#2614) (#2695)

Bishal Shrestha82df89ef4566
diff --git a/app/views/accounts/show/_statements.html.erb b/app/views/accounts/show/_statements.html.erb
index 3a5d4a11ae..6be92fd4e3 100644
--- a/app/views/accounts/show/_statements.html.erb
+++ b/app/views/accounts/show/_statements.html.erb
@@ -19,6 +19,7 @@
aria: { label: t("account_statements.account_tab.year_label") } %>
<% end %>
<%= link_to account_statements_path,
+ data: { turbo_frame: "_top" },
class: "inline-flex items-center gap-2 text-sm font-medium text-primary hover:text-primary-hover" do %>
<%= icon("inbox", size: "sm") %>
<%= t("account_statements.account_tab.open_inbox") %>
@@ -75,7 +76,11 @@
<% statements.each do |statement| %>
<tr id="<%= dom_id(statement) %>" class="border-b border-subdued hover:bg-surface-hover">
<td class="px-3 py-3">
- <%= link_to account_statement_path(statement), class: "flex items-center gap-2 min-w-0 text-sm font-medium text-primary hover:underline" do %>
+ <% file_attached = statement.original_file.attached? %>
+ <%= link_to file_attached ? rails_blob_path(statement.original_file, disposition: "inline") : account_statement_path(statement),
+ target: (file_attached ? "_blank" : nil),
+ data: { turbo_frame: "_top" },
+ class: "flex items-center gap-2 min-w-0 text-sm font-medium text-primary hover:underline" do %>
<%= icon(account_statement_file_icon(statement), size: "sm") %>
<span class="truncate"><%= statement.filename %></span>
<% end %>
@@ -94,10 +99,25 @@
</td>
<td class="px-3 py-3">
<div class="flex items-center justify-end gap-3">
- <%= link_to account_statement_path(statement), aria: { label: t("account_statements.table.view") } do %>
- <%= icon("eye", class: "w-5 h-5 text-primary") %>
+ <%# View: open the actual file inline (PDF) or download (CSV/XLSX) %>
+ <% if file_attached %>
+ <%= link_to rails_blob_path(statement.original_file, disposition: "inline"),
+ target: "_blank",
+ data: { turbo_frame: "_top" },
+ aria: { label: t("account_statements.table.view") } do %>
+ <%= icon("eye", class: "w-5 h-5 text-primary") %>
+ <% end %>
+ <% end %>
+
+ <%# Edit: go to statement details/edit page %>
+ <%= link_to account_statement_path(statement),
+ data: { turbo_frame: "_top" },
+ aria: { label: t("account_statements.table.edit") } do %>
+ <%= icon("pencil", class: "w-5 h-5 text-primary") %>
<% end %>
- <% if statement.original_file.attached? %>
+
+ <%# Download %>
+ <% if file_attached %>
<%= link_to rails_blob_path(statement.original_file, disposition: "attachment"), aria: { label: t("account_statements.table.download") } do %>
<%= icon("download", class: "w-5 h-5 text-primary") %>
<% end %>
@@ -106,6 +126,7 @@
<%= button_to unlink_account_statement_path(statement),
method: :patch,
class: "flex items-center",
+ form: { data: { turbo_frame: "_top" } },
aria: { label: t("account_statements.table.unlink") } do %>
<%= icon("unlink", class: "w-5 h-5 text-secondary") %>
<% end %>
diff --git a/config/locales/views/account_statements/ca.yml b/config/locales/views/account_statements/ca.yml
index 84f7324242..d4e0df21fb 100644
--- a/config/locales/views/account_statements/ca.yml
+++ b/config/locales/views/account_statements/ca.yml
@@ -105,6 +105,7 @@ ca:
account: Compte
actions: Accions
download: Descarrega
+ edit: Edita
file: Fitxer
link_suggestion: Suggeriment d'enllaç
period: Període
diff --git a/config/locales/views/account_statements/de.yml b/config/locales/views/account_statements/de.yml
index 52d629ca47..47d372156d 100644
--- a/config/locales/views/account_statements/de.yml
+++ b/config/locales/views/account_statements/de.yml
@@ -102,6 +102,7 @@ de:
account: Konto
actions: Aktionen
download: Herunterladen
+ edit: Bearbeiten
file: Datei
link_suggestion: Verknüpfungsvorschlag
period: Zeitraum
diff --git a/config/locales/views/account_statements/en.yml b/config/locales/views/account_statements/en.yml
index 78e21ae574..6a4062d47d 100644
--- a/config/locales/views/account_statements/en.yml
+++ b/config/locales/views/account_statements/en.yml
@@ -102,6 +102,7 @@ en:
account: Account
actions: Actions
download: Download
+ edit: Edit
file: File
link_suggestion: Link suggestion
period: Period
diff --git a/config/locales/views/account_statements/es.yml b/config/locales/views/account_statements/es.yml
index 3486f844db..8572eb7180 100644
--- a/config/locales/views/account_statements/es.yml
+++ b/config/locales/views/account_statements/es.yml
@@ -102,6 +102,7 @@ es:
account: Cuenta
actions: Acciones
download: Descargar
+ edit: Editar
file: Archivo
link_suggestion: Sugerencia de vínculo
period: Periodo
diff --git a/config/locales/views/account_statements/fr.yml b/config/locales/views/account_statements/fr.yml
index 57d8714237..b2b0265374 100644
--- a/config/locales/views/account_statements/fr.yml
+++ b/config/locales/views/account_statements/fr.yml
@@ -107,6 +107,7 @@ fr:
account: Compte
actions: Actions
download: Télécharger
+ edit: Modifier
file: Fichier
link_suggestion: Suggestion de lien
period: Période
diff --git a/config/locales/views/account_statements/hu.yml b/config/locales/views/account_statements/hu.yml
index 0a3fc5966d..8a9201114f 100644
--- a/config/locales/views/account_statements/hu.yml
+++ b/config/locales/views/account_statements/hu.yml
@@ -102,6 +102,7 @@ hu:
account: Számla
actions: Műveletek
download: Letöltés
+ edit: Szerkesztés
file: Fájl
link_suggestion: Kapcsolati javaslat
period: Időszak
diff --git a/config/locales/views/account_statements/nl.yml b/config/locales/views/account_statements/nl.yml
index bc33505b94..35e302f6ed 100644
--- a/config/locales/views/account_statements/nl.yml
+++ b/config/locales/views/account_statements/nl.yml
@@ -102,6 +102,7 @@ nl:
account: Account
actions: Acties
download: Downloaden
+ edit: Bewerken
file: Bestand
link_suggestion: Koppelsuggestie
period: Periode
diff --git a/config/locales/views/account_statements/pt-BR.yml b/config/locales/views/account_statements/pt-BR.yml
index 7f8f840573..5a44e1cb76 100644
--- a/config/locales/views/account_statements/pt-BR.yml
+++ b/config/locales/views/account_statements/pt-BR.yml
@@ -102,6 +102,7 @@ pt-BR:
account: Conta
actions: Ações
download: Baixar
+ edit: Editar
file: Arquivo
link_suggestion: Sugestão de vínculo
period: Período
diff --git a/config/locales/views/account_statements/ru.yml b/config/locales/views/account_statements/ru.yml
index 0c67d7872a..6a33009f2b 100644
--- a/config/locales/views/account_statements/ru.yml
+++ b/config/locales/views/account_statements/ru.yml
@@ -110,6 +110,7 @@ ru:
account: Счёт
actions: Действия
download: Скачать
+ edit: Редактировать
file: Файл
link_suggestion: Предложение привязки
period: Период
diff --git a/config/locales/views/account_statements/vi.yml b/config/locales/views/account_statements/vi.yml
index 709ca0c452..b68ed162be 100644
--- a/config/locales/views/account_statements/vi.yml
+++ b/config/locales/views/account_statements/vi.yml
@@ -102,6 +102,7 @@ vi:
account: Tài khoản
actions: Hành động
download: Tải xuống
+ edit: Chỉnh sửa
file: Tệp
link_suggestion: Gợi ý liên kết
period: Kỳ
diff --git a/config/locales/views/account_statements/zh-CN.yml b/config/locales/views/account_statements/zh-CN.yml
index 73e27a5139..96001b4939 100644
--- a/config/locales/views/account_statements/zh-CN.yml
+++ b/config/locales/views/account_statements/zh-CN.yml
@@ -102,6 +102,7 @@ zh-CN:
account: 账户
actions: 操作
download: 下载
+ edit: 编辑
file: 文件
link_suggestion: 关联建议
period: 周期
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index 8ace6ec048..a62ead4ac3 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -31,6 +31,39 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_select "turbo-frame[src='#{statements_path}']"
end
+ test "statements tab links escape turbo frame for full-page navigation" do
+ # Upload a statement to ensure table rows render
+ statement = AccountStatement.create_from_upload!(
+ family: @account.family,
+ file: uploaded_file(
+ filename: "test.pdf",
+ content_type: "application/pdf",
+ content: "%PDF-1.4 test content"
+ ),
+ account: @account
+ )
+
+
+ get account_url(@account, tab: "statements")
+
+ assert_response :success
+
+ # Inbox link escapes frame
+ assert_select "a[href='#{account_statements_path}'][data-turbo-frame='_top']"
+
+ # Statement filename link escapes frame
+ assert_select "a[data-turbo-frame='_top']", text: statement.filename
+
+ # Eye/view icon escapes frame and opens in new tab
+ assert_select "a[target='_blank'][data-turbo-frame='_top'][aria-label='#{I18n.t("account_statements.table.view")}']"
+
+ # Edit icon escapes frame
+ assert_select "a[href='#{account_statement_path(statement)}'][data-turbo-frame='_top'][aria-label='#{I18n.t("account_statements.table.edit")}']"
+
+ # Unlink button escapes frame
+ assert_select "form[action='#{unlink_account_statement_path(statement)}'][data-turbo-frame='_top'] button"
+ end
+
test "statements tab shows coverage and upload for statement managers with account write access" do
get account_url(@account, tab: "statements")