From d3151be9ae12f09bd1895ac6cc3358283927c8a6 Mon Sep 17 00:00:00 2001 From: Adrien Poly Date: Sun, 11 Feb 2024 19:34:18 +0100 Subject: [PATCH 1/3] fix migration and add smoke test for migrations (#438) * adds a smoke test in the CI for the migration * add back money rails gem * really remove money-rails * update the migration to remove add_monetize --- .github/workflows/ci.yml | 8 +++++++- db/migrate/20240206031739_replace_money_field.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73c24574..9d92bb91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: pull_request: push: - branches: [ main ] + branches: [main] jobs: scan_ruby: @@ -92,6 +92,12 @@ jobs: # REDIS_URL: redis://localhost:6379/0 run: bin/rails db:setup test test:system + - name: Smoke test database seeds + env: + RAILS_ENV: test + DATABASE_URL: postgres://postgres:postgres@localhost:5432 + run: bin/rails db:reset + - name: Keep screenshots from failed system tests uses: actions/upload-artifact@v4 if: failure() diff --git a/db/migrate/20240206031739_replace_money_field.rb b/db/migrate/20240206031739_replace_money_field.rb index 4c5ef9db..48e4d188 100644 --- a/db/migrate/20240206031739_replace_money_field.rb +++ b/db/migrate/20240206031739_replace_money_field.rb @@ -1,6 +1,6 @@ class ReplaceMoneyField < ActiveRecord::Migration[7.2] def change - add_monetize :accounts, :balance + add_column :accounts, :balance_cents change_column :accounts, :balance_cents, :integer, limit: 8 Account.reset_column_information From aef15c937183ffbec9bd8fc5aab398cd45d2af1c Mon Sep 17 00:00:00 2001 From: Sergey Tyan Date: Mon, 12 Feb 2024 02:38:28 +0800 Subject: [PATCH 2/3] Add controller to save accounts collapse state to localStorage (#432) * Add controller to save accounts collapse state to localStorage * Small clean up * Fix indentation --- .../account_collapse_controller.js | 53 +++++++++++++++++++ app/views/accounts/_account_list.html.erb | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/javascript/controllers/account_collapse_controller.js diff --git a/app/javascript/controllers/account_collapse_controller.js b/app/javascript/controllers/account_collapse_controller.js new file mode 100644 index 00000000..2f453198 --- /dev/null +++ b/app/javascript/controllers/account_collapse_controller.js @@ -0,0 +1,53 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="account-collapse" +export default class extends Controller { + static values = { type: String } + boundOnToggle = null + initialToggle = false + STORAGE_NAME = "accountCollapseStates" + + connect() { + this.boundOnToggle = this.onToggle.bind(this) + this.element.addEventListener("toggle", this.boundOnToggle) + this.updateFromLocalStorage() + } + + disconnect() { + this.element.removeEventListener("toggle", this.boundOnToggle) + } + + onToggle() { + if (this.initialToggle) { + this.initialToggle = false + return + } + + const items = this.getItemsFromLocalStorage() + if (items.has(this.typeValue)) { + items.delete(this.typeValue) + } else { + items.add(this.typeValue) + } + localStorage.setItem(this.STORAGE_NAME, JSON.stringify([...items])) + } + + updateFromLocalStorage() { + const items = this.getItemsFromLocalStorage() + + if (items.has(this.typeValue)) { + this.initialToggle = true + this.element.setAttribute("open", "") + } + } + + getItemsFromLocalStorage() { + try { + const items = localStorage.getItem(this.STORAGE_NAME) + return new Set(items ? JSON.parse(items) : []) + } catch (error) { + console.error("Error parsing items from localStorage:", error) + return new Set() + } + } +} diff --git a/app/views/accounts/_account_list.html.erb b/app/views/accounts/_account_list.html.erb index 96a33999..90bb9294 100644 --- a/app/views/accounts/_account_list.html.erb +++ b/app/views/accounts/_account_list.html.erb @@ -3,7 +3,7 @@ <% accounts = Current.family.accounts.where(accountable_type: type.name) %> <% if accounts.sum(&:converted_balance) > 0 %> -
+
<%= lucide_icon("chevron-down", class: "hidden group-open:block text-[#737373] w-5 h-5") %> <%= lucide_icon("chevron-right", class: "group-open:hidden text-[#737373] w-5 h-5") %> From e37ed2c98871e374d7b0124dea4c724da18bb440 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Sun, 11 Feb 2024 18:47:58 +0000 Subject: [PATCH 3/3] Add sidebar link helper (#435) * Add helper for sidebar nav links * Allow options to be passed down to sidebar link --- app/helpers/application_helper.rb | 18 ++++++++++++++++++ app/views/layouts/application.html.erb | 15 +++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 18b88f95..50f1f745 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -18,6 +18,24 @@ module ApplicationHelper render partial: "shared/modal", locals: { content: content } end + def sidebar_link_to(name, path, options = {}) + base_class_names = "block border border-transparent rounded-xl -ml-2 p-2 text-sm font-medium text-gray-500 flex items-center" + hover_class_names = "hover:bg-white hover:border-[#141414]/[0.07] hover:text-gray-900 hover:shadow-xs" + current_page_class_names = "bg-white border-[#141414]/[0.07] text-gray-900 shadow-xs" + + link_class_names = class_names( + base_class_names, + hover_class_names, + current_page_class_names => current_page?(path) + ) + + merged_options = options.reverse_merge(class: link_class_names).except(:icon) + + link_to path, merged_options do + lucide_icon(options[:icon], class: "w-5 h-5 mr-2") + name + end + end + def format_currency(number, options = {}) user_currency_preference = Current.family.try(:currency) || "USD" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f9cb8e4b..ff8d2db1 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -47,22 +47,13 @@