Skip to content

Commit

Permalink
feat(TransitionsRules): add custom message and refine ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed May 15, 2024
1 parent c6a78e4 commit ec5b043
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 32 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/02_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@

.element-warning {
border: 4px solid var(--border-plain-warning);
border-radius: 5px;
}

// Labels that we only want for screen readers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
%div{ id: dom_id(@revision, :transitions_rules) }
= form_tag admin_procedure_transitions_rules_path(@revision.procedure_id), method: :patch, data: { turbo: true, controller: 'autosave' }, class: 'form width-100' do
- if @condition.present?
.conditionnel.fr-mt-3w.width-100
%table.condition-table.mt-2{ class: class_names('element-warning' => pending_changes?) }
%thead
%tr
%th.far-left
%th.target Champ Cible
%th.operator Opérateur
%th.value Valeur
%th.delete-column
%tbody
- rows.each.with_index do |(targeted_champ, operator_name, value), row_index|
%tr
%td.far-left= far_left_tag(row_index)
%td.target= left_operand_tag(targeted_champ, row_index)
%td.operator= operator_tag(operator_name, targeted_champ, row_index)
%td.value= right_operand_tag(targeted_champ, value, row_index, operator_name)
%td.delete-column= delete_condition_tag(row_index)
%div{ class: class_names('element-warning' => pending_changes?, 'fr-p-3w': pending_changes?) }
%h2.fr-h2
Gestion des critères d'eligibilité

= render Procedure::PendingRepublishComponent.new(procedure: @revision.procedure, render_if: pending_changes?)
%p.fr-mt-3w= add_condition_tag
= form_tag admin_procedure_transitions_rules_path(@revision.procedure_id), method: :patch, data: { turbo: true, controller: 'autosave' }, class: 'form width-100' do
- if @condition.present?
.conditionnel.fr-mt-3w.width-100
%table.condition-table.mt-2
%thead
%tr
%th.far-left
%th.target Champ Cible
%th.operator Opérateur
%th.value Valeur
%th.delete-column
%tbody
- rows.each.with_index do |(targeted_champ, operator_name, value), row_index|
%tr
%td.far-left= far_left_tag(row_index)
%td.target= left_operand_tag(targeted_champ, row_index)
%td.operator= operator_tag(operator_name, targeted_champ, row_index)
%td.value= right_operand_tag(targeted_champ, value, row_index, operator_name)
%td.delete-column= delete_condition_tag(row_index)
%tfoot
%tr
%td{ colspan: 5 }= add_condition_tag

- else
= tag.button "Activer l'éligibilité des dossiers", formaction: add_condition_path, formvalidate: true, class: 'fr-btn fr-btn--primary'

- else
= tag.button "Activer l'éligibilité des dossiers", formaction: add_condition_path, formvalidate: true, class: 'fr-btn fr-btn--primary'
- if @condition.present?
%h2.fr-h2.fr-mt-3w Message d'inéligibilité
= form_for(@revision, url: change_message_admin_procedure_transitions_rules_path(@revision.procedure_id)) do |f|
= render Dsfr::InputComponent.new(form: f, attribute: :dossier_ineligble_message, input_type: :text_area, opts: {rows: 5})
%p.fr-mb-0= f.submit "Modifier le message d'inéligibilité", class: 'fr-btn'

= render Procedure::PendingRepublishComponent.new(procedure: @revision.procedure, render_if: pending_changes?)
- if @condition.present?
= button_to 'Désactiver l’éligibilité des dossiers', delete_all_admin_procedure_transitions_rules_path(@revision.procedure), method: :delete, class: 'fr-btn'
%h2.fr-h2.fr-mt-3w Désactivation des critères d'eligibilité
= button_to 'Désactiver l’éligibilité des dossiers', delete_all_admin_procedure_transitions_rules_path(@revision.procedure), method: :delete, class: 'fr-btn fr-btn--tertiary'
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def render?
transitions_rules_computable? && !can_passer_en_construction?
end

def error_message
@dossier.revision.dossier_ineligble_message || t('.modal.body', procedure_libelle: @dossier.procedure.libelle)
end

private

def transitions_rules_computable?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
%h1#fr-modal-title-modal-1.fr-modal__title
%span.fr-icon-arrow-right-line.fr-icon--lg>
= t('.modal.title')
%p= t('.modal.body', procedure_libelle: @dossier.procedure.libelle)
%p= error_message
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
fr:
pending_republish_html: |
Cette modification ne sera appliquée qu'à la prochaine publication. Vous pouvez vérifier puis publier les modifications sur l'écran de <a href="%{href}">gestion de la démarche</a>
Ces modifications ne seront appliquées qu'à la prochaine publication. Vous pouvez vérifier puis publier les modifications sur l'écran de <a href="%{href}">gestion de la démarche</a>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= render Dsfr::AlertComponent.new(state: :warning, extra_class_names: 'fr-mt-3w') do |c|
= render Dsfr::AlertComponent.new(state: :warning) do |c|
- c.with_body do
= t('.pending_republish_html', href: admin_procedure_path(@procedure.id))
5 changes: 5 additions & 0 deletions app/components/procedure/revision_changes_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Procedure::RevisionChangesComponent < ApplicationComponent
def initialize(new_revision:, previous_revision:)
@previous_revision = previous_revision
@new_revision = new_revision

@tdc_changes = previous_revision.compare_types_de_champ(new_revision)
@public_move_changes, @private_move_changes = @tdc_changes.filter { _1.op == :move }.partition { !_1.private? }
Expand All @@ -9,6 +10,10 @@ def initialize(new_revision:, previous_revision:)
@transition_rules_changes = previous_revision.compare_transitions_rules(new_revision)
end

def dossier_ineligble_message_changed?
@new_revision.dossier_ineligble_message != @previous_revision.dossier_ineligble_message
end

private

def total_dossiers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fr:
remove_expression_reguliere_error_message: Le message d’erreur de l’expression régulière de l’annotation privée « %{label} » a été supprimé.
update_expression_reguliere_error_message: Le message d’erreur de l’expression régulière de l’annotation privée « %{label} » a été modifiée. Le nouveau message est « %{to} ».
transitions_rules:
add: La condition d’elligibilité « %{new_condition} » a été ajoutée.
remove: La condition d’elligibilité « %{previous_condition} » a été supprimée
update: La conditon d’elligibilité « %{previous_condition} » a été changée pour « %{new_condition} »
add: La condition d’eligibilité « %{new_condition} » a été ajoutée.
remove: La condition d’eligibilité « %{previous_condition} » a été supprimée
update: La conditon d’eligibilité « %{previous_condition} » a été changée pour « %{new_condition} »
dossier_ineligble_message_changed: "Le message d’eligibilité a été changé : « %{new_dossier_ineligble_message} »"
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,7 @@
- @transition_rules_changes.each do |change|
- list.with_item do
= t(".transitions_rules.#{change.op}", previous_condition: change.previous_condition, new_condition: change.new_condition)

- if dossier_ineligble_message_changed?
- list.with_item do
= t('.transitions_rules.dossier_ineligble_message_changed', new_dossier_ineligble_message: @new_revision.dossier_ineligble_message)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class TransitionsRulesController < AdministrateurController
def edit
end

def change_message
if revision.update(params.require(:procedure_revision).permit(:dossier_ineligble_message))
redirect_to edit_admin_procedure_transitions_rules_path(@procedure)
else
render :edit
end
end

def add_row
condition = Logic.add_empty_condition_to(revision.transitions_rules)
revision.update!(transitions_rules: condition)
Expand Down
10 changes: 10 additions & 0 deletions app/models/procedure_revision_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,14 @@ def op = :remove
class ChangeTransitionsRule < TransitionsRulesChange
def op = :update
end

class ChangeDossierIneligbleMessage
attr_reader :previous_revision, :new_revision
def initialize(previous_revision, new_revision)
@previous_revision = previous_revision
@new_revision = new_revision
end

def op = :update
end
end
7 changes: 7 additions & 0 deletions config/locales/models/procedure_revision/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fr:
activerecord:
attributes:
procedure_revision:
dossier_ineligble_message: Message d'inéligibilité
hints:
dossier_ineligble_message: "Ce message sera affiché à l'usager si son dossier ne correspond pas à vos critères d'éligibilité"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@
patch :add_row, on: :member
delete :delete_row, on: :member
delete :delete_all, on: :member
patch :change_message
end

patch :update_defaut_groupe_instructeur, controller: 'routing_rules', as: :update_defaut_groupe_instructeur
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDossierIneligbleMessageToProcedureRevisions < ActiveRecord::Migration[7.0]
def change
add_column :procedure_revisions, :dossier_ineligble_message, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_04_17_053843) do
ActiveRecord::Schema[7.0].define(version: 2024_05_14_075727) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_buffercache"
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -848,6 +848,7 @@

create_table "procedure_revisions", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.text "dossier_ineligble_message"
t.bigint "dossier_submitted_message_id"
t.bigint "procedure_id", null: false
t.datetime "published_at", precision: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,15 @@
end
end
end

describe 'change_message' do
let(:dossier_ineligble_message) { 'panpan' }
before { sign_in(admin.user) }
it 'works' do
expect { patch :change_message, params: { procedure_id: procedure.id, procedure_revision: { dossier_ineligble_message: } } }
.to change { procedure.reload.draft_revision.dossier_ineligble_message }
.from(nil).to(dossier_ineligble_message)
expect(response).to redirect_to(edit_admin_procedure_transitions_rules_path(procedure))
end
end
end

0 comments on commit ec5b043

Please sign in to comment.