From 670a0c89e2d4ca8acd949267c680f65d7ea92e6c Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 7 Oct 2024 21:32:16 -0400 Subject: [PATCH 1/7] Add empty states to account summary page --- app/models/account.rb | 17 +-- app/views/accounts/_header.html.erb | 2 - app/views/accounts/summary.html.erb | 100 ++++++++++-------- .../pages/_account_percentages_bar.html.erb | 4 +- .../pages/_account_percentages_table.html.erb | 2 +- config/locales/views/accounts/en.yml | 6 +- 6 files changed, 75 insertions(+), 56 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index cf6ff98be96..fcba6c26f22 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -39,13 +39,16 @@ def by_group(period: Period.all, currency: Money.default_currency.iso_code) Accountable.by_classification.each do |classification, types| types.each do |type| - group = grouped_accounts[classification.to_sym].add_child_group(type, currency) - self.where(accountable_type: type).each do |account| - group.add_value_node( - account, - account.balance_money.exchange_to(currency, fallback_rate: 0), - account.series(period: period, currency: currency) - ) + accounts = self.where(accountable_type: type) + if accounts.any? + group = grouped_accounts[classification.to_sym].add_child_group(type, currency) + accounts.each do |account| + group.add_value_node( + account, + account.balance_money.exchange_to(currency, fallback_rate: 0), + account.series(period: period, currency: currency) + ) + end end end end diff --git a/app/views/accounts/_header.html.erb b/app/views/accounts/_header.html.erb index 3e43e29a2f7..f8c8eb3e557 100644 --- a/app/views/accounts/_header.html.erb +++ b/app/views/accounts/_header.html.erb @@ -13,8 +13,6 @@ <% end %> - <%= render "sync_all_button" %> - <%= link_to new_account_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %> <%= lucide_icon("plus", class: "w-5 h-5") %>

<%= t(".new") %>

diff --git a/app/views/accounts/summary.html.erb b/app/views/accounts/summary.html.erb index 4dc83eaf2ca..2cf99be6548 100644 --- a/app/views/accounts/summary.html.erb +++ b/app/views/accounts/summary.html.erb @@ -2,75 +2,89 @@ <%= render "header" %> - <% if @accounts.empty? %> - <%= render "shared/no_account_empty_state" %> - <% else %> -
-
-
- <%= render partial: "shared/value_heading", locals: { +
+
+
+ <%= render partial: "shared/value_heading", locals: { label: "Assets", period: @period, value: Current.family.assets, trend: @asset_series.trend } %> -
-
+
-
-
-
- <%= render partial: "shared/value_heading", locals: { +
+
+
+ <%= render partial: "shared/value_heading", locals: { label: "Liabilities", period: @period, size: "md", value: Current.family.liabilities, trend: @liability_series.trend } %> -
-
+
-
-
-
-

Assets

-
- <%= link_to new_account_path, class: "flex items-center gap-1 p-2 pr-3 text-gray-900 text-sm font-medium bg-gray-50 rounded-lg hover:bg-gray-100", data: { turbo_frame: "modal" } do %> - <%= lucide_icon("plus", class: "w-5 h-5 text-gray-500") %> -

<%= t(".new") %>

- <% end %> - <%= form_with url: summary_accounts_path, method: :get, data: { controller: "auto-submit-form" } do |form| %> - <%= period_select form: form, selected: @period.name %> - <% end %> -
+
+
+
+

Assets

+
+ <%= link_to new_account_path, class: "btn btn--secondary flex items-center gap-1", data: { turbo_frame: "modal" } do %> + <%= lucide_icon("plus", class: "w-5 h-5 text-gray-500") %> +

<%= t(".new") %>

+ <% end %> + <%= form_with url: summary_accounts_path, method: :get, data: { controller: "auto-submit-form" } do |form| %> + <%= period_select form: form, selected: @period.name %> + <% end %>
+
+ + <% if @account_groups[:assets].children.any? %> <%= render partial: "pages/account_percentages_bar", locals: { account_groups: @account_groups[:assets].children } %> <%= render partial: "pages/account_percentages_table", locals: { account_groups: @account_groups[:assets].children } %> -
-
-
-

Liabilities

-
- <%= link_to new_account_path, class: "flex items-center gap-1 p-2 pr-3 text-gray-900 text-sm font-medium bg-gray-50 rounded-lg hover:bg-gray-100", data: { turbo_frame: "modal" } do %> - <%= lucide_icon("plus", class: "w-5 h-5 text-gray-500") %> -

<%= t(".new") %>

- <% end %> - <%= form_with url: summary_accounts_path, method: :get, data: { controller: "auto-submit-form" } do |form| %> - <%= period_select form: form, selected: @period.name %> - <% end %> -
+ <% else %> +
+ <%= lucide_icon "blocks", class: "w-6 h-6 shrink-0 text-gray-500" %> +

<%= t(".no_assets") %>

+

<%= t(".no_assets_description") %>

+
+ <% end %> +
+
+
+

Liabilities

+
+ <%= link_to new_account_path, class: "btn btn--secondary flex items-center gap-1", data: { turbo_frame: "modal" } do %> + <%= lucide_icon("plus", class: "w-5 h-5 text-gray-500") %> +

<%= t(".new") %>

+ <% end %> + <%= form_with url: summary_accounts_path, method: :get, data: { controller: "auto-submit-form" } do |form| %> + <%= period_select form: form, selected: @period.name %> + <% end %>
+
+ + <% if @account_groups[:liabilities].children.any? %> <%= render partial: "pages/account_percentages_bar", locals: { account_groups: @account_groups[:liabilities].children } %> <%= render partial: "pages/account_percentages_table", locals: { account_groups: @account_groups[:liabilities].children } %> -
- <% end %> + <% else %> +
+ <%= lucide_icon "blocks", class: "w-6 h-6 shrink-0 text-gray-500" %> +

<%= t(".no_liabilities") %>

+

<%= t(".no_liabilities_description") %>

+
+ <% end %> +
diff --git a/app/views/pages/_account_percentages_bar.html.erb b/app/views/pages/_account_percentages_bar.html.erb index cab529d8178..f7394a6007f 100644 --- a/app/views/pages/_account_percentages_bar.html.erb +++ b/app/views/pages/_account_percentages_bar.html.erb @@ -1,12 +1,12 @@ <%# locals: (account_groups:) %>
- <% account_groups.each do |group| %> + <% account_groups.sort_by(&:percent_of_total).reverse.each do |group| %>
<% end %>
- <% account_groups.each do |group| %> + <% account_groups.sort_by(&:percent_of_total).reverse.each do |group| %>

<%= to_accountable_title(Accountable.from_type(group.name)) %>

diff --git a/app/views/pages/_account_percentages_table.html.erb b/app/views/pages/_account_percentages_table.html.erb index f96d7ec1360..3fa8126d4c1 100644 --- a/app/views/pages/_account_percentages_table.html.erb +++ b/app/views/pages/_account_percentages_table.html.erb @@ -15,6 +15,6 @@
- <%= render partial: "pages/account_group_disclosure", collection: account_groups, as: :accountable_group %> + <%= render partial: "pages/account_group_disclosure", collection: account_groups.sort_by(&:percent_of_total).reverse, as: :accountable_group %>
diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml index 832bcce30b1..ef71a5f7b94 100644 --- a/config/locales/views/accounts/en.yml +++ b/config/locales/views/accounts/en.yml @@ -107,7 +107,11 @@ en: transactions: Transactions value: Value summary: - new: New account + new: New + no_assets: No assets found + no_assets_description: Add an asset either via connection, importing or entering manually. + no_liabilities: No liabilities found + no_liabilities_description: Add a liability either via connection, importing or entering manually. sync_all: button_text: Sync all success: Successfully queued accounts for syncing. From 454c56e0d4964f793c5bf0b750310014b4aee611 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 7 Oct 2024 21:33:57 -0400 Subject: [PATCH 2/7] Liability icon fix --- app/views/accounts/summary.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/accounts/summary.html.erb b/app/views/accounts/summary.html.erb index 2cf99be6548..feffec64f77 100644 --- a/app/views/accounts/summary.html.erb +++ b/app/views/accounts/summary.html.erb @@ -81,7 +81,7 @@ <%= render partial: "pages/account_percentages_table", locals: { account_groups: @account_groups[:liabilities].children } %> <% else %>
- <%= lucide_icon "blocks", class: "w-6 h-6 shrink-0 text-gray-500" %> + <%= lucide_icon "scale", class: "w-6 h-6 shrink-0 text-gray-500" %>

<%= t(".no_liabilities") %>

<%= t(".no_liabilities_description") %>

From abfe559f689d12721b4f1c1d38ee64d61db4fe11 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 8 Oct 2024 07:15:12 -0400 Subject: [PATCH 3/7] Normalize translations --- config/locales/views/accounts/en.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml index ef71a5f7b94..b1c816af448 100644 --- a/config/locales/views/accounts/en.yml +++ b/config/locales/views/accounts/en.yml @@ -109,9 +109,11 @@ en: summary: new: New no_assets: No assets found - no_assets_description: Add an asset either via connection, importing or entering manually. + no_assets_description: Add an asset either via connection, importing or entering + manually. no_liabilities: No liabilities found - no_liabilities_description: Add a liability either via connection, importing or entering manually. + no_liabilities_description: Add a liability either via connection, importing + or entering manually. sync_all: button_text: Sync all success: Successfully queued accounts for syncing. From 4fd6f269c4a83c5e665606ff703d82977972cbbc Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 8 Oct 2024 07:43:00 -0400 Subject: [PATCH 4/7] Clean up modal styles --- app/views/accounts/_account_type.html.erb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/accounts/_account_type.html.erb b/app/views/accounts/_account_type.html.erb index be85f847f60..0cf99e4e004 100644 --- a/app/views/accounts/_account_type.html.erb +++ b/app/views/accounts/_account_type.html.erb @@ -1,4 +1,9 @@ -<%= link_to new_account_path(step: "method", type: type.class.name.demodulize, institution_id: params[:institution_id]), class: "flex items-center gap-4 w-full text-center focus:outline-none focus:bg-gray-25 border border-transparent focus:border focus:border-gray-200 block px-2 hover:bg-gray-25 rounded-lg p-2" do %> +<%= link_to new_account_path( + step: "method", + type: type.class.name.demodulize, + institution_id: params[:institution_id] + ), + class: "flex items-center gap-4 w-full text-center focus:outline-none focus:bg-alpha-black-25 hover:bg-alpha-black-25 border border-transparent block px-2 rounded-lg p-2" do %> <%= lucide_icon(icon, class: "#{text_color} w-5 h-5") %> From c5103d2c24dd682fe19f763540441c750ad12c81 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 8 Oct 2024 07:44:59 -0400 Subject: [PATCH 5/7] Account color updates --- app/views/accounts/new.html.erb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/accounts/new.html.erb b/app/views/accounts/new.html.erb index 460293a25af..2beba39974e 100644 --- a/app/views/accounts/new.html.erb +++ b/app/views/accounts/new.html.erb @@ -8,15 +8,15 @@
- <%= render "account_type", type: Depository.new, bg_color: "bg-blue-50", text_color: "text-blue-500", icon: "landmark" %> - <%= render "account_type", type: Investment.new, bg_color: "bg-green-50", text_color: "text-green-500", icon: "line-chart" %> - <%= render "account_type", type: Crypto.new, bg_color: "bg-green-50", text_color: "text-green-500", icon: "bitcoin" %> - <%= render "account_type", type: Property.new, bg_color: "bg-pink-50", text_color: "text-pink-500", icon: "home" %> - <%= render "account_type", type: Vehicle.new, bg_color: "bg-indigo-50", text_color: "text-indigo-500", icon: "car-front" %> - <%= render "account_type", type: CreditCard.new, bg_color: "bg-violet-50", text_color: "text-violet-500", icon: "credit-card" %> - <%= render "account_type", type: Loan.new, bg_color: "bg-yellow-50", text_color: "text-yellow-500", icon: "hand-coins" %> - <%= render "account_type", type: OtherAsset.new, bg_color: "bg-green-50", text_color: "text-green-500", icon: "plus" %> - <%= render "account_type", type: OtherLiability.new, bg_color: "bg-red-50", text_color: "text-red-500", icon: "minus" %> + <%= render "account_type", type: Depository.new, bg_color: "bg-blue-500/5", text_color: "text-blue-500", icon: "landmark" %> + <%= render "account_type", type: Investment.new, bg_color: "bg-green-500/5", text_color: "text-green-500", icon: "line-chart" %> + <%= render "account_type", type: Crypto.new, bg_color: "bg-orange-500/5", text_color: "text-orange-500", icon: "bitcoin" %> + <%= render "account_type", type: Property.new, bg_color: "bg-pink-500/5", text_color: "text-pink-500", icon: "home" %> + <%= render "account_type", type: Vehicle.new, bg_color: "bg-cyan-500/5", text_color: "text-cyan-500", icon: "car-front" %> + <%= render "account_type", type: CreditCard.new, bg_color: "bg-violet-500/5", text_color: "text-violet-500", icon: "credit-card" %> + <%= render "account_type", type: Loan.new, bg_color: "bg-yellow-500/5", text_color: "text-yellow-500", icon: "hand-coins" %> + <%= render "account_type", type: OtherAsset.new, bg_color: "bg-green-500/5", text_color: "text-green-500", icon: "plus" %> + <%= render "account_type", type: OtherLiability.new, bg_color: "bg-red-500/5", text_color: "text-red-500", icon: "minus" %>
From f04b02fce74954d5c4ab92545ea7fac34035a523 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 8 Oct 2024 07:45:33 -0400 Subject: [PATCH 6/7] Lint fixes --- app/views/accounts/_account_type.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/accounts/_account_type.html.erb b/app/views/accounts/_account_type.html.erb index 0cf99e4e004..d8b400c7c4c 100644 --- a/app/views/accounts/_account_type.html.erb +++ b/app/views/accounts/_account_type.html.erb @@ -1,8 +1,8 @@ <%= link_to new_account_path( - step: "method", - type: type.class.name.demodulize, + step: "method", + type: type.class.name.demodulize, institution_id: params[:institution_id] - ), + ), class: "flex items-center gap-4 w-full text-center focus:outline-none focus:bg-alpha-black-25 hover:bg-alpha-black-25 border border-transparent block px-2 rounded-lg p-2" do %> <%= lucide_icon(icon, class: "#{text_color} w-5 h-5") %> From 0e46c3a0e8711534c12166b310c5c41466faba89 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 8 Oct 2024 12:56:38 -0400 Subject: [PATCH 7/7] Test fix --- test/system/accounts_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/system/accounts_test.rb b/test/system/accounts_test.rb index 2ccb9081f34..666fa843e9e 100644 --- a/test/system/accounts_test.rb +++ b/test/system/accounts_test.rb @@ -58,11 +58,9 @@ class AccountsTest < ApplicationSystemTestCase assert_account_created("OtherLiability") end - test "can sync all acounts on accounts page and account summary page" do + test "can sync all acounts on accounts page" do visit accounts_url assert_button "Sync all" - visit summary_accounts_url - assert_button "Sync all" end private