From 12d23f1498208fc12e01b9447aac84a38a30798f Mon Sep 17 00:00:00 2001 From: mfo Date: Wed, 5 Jun 2024 17:08:00 +0200 Subject: [PATCH] feat(Procedure::Cards::IneligibleDossier): add an ineligibilite dossier card to procedure dashboard --- .../conditions/conditions_component.rb | 2 +- .../card/ineligibilite_dossier_component.rb | 19 ++++++++++++++ .../ineligibilite_dossier_component.fr.yml | 8 ++++++ .../ineligibilite_dossier_component.html.haml | 15 +++++++++++ app/models/procedure_revision.rb | 4 +++ app/models/type_de_champ.rb | 4 +++ .../administrateurs/procedures/show.html.haml | 1 + .../card/ineligibilite_dossier_component.rb | 25 +++++++++++++++++++ 8 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 app/components/procedure/card/ineligibilite_dossier_component.rb create mode 100644 app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.fr.yml create mode 100644 app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.html.haml create mode 100644 spec/components/procedures/card/ineligibilite_dossier_component.rb diff --git a/app/components/conditions/conditions_component.rb b/app/components/conditions/conditions_component.rb index 01f081a85..8817a1336 100644 --- a/app/components/conditions/conditions_component.rb +++ b/app/components/conditions/conditions_component.rb @@ -61,7 +61,7 @@ class Conditions::ConditionsComponent < ApplicationComponent def available_targets_for_select @source_tdcs - .filter { |tdc| ChampValue::MANAGED_TYPE_DE_CHAMP.values.include?(tdc.type_champ) } + .filter(&:conditionable?) .map { |tdc| [tdc.libelle, champ_value(tdc.stable_id).to_json] } end diff --git a/app/components/procedure/card/ineligibilite_dossier_component.rb b/app/components/procedure/card/ineligibilite_dossier_component.rb new file mode 100644 index 000000000..d69e06623 --- /dev/null +++ b/app/components/procedure/card/ineligibilite_dossier_component.rb @@ -0,0 +1,19 @@ +class Procedure::Card::IneligibiliteDossierComponent < ApplicationComponent + def initialize(procedure:) + @procedure = procedure + end + + def ready? + @procedure.draft_revision + .conditionable_types_de_champ + .present? + end + + def error? + !@procedure.draft_revision.validate(:ineligibilite_rules_editor) + end + + def completed? + @procedure.draft_revision.ineligibilite_enabled + end +end diff --git a/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.fr.yml b/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.fr.yml new file mode 100644 index 000000000..d65f0d535 --- /dev/null +++ b/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.fr.yml @@ -0,0 +1,8 @@ +--- +fr: + title: Inéligibilité des dossiers + state: + pending: Champs à configurer + ready: À configurer + completed: Activé + subtitle: Gérez vos critères d’inéligibilité en fonction des champs du formulaire diff --git a/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.html.haml b/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.html.haml new file mode 100644 index 000000000..e82e64fad --- /dev/null +++ b/app/components/procedure/card/ineligibilite_dossier_component/ineligibilite_dossier_component.html.haml @@ -0,0 +1,15 @@ +.fr-col-6.fr-col-md-4.fr-col-lg-3 + = link_to edit_admin_procedure_ineligibilite_rules_path(@procedure), class: 'fr-tile fr-enlarge-link' do + .fr-tile__body.flex.column.align-center.justify-between + - if !ready? + %p.fr-badge.fr-badge--warning= t('.state.pending') + - elsif error? + %p.fr-badge.fr-badge--error À modifier + - elsif !completed? + %p.fr-badge.fr-badge--info= t('.state.ready') + - else + %p.fr-badge.fr-badge--success= t('.state.completed') + %div + %h3.fr-h6.fr-mt-10v= t('.title') + %p.fr-tile-subtitle= t('.subtitle') + %p.fr-btn.fr-btn--tertiary= t('views.shared.actions.edit') diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index fef3516d5..157b4dd67 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -251,6 +251,10 @@ class ProcedureRevision < ApplicationRecord types_de_champ_public.filter(&:routable?) end + def conditionable_types_de_champ + types_de_champ_for(scope: :public).filter(&:conditionable?) + end + private def compute_estimated_fill_duration diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 10e415c05..cf2c321d8 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -657,6 +657,10 @@ class TypeDeChamp < ApplicationRecord type_champ.in?(ROUTABLE_TYPES) end + def conditionable? + Logic::ChampValue::MANAGED_TYPE_DE_CHAMP.values.include?(type_champ) + end + def invalid_regexp? self.errors.delete(:expression_reguliere) self.errors.delete(:expression_reguliere_exemple_text) diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 345eb2824..4d63d909b 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -71,6 +71,7 @@ = render Procedure::Card::PresentationComponent.new(procedure: @procedure) = render Procedure::Card::ZonesComponent.new(procedure: @procedure) if Rails.application.config.ds_zonage_enabled = render Procedure::Card::ChampsComponent.new(procedure: @procedure) + = render Procedure::Card::IneligibiliteDossierComponent.new(procedure: @procedure) = render Procedure::Card::ServiceComponent.new(procedure: @procedure, administrateur: current_administrateur) = render Procedure::Card::AdministrateursComponent.new(procedure: @procedure) = render Procedure::Card::InstructeursComponent.new(procedure: @procedure) diff --git a/spec/components/procedures/card/ineligibilite_dossier_component.rb b/spec/components/procedures/card/ineligibilite_dossier_component.rb new file mode 100644 index 000000000..433b59155 --- /dev/null +++ b/spec/components/procedures/card/ineligibilite_dossier_component.rb @@ -0,0 +1,25 @@ +describe Procedure::Card::IneligibiliteDossierComponent, type: :component do + describe 'render' do + subject do + render_inline(described_class.new(procedure: procedure)) + end + + context 'when none of types_de_champ_public supports conditional' do + let(:procedure) { create(:procedure, types_de_champ_public: []) } + + it 'render missing setup' do + subject + expect(page).to have_text('Champs manquant') + end + end + + context 'when at least one of types_de_champ_public support conditional' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) } + + it 'render the template' do + subject + expect(page).to have_text('À configurer') + end + end + end +end