1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-03 20:45:21 +02:00

Allow optional import fields (#865)

This commit is contained in:
Zach Gollwitzer 2024-06-11 18:46:44 -04:00 committed by GitHub
parent 6477c0f766
commit 8372e26864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 5 deletions

View file

@ -148,15 +148,18 @@ class Import < ApplicationRecord
name_field = Import::Field.new \ name_field = Import::Field.new \
key: "name", key: "name",
label: "Name" label: "Name",
is_optional: true
category_field = Import::Field.new \ category_field = Import::Field.new \
key: "category", key: "category",
label: "Category" label: "Category",
is_optional: true
tags_field = Import::Field.new \ tags_field = Import::Field.new \
key: "tags", key: "tags",
label: "Tags" label: "Tags",
is_optional: true
amount_field = Import::Field.new \ amount_field = Import::Field.new \
key: "amount", key: "amount",

View file

@ -15,12 +15,17 @@ class Import::Field
attr_reader :key, :label, :validator attr_reader :key, :label, :validator
def initialize(key:, label:, validator: nil) def initialize(key:, label:, is_optional: false, validator: nil)
@key = key.to_s @key = key.to_s
@label = label @label = label
@is_optional = is_optional
@validator = validator @validator = validator
end end
def optional?
@is_optional
end
def define_validator(validator = nil, &block) def define_validator(validator = nil, &block)
@validator = validator || block @validator = validator || block
end end

View file

@ -14,7 +14,8 @@
<% @import.expected_fields.each do |field| %> <% @import.expected_fields.each do |field| %>
<%= mappings.select field.key, <%= mappings.select field.key,
options_for_select(@import.available_headers, @import.get_selected_header_for_field(field)), options_for_select(@import.available_headers, @import.get_selected_header_for_field(field)),
label: field.label %> label: field.label,
include_blank: field.optional? ? t(".optional") : false %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>

View file

@ -18,6 +18,7 @@ en:
confirm_title: Are you sure? confirm_title: Are you sure?
invalid_csv: Please load a CSV first invalid_csv: Please load a CSV first
next: Next next: Next
optional: "(optional) No column selected"
confirm: confirm:
confirm_description: Preview your transactions below and check to see if there confirm_description: Preview your transactions below and check to see if there
are any changes that are required. are any changes that are required.