only display not_available error message

This commit is contained in:
simon lehericey 2022-09-27 10:18:59 +02:00
parent 5129fedac4
commit dd7af753fe

View file

@ -6,10 +6,24 @@ class TypesDeChampEditor::ConditionsErrorsComponent < ApplicationComponent
private private
def errors def errors
@conditions errors = @conditions
.flat_map { |condition| condition.errors(@upper_tdcs) } .flat_map { |condition| condition.errors(@upper_tdcs) }
.map { |error| humanize(error) }
.uniq .uniq
# if a tdc is not available (has been removed for example)
# it causes a lot of errors (incompatible type for example)
# only the root cause is displayed
messages = if errors.include?({ type: :not_available })
[t('not_available', scope: '.errors')]
else
errors.map { |error| humanize(error) }
end
to_html_list(messages)
end
def to_html_list(messages)
messages
.map { |message| tag.li(message) } .map { |message| tag.li(message) }
.then { |lis| tag.ul(lis.reduce(&:+)) } .then { |lis| tag.ul(lis.reduce(&:+)) }
end end