Merge pull request #7708 from betagouv/add_errors_summary_component

ajoute un résumé des erreurs présentes dans l'éditeur de champ
This commit is contained in:
LeSim 2022-09-01 15:13:49 +02:00 committed by GitHub
commit e521e9f376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 27 deletions

View file

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

@ -4,6 +4,7 @@
metadatas: ["Créée le #{@procedure.created_at.strftime('%d/%m/%Y')} - n° #{@procedure.id}", "#{@procedure.close? ? "Close le #{@procedure.closed_at.strftime('%d/%m/%Y')}" : @procedure.locked? ? "Publiée - #{procedure_lien(@procedure)}" : "Brouillon"}"] } metadatas: ["Créée le #{@procedure.created_at.strftime('%d/%m/%Y')} - n° #{@procedure.id}", "#{@procedure.close? ? "Close le #{@procedure.closed_at.strftime('%d/%m/%Y')}" : @procedure.locked? ? "Publiée - #{procedure_lien(@procedure)}" : "Brouillon"}"] }
.container.procedure-admin-container .container.procedure-admin-container
- if @procedure.draft_revision.valid?
- if !@procedure.brouillon? - if !@procedure.brouillon?
= link_to admin_procedure_archives_path(@procedure), class: 'button', id: "archive-procedure" do = link_to admin_procedure_archives_path(@procedure), class: 'button', id: "archive-procedure" do
%span.icon.download %span.icon.download
@ -38,7 +39,10 @@
%span.icon.archive %span.icon.archive
Clore Clore
- if @procedure.draft_changed? .container
= render TypesDeChampEditor::ErrorsSummary.new(revision: @procedure.draft_revision)
- if @procedure.draft_changed? && @procedure.draft_revision.valid?
.container .container
.card.featured .card.featured
.card-title .card-title

View file

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