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:
parent
6477c0f766
commit
8372e26864
4 changed files with 15 additions and 5 deletions
|
@ -148,15 +148,18 @@ class Import < ApplicationRecord
|
|||
|
||||
name_field = Import::Field.new \
|
||||
key: "name",
|
||||
label: "Name"
|
||||
label: "Name",
|
||||
is_optional: true
|
||||
|
||||
category_field = Import::Field.new \
|
||||
key: "category",
|
||||
label: "Category"
|
||||
label: "Category",
|
||||
is_optional: true
|
||||
|
||||
tags_field = Import::Field.new \
|
||||
key: "tags",
|
||||
label: "Tags"
|
||||
label: "Tags",
|
||||
is_optional: true
|
||||
|
||||
amount_field = Import::Field.new \
|
||||
key: "amount",
|
||||
|
|
|
@ -15,12 +15,17 @@ class Import::Field
|
|||
|
||||
attr_reader :key, :label, :validator
|
||||
|
||||
def initialize(key:, label:, validator: nil)
|
||||
def initialize(key:, label:, is_optional: false, validator: nil)
|
||||
@key = key.to_s
|
||||
@label = label
|
||||
@is_optional = is_optional
|
||||
@validator = validator
|
||||
end
|
||||
|
||||
def optional?
|
||||
@is_optional
|
||||
end
|
||||
|
||||
def define_validator(validator = nil, &block)
|
||||
@validator = validator || block
|
||||
end
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
<% @import.expected_fields.each do |field| %>
|
||||
<%= mappings.select field.key,
|
||||
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 %>
|
||||
</div>
|
||||
|
|
|
@ -18,6 +18,7 @@ en:
|
|||
confirm_title: Are you sure?
|
||||
invalid_csv: Please load a CSV first
|
||||
next: Next
|
||||
optional: "(optional) No column selected"
|
||||
confirm:
|
||||
confirm_description: Preview your transactions below and check to see if there
|
||||
are any changes that are required.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue