Allow optional import fields (#865)

This commit was merged in pull request #865.
This commit is contained in:
Zach Gollwitzer
2024-06-11 18:46:44 -04:00
committed by GitHub
parent 6477c0f766
commit 8372e26864
4 changed files with 15 additions and 5 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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>

View File

@@ -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.