Merge pull request #10636 from tchak/improuve-dynamic-routage

refactor(routing_roules): simplify refresh conditions
This commit is contained in:
Paul Chavard 2024-07-25 08:29:27 +00:00 committed by GitHub
commit 2a225013ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View file

@ -556,18 +556,22 @@ module Users
def update_dossier_and_compute_errors def update_dossier_and_compute_errors
@dossier.update_champs_attributes(champs_public_attributes_params, :public, updated_by: current_user.email) @dossier.update_champs_attributes(champs_public_attributes_params, :public, updated_by: current_user.email)
if @dossier.champs.any?(&:changed_for_autosave?) updated_champs = @dossier.champs.filter(&:changed_for_autosave?)
if updated_champs.present?
@dossier.last_champ_updated_at = Time.zone.now @dossier.last_champ_updated_at = Time.zone.now
if @dossier.champs_public.any? { _1.changed_for_autosave? && _1.used_by_routing_rules? }
RoutingEngine.compute(@dossier)
end
end end
# We save the dossier without validating fields, and if it is successful and the client # We save the dossier without validating fields, and if it is successful and the client
# requests it, we ask for field validation errors. # requests it, we ask for field validation errors.
if @dossier.save && params[:validate].present? if @dossier.save
@dossier.valid?(:champs_public_value) if updated_champs.any?(&:used_by_routing_rules?)
@update_contact_information = true
RoutingEngine.compute(@dossier)
end
if params[:validate].present?
@dossier.valid?(:champs_public_value)
end
end end
@dossier.errors @dossier.errors

View file

@ -5,5 +5,6 @@
= turbo_stream.append('contenu', render(Dossiers::InvalidIneligibiliteRulesComponent.new(dossier: @dossier))) = turbo_stream.append('contenu', render(Dossiers::InvalidIneligibiliteRulesComponent.new(dossier: @dossier)))
- else @ineligibilite_rules_is_computable - else @ineligibilite_rules_is_computable
= turbo_stream.remove(dom_id(@dossier, :ineligibilite_rules_broken)) = turbo_stream.remove(dom_id(@dossier, :ineligibilite_rules_broken))
- if @dossier.champs.any? { _1.used_by_routing_rules? && params[:dossier][:champs_public_attributes].key?(_1.stable_id.to_s) }
- if @update_contact_information
= turbo_stream.update "contact_information", partial: 'shared/dossiers/update_contact_information', locals: { dossier: @dossier, procedure: @procedure } = turbo_stream.update "contact_information", partial: 'shared/dossiers/update_contact_information', locals: { dossier: @dossier, procedure: @procedure }