add errors_summary component

This commit is contained in:
simon lehericey 2022-06-28 12:14:32 +02:00 committed by LeSim
parent a98484809f
commit f4b465a03f
6 changed files with 36 additions and 0 deletions

View file

@ -1,4 +1,5 @@
.types-de-champ-editor.editor-root{ 'data-turbo': 'true', id: dom_id(@revision, :types_de_champ_editor) }
= render TypesDeChampEditor::ErrorsSummary.new(revision: @revision)
= render TypesDeChampEditor::BlockComponent.new(block: @revision, coordinates: coordinates)
.buttons
= render TypesDeChampEditor::AddChampButtonComponent.new(revision: @revision, is_annotation: annotations?)

View file

@ -0,0 +1,18 @@
class TypesDeChampEditor::ErrorsSummary < ApplicationComponent
def initialize(revision:)
@revision = revision
end
private
def error_message
@revision.errors
.map { |error| error.options[:type_de_champ] }
.map { |tdc| tag.li(tdc_anchor(tdc)) }
.then { |lis| tag.ul(lis.reduce(&:+)) }
end
def tdc_anchor(tdc)
tag.a(tdc.libelle, href: champs_admin_procedure_path(@revision.procedure_id, anchor: dom_id(tdc.stable_self, :conditions)), data: { turbo: false })
end
end

View file

@ -0,0 +1,5 @@
fr:
fix:
one: 'Corrigez le champ suivant :'
other: 'Corrigez les champs suivants :'

View file

@ -0,0 +1,7 @@
#errors-summary
- if @revision.invalid?
.card.warning
.card-title La logique conditionnelle est devenue invalide
%p.mb-2= t('.fix', count: @revision.errors.count)
= error_message

View file

@ -38,6 +38,9 @@
%span.icon.archive
Clore
.container
= render TypesDeChampEditor::ErrorsSummary.new(revision: @procedure.draft_revision)
- if @procedure.draft_changed?
.container
.card.featured

View file

@ -1,3 +1,5 @@
= turbo_stream.replace 'errors-summary', render(TypesDeChampEditor::ErrorsSummary.new(revision: @procedure.draft_revision))
- if @destroyed.present?
= turbo_stream.remove dom_id(@destroyed, :type_de_champ_editor)