Merge pull request #9556 from demarches-simplifiees/fix_conditionnal

Administrateur : correction de l'affichage du bouton "logique conditionnelle" dans l'éditeur de champ
This commit is contained in:
Colin Darie 2023-10-09 11:19:22 +00:00 committed by GitHub
commit e3b05f7e20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 10 deletions

View file

@ -56,13 +56,7 @@ module Administrateurs
def retrieve_coordinate_and_uppers def retrieve_coordinate_and_uppers
@tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id]) @tdc = draft_revision.find_and_ensure_exclusive_use(params[:stable_id])
@coordinate = draft_revision.coordinate_for(@tdc) @coordinate = draft_revision.coordinate_for(@tdc)
@upper_tdcs = @coordinate.upper_coordinates.map(&:type_de_champ)
upper_coordinates = @coordinate.upper_siblings
if @coordinate.child?
upper_coordinates += @coordinate.parent.upper_siblings
end
@upper_tdcs = upper_coordinates.map(&:type_de_champ)
end end
def draft_revision def draft_revision

View file

@ -105,7 +105,7 @@ module Administrateurs
def champ_component_from(coordinate, focused: false, errors: '') def champ_component_from(coordinate, focused: false, errors: '')
TypesDeChampEditor::ChampComponent.new( TypesDeChampEditor::ChampComponent.new(
coordinate:, coordinate:,
upper_coordinates: coordinate.upper_siblings, upper_coordinates: coordinate.upper_coordinates,
focused: focused, focused: focused,
errors: errors:
) )

View file

@ -39,8 +39,14 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
end end
end end
def upper_siblings def upper_coordinates
siblings.filter { |s| s.position < position } upper = siblings.filter { |s| s.position < position }
if child?
upper += parent.upper_coordinates
end
upper
end end
def siblings_starting_at(offset) def siblings_starting_at(offset)

View file

@ -0,0 +1,27 @@
describe ProcedureRevisionTypeDeChamp do
describe '#upper_coordinates' do
context 'when the coordinate is in a bloc bellow another coordinate' do
let(:procedure) do
create(:procedure,
types_de_champ_public: [
{ libelle: 'l1' },
{
type: :repetition, children: [
{ libelle: 'l2.1' },
{ libelle: 'l2.2' }
]
}
])
end
let(:l2_2) do
procedure
.draft_revision
.revision_types_de_champ.joins(:type_de_champ)
.find_by(type_de_champ: { libelle: 'l2.2' })
end
it { expect(l2_2.upper_coordinates.map(&:libelle)).to match_array(["l1", "l2.1"]) }
end
end
end