fix(dossier): do not show repetitions in header sections summary

This commit is contained in:
Paul Chavard 2024-09-20 16:21:12 +02:00
parent 6254b50de9
commit 3429a72f53
No known key found for this signature in database
6 changed files with 83 additions and 7 deletions

View file

@ -7,15 +7,16 @@ class ViewableChamp::HeaderSectionsSummaryComponent < ApplicationComponent
@dossier = dossier @dossier = dossier
@is_private = is_private @is_private = is_private
@header_sections = @dossier.revision @header_sections = if is_private
.types_de_champ_for(scope: @is_private ? :private : :public) dossier.revision.types_de_champ_private
.filter(&:header_section?) else
.map { @dossier.project_champ(_1, nil) } # row_id not needed, do not link to repetiion header_sections dossier.revision.types_de_champ_public
end.filter(&:header_section?)
end end
def render? = header_sections.any? def render? = header_sections.any?
def href(header_section) # used by viewable champs to anchor elements def href(header_section) # used by viewable champs to anchor elements
"##{header_section.input_group_id}" "##{header_section.html_id}"
end end
end end

View file

@ -262,7 +262,7 @@ class Champ < ApplicationRecord
end end
def html_id def html_id
"champ-#{public_id}" type_de_champ.html_id(row_id)
end end
def needs_dossier_id? def needs_dossier_id?

View file

@ -13,7 +13,7 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) } scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) }
scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) } scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) }
delegate :stable_id, :libelle, :description, :type_champ, :mandatory?, :private?, :to_typed_id, to: :type_de_champ delegate :stable_id, :libelle, :description, :type_champ, :header_section?, :mandatory?, :private?, :to_typed_id, to: :type_de_champ
def child? def child?
parent_id.present? parent_id.present?

View file

@ -763,6 +763,10 @@ class TypeDeChamp < ApplicationRecord
end end
end end
def html_id(row_id = nil)
"champ-#{public_id(row_id)}"
end
private private
def populate_stable_id def populate_stable_id

View file

@ -0,0 +1,35 @@
# frozen_string_literal: true
RSpec.describe ViewableChamp::HeaderSectionsSummaryComponent, type: :component do
subject { render_inline(component).to_html }
let(:is_private) { false }
let(:types_de_champ) do
[
{ type: :header_section, level: 1 },
{ type: :text },
{ type: :header_section, level: 2 },
{ type: :repetition, children: [{ type: :text }, { type: :header_section, level: 1 }] },
{ type: :header_section, level: 3 },
{ type: :text }
]
end
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ, types_de_champ_private: types_de_champ) }
let(:dossier) { create(:dossier, procedure:) }
let(:component) { described_class.new(dossier:, is_private:) }
let(:types_de_champ_public) { dossier.revision.types_de_champ_public.filter(&:header_section?) }
let(:types_de_champ_private) { dossier.revision.types_de_champ_private.filter(&:header_section?) }
context 'public' do
it do
types_de_champ_public.each { expect(subject).to have_selector("a[href='##{_1.html_id}']") }
end
end
context 'private' do
let(:is_private) { true }
it do
types_de_champ_private.each { expect(subject).to have_selector("a[href='##{_1.html_id}']") }
end
end
end

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
RSpec.describe TypesDeChampEditor::HeaderSectionsSummaryComponent, type: :component do
include ActionView::RecordIdentifier
subject { render_inline(component).to_html }
let(:is_private) { false }
let(:types_de_champ) do
[
{ type: :header_section, level: 1 },
{ type: :text },
{ type: :header_section, level: 2 },
{ type: :repetition, children: [{ type: :text }, { type: :header_section, level: 1 }] },
{ type: :header_section, level: 3 },
{ type: :text }
]
end
let(:procedure) { create(:procedure, types_de_champ_public: types_de_champ, types_de_champ_private: types_de_champ) }
let(:component) { described_class.new(procedure:, is_private:) }
let(:types_de_champ_public) { procedure.draft_revision.revision_types_de_champ_public.filter(&:header_section?) }
let(:types_de_champ_private) { procedure.draft_revision.revision_types_de_champ_private.filter(&:header_section?) }
context 'public' do
it do
types_de_champ_public.each { expect(subject).to have_selector("a[href='##{dom_id(_1, :type_de_champ_editor)}']") }
end
end
context 'private' do
let(:is_private) { true }
it do
types_de_champ_private.each { expect(subject).to have_selector("a[href='##{dom_id(_1, :type_de_champ_editor)}']") }
end
end
end