From f4b465a03f3cc1c942a6adff7181ca895bf8c02c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 28 Jun 2022 12:14:32 +0200 Subject: [PATCH] add errors_summary component --- .../editor_component.html.haml | 1 + .../types_de_champ_editor/errors_summary.rb | 18 ++++++++++++++++++ .../errors_summary/errors_summary.fr.yml | 5 +++++ .../errors_summary/errors_summary.html.haml | 7 +++++++ .../administrateurs/procedures/show.html.haml | 3 +++ .../types_de_champ/_insert.turbo_stream.haml | 2 ++ 6 files changed, 36 insertions(+) create mode 100644 app/components/types_de_champ_editor/errors_summary.rb create mode 100644 app/components/types_de_champ_editor/errors_summary/errors_summary.fr.yml create mode 100644 app/components/types_de_champ_editor/errors_summary/errors_summary.html.haml diff --git a/app/components/types_de_champ_editor/editor_component/editor_component.html.haml b/app/components/types_de_champ_editor/editor_component/editor_component.html.haml index 7ae3d98da..0baff9f5b 100644 --- a/app/components/types_de_champ_editor/editor_component/editor_component.html.haml +++ b/app/components/types_de_champ_editor/editor_component/editor_component.html.haml @@ -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?) diff --git a/app/components/types_de_champ_editor/errors_summary.rb b/app/components/types_de_champ_editor/errors_summary.rb new file mode 100644 index 000000000..aa71d9e67 --- /dev/null +++ b/app/components/types_de_champ_editor/errors_summary.rb @@ -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 diff --git a/app/components/types_de_champ_editor/errors_summary/errors_summary.fr.yml b/app/components/types_de_champ_editor/errors_summary/errors_summary.fr.yml new file mode 100644 index 000000000..801c1d862 --- /dev/null +++ b/app/components/types_de_champ_editor/errors_summary/errors_summary.fr.yml @@ -0,0 +1,5 @@ +fr: + fix: + one: 'Corrigez le champ suivant :' + other: 'Corrigez les champs suivants :' + diff --git a/app/components/types_de_champ_editor/errors_summary/errors_summary.html.haml b/app/components/types_de_champ_editor/errors_summary/errors_summary.html.haml new file mode 100644 index 000000000..2f265d94b --- /dev/null +++ b/app/components/types_de_champ_editor/errors_summary/errors_summary.html.haml @@ -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 diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 7b6b32221..aef5d1f38 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -38,6 +38,9 @@ %span.icon.archive Clore +.container + = render TypesDeChampEditor::ErrorsSummary.new(revision: @procedure.draft_revision) + - if @procedure.draft_changed? .container .card.featured diff --git a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml index 8e9643849..fc235a715 100644 --- a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml @@ -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)