From 247bb6f8c6a76b61bd6c9cb953e68258385eb483 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 4 Sep 2024 17:32:21 +0200 Subject: [PATCH] refactor(attestation): hide libelle of empty repetitions --- app/assets/stylesheets/attestation.scss | 8 ++++++- .../repetition_presentation.rb | 3 ++- app/services/tiptap_service.rb | 4 ++-- .../repetition_presentation_spec.rb | 23 ++++++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/attestation.scss b/app/assets/stylesheets/attestation.scss index 33cb38c48..7af3840f3 100644 --- a/app/assets/stylesheets/attestation.scss +++ b/app/assets/stylesheets/attestation.scss @@ -181,11 +181,17 @@ .tdc-repetition li { margin-bottom: 5mm; + padding-left: 3mm; dl { display: grid; grid-template-columns: auto 1fr; - gap: 1mm 5mm; + gap: 1mm 10mm; + } + + .invisible { + visibility: hidden; + height: 0; } } } diff --git a/app/models/champ_presentations/repetition_presentation.rb b/app/models/champ_presentations/repetition_presentation.rb index 41bf2c2ad..000f74430 100644 --- a/app/models/champ_presentations/repetition_presentation.rb +++ b/app/models/champ_presentations/repetition_presentation.rb @@ -31,13 +31,14 @@ class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePrese [ { type: 'descriptionTerm', + attrs: champ.blank? ? { class: 'invisible' } : nil, # still render libelle so width & alignment are preserved content: [ { type: 'text', text: champ.libelle } ] - }, + }.compact, { type: 'descriptionDetails', content: [ diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb index ee50bb458..c63ee7f0a 100644 --- a/app/services/tiptap_service.rb +++ b/app/services/tiptap_service.rb @@ -85,8 +85,8 @@ class TiptapService "
  • #{children(content, substitutions, level + 1)}
  • " in type: 'descriptionList', content: "
    #{children(content, substitutions, level + 1)}
    " - in type: 'descriptionTerm', content: - "
    #{children(content, substitutions, level + 1)}
    " + in type: 'descriptionTerm', content:, **rest + "#{children(content, substitutions, level + 1)}" in type: 'descriptionDetails', content: "
    #{children(content, substitutions, level + 1)}
    " in type: 'text', text:, **rest diff --git a/spec/models/champ_presentations/repetition_presentation_spec.rb b/spec/models/champ_presentations/repetition_presentation_spec.rb index de815b327..37c7fec5a 100644 --- a/spec/models/champ_presentations/repetition_presentation_spec.rb +++ b/spec/models/champ_presentations/repetition_presentation_spec.rb @@ -21,6 +21,9 @@ describe ChampPresentations::RepetitionPresentation do nom.update(value: "ruby") stars.update(value: 5) + nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision) + nom.update(value: "js") + nom, stars = dossier.champs[0].add_row(dossier.procedure.active_revision) nom.update(value: "rust") stars.update(value: 4) @@ -37,6 +40,9 @@ describe ChampPresentations::RepetitionPresentation do nom : ruby stars : 5 + nom : js + stars :#{' '} + nom : rust stars : 4 TXT @@ -63,7 +69,22 @@ describe ChampPresentations::RepetitionPresentation do ] } ] - }, { + }, + { + type: "listItem", + content: [ + { + type: "descriptionList", + content: [ + { content: [{ text: "nom", type: "text" }], type: "descriptionTerm" }, + { content: [{ text: "js", type: "text" }], type: "descriptionDetails" }, + { content: [{ text: "stars", type: "text" }], type: "descriptionTerm", attrs: { class: "invisible" } }, + { content: [{ text: "", type: "text" }], type: "descriptionDetails" } + ] + } + ] + }, + { type: "listItem", content: [ {