mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
CSV Imports Overhaul (Transactions, Trades, Accounts, and Mint import support) (#1209)
* Remove stale 1.0 import logic and model * Fresh start * Checkpoint before removing nav * First working prototype * Add trade, account, and mint import flows * Basic working version with tests * System tests for each import type * Clean up mappings flow * Clean up PR, refactor stale code, tests * Add back row validations * Row validations * Fix import job test * Fix import navigation * Fix mint import configuration form * Currency preset for new accounts
This commit is contained in:
parent
23786b444a
commit
398b246965
103 changed files with 2420 additions and 1689 deletions
|
@ -1,19 +1,63 @@
|
|||
module ImportsHelper
|
||||
def table_corner_class(row_idx, col_idx, rows, cols)
|
||||
return "rounded-tl-xl" if row_idx == 0 && col_idx == 0
|
||||
return "rounded-tr-xl" if row_idx == 0 && col_idx == cols.size - 1
|
||||
return "rounded-bl-xl" if row_idx == rows.size - 1 && col_idx == 0
|
||||
return "rounded-br-xl" if row_idx == rows.size - 1 && col_idx == cols.size - 1
|
||||
""
|
||||
def mapping_label(mapping_class)
|
||||
{
|
||||
"Import::AccountTypeMapping" => "Account Type",
|
||||
"Import::AccountMapping" => "Account",
|
||||
"Import::CategoryMapping" => "Category",
|
||||
"Import::TagMapping" => "Tag"
|
||||
}.fetch(mapping_class.name)
|
||||
end
|
||||
|
||||
def nav_steps(import = Import.new)
|
||||
[
|
||||
{ name: "Select", complete: import.persisted?, path: import.persisted? ? edit_import_path(import) : new_import_path },
|
||||
{ name: "Import", complete: import.loaded?, path: import.persisted? ? load_import_path(import) : nil },
|
||||
{ name: "Setup", complete: import.configured?, path: import.persisted? ? configure_import_path(import) : nil },
|
||||
{ name: "Clean", complete: import.cleaned?, path: import.persisted? ? clean_import_path(import) : nil },
|
||||
{ name: "Confirm", complete: import.complete?, path: import.persisted? ? confirm_import_path(import) : nil }
|
||||
]
|
||||
def import_col_label(key)
|
||||
{
|
||||
date: "Date",
|
||||
amount: "Amount",
|
||||
name: "Name",
|
||||
currency: "Currency",
|
||||
category: "Category",
|
||||
tags: "Tags",
|
||||
account: "Account",
|
||||
notes: "Notes",
|
||||
qty: "Quantity",
|
||||
ticker: "Ticker",
|
||||
price: "Price",
|
||||
entity_type: "Type"
|
||||
}[key]
|
||||
end
|
||||
|
||||
def dry_run_resource(key)
|
||||
map = {
|
||||
transactions: DryRunResource.new(label: "Transactions", icon: "credit-card", text_class: "text-cyan-500", bg_class: "bg-cyan-500/5"),
|
||||
accounts: DryRunResource.new(label: "Accounts", icon: "layers", text_class: "text-orange-500", bg_class: "bg-orange-500/5"),
|
||||
categories: DryRunResource.new(label: "Categories", icon: "shapes", text_class: "text-blue-500", bg_class: "bg-blue-500/5"),
|
||||
tags: DryRunResource.new(label: "Tags", icon: "tags", text_class: "text-violet-500", bg_class: "bg-violet-500/5")
|
||||
}
|
||||
|
||||
map[key]
|
||||
end
|
||||
|
||||
def permitted_import_configuration_path(import)
|
||||
if permitted_import_types.include?(import.type.underscore)
|
||||
"import/configurations/#{import.type.underscore}"
|
||||
else
|
||||
raise "Unknown import type: #{import.type}"
|
||||
end
|
||||
end
|
||||
|
||||
def cell_class(row, field)
|
||||
base = "text-sm focus:ring-gray-900 focus:border-gray-900 w-full max-w-full disabled:text-gray-400"
|
||||
|
||||
row.valid? # populate errors
|
||||
|
||||
border = row.errors.key?(field) ? "border-red-500" : "border-transparent"
|
||||
|
||||
[ base, border ].join(" ")
|
||||
end
|
||||
|
||||
private
|
||||
def permitted_import_types
|
||||
%w[transaction_import trade_import account_import mint_import]
|
||||
end
|
||||
|
||||
DryRunResource = Struct.new(:label, :icon, :text_class, :bg_class, keyword_init: true)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue