feat(prefill): add possible values (#8299)

* update layout in order to show possible values

* filter out non fillable types de champ
This commit is contained in:
Sébastien Carceles 2022-12-20 11:04:42 +01:00 committed by GitHub
parent d9bc44ac8b
commit dd0a05c1d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 130 additions and 60 deletions

View file

@ -0,0 +1,9 @@
.prefill-description {
table {
table-layout: fixed;
th {
width: 25%;
}
}
}

View file

@ -15,7 +15,7 @@ class PrefillDescription < SimpleDelegator
end end
def types_de_champ def types_de_champ
active_revision.types_de_champ_public active_revision.types_de_champ_public.fillable
end end
def include?(type_de_champ_id) def include?(type_de_champ_id)
@ -37,10 +37,14 @@ class PrefillDescription < SimpleDelegator
private private
def prefilled_champs_for_link def prefilled_champs_for_link
prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id}", type_de_champ.libelle] }.to_h prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id}", example_value(type_de_champ)] }.to_h
end end
def prefilled_champs_for_query def prefilled_champs_for_query
prefilled_champs.map { |type_de_champ| "\"champ_#{type_de_champ.to_typed_id}\": \"#{type_de_champ.libelle}\"" } .join(', ') prefilled_champs.map { |type_de_champ| "\"champ_#{type_de_champ.to_typed_id}\": \"#{example_value(type_de_champ)}\"" } .join(', ')
end
def example_value(type_de_champ)
I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
end end
end end

View file

@ -1,44 +1,44 @@
= turbo_frame_tag "#{dom_id(@prefill_description)}_types_de_champs" do = turbo_frame_tag "#{dom_id(@prefill_description)}_types_de_champs" do
.card .fr-grid-row.fr-grid-row--gutters.fr-py-5w
.card-title - prefill_description.types_de_champ.each do |type_de_champ|
%span.icon.edit .fr-col-md-6.fr-col-12
= t("views.prefill_descriptions.edit.champs_title") .card
.card-title.flex.justify-between.align-center
= type_de_champ.libelle
= form_for prefill_description, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f|
- if prefill_description.include?(type_de_champ.id)
- (prefill_description.selected_type_de_champ_ids - [type_de_champ.id.to_s]).each do |id|
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true
= f.submit t("views.prefill_descriptions.edit.champ_remove"), class: 'fr-btn fr-btn--secondary fr-btn--md'
- elsif type_de_champ.prefillable?
- (prefill_description.selected_type_de_champ_ids + [type_de_champ.id.to_s]).each do |id|
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true
= f.submit t("views.prefill_descriptions.edit.champ_add"), class: 'fr-btn fr-btn--md'
- else
%button.fr-btn.fr-btn--secondary{ disabled: true }
= t("views.prefill_descriptions.edit.champ_unavailable")
%table.table.hoverable = type_de_champ.description
%thead
%tr
%th
= t("views.prefill_descriptions.edit.champ_id")
%th
= t("views.prefill_descriptions.edit.champ_type")
%th
= t("views.prefill_descriptions.edit.champ_libelle")
%th
= t("views.prefill_descriptions.edit.champ_description")
%th
= t("views.prefill_descriptions.edit.champ_prefill")
%tbody %table.table.vertical
- prefill_description.types_de_champ.each do |type_de_champ| %tbody
%tr %tr
%td %th
= type_de_champ.to_typed_id = t("views.prefill_descriptions.edit.champ_id")
%td %td
= t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}") = type_de_champ.to_typed_id
%td %tr
= type_de_champ.libelle %th
%td = t("views.prefill_descriptions.edit.champ_type")
= type_de_champ.description %td
%td.text-center = t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}")
= form_for prefill_description, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f| %tr
- if prefill_description.include?(type_de_champ.id) %th
- (prefill_description.selected_type_de_champ_ids - [type_de_champ.id.to_s]).each do |id| = t("views.prefill_descriptions.edit.possible_values.title")
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true %td
= f.submit t("views.prefill_descriptions.edit.champ_remove"), class: 'fr-btn fr-btn--secondary fr-btn--md' = t("views.prefill_descriptions.edit.possible_values.#{type_de_champ.type_champ}")
- elsif type_de_champ.prefillable? %tr
- (prefill_description.selected_type_de_champ_ids + [type_de_champ.id.to_s]).each do |id| %th
= f.hidden_field :selected_type_de_champ_ids, value: id, multiple: true = t("views.prefill_descriptions.edit.examples.title")
= f.submit t("views.prefill_descriptions.edit.champ_add"), class: 'fr-btn fr-btn--md' %td
- else = t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
%button.fr-btn.fr-btn--secondary{ disabled: true }
= t("views.prefill_descriptions.edit.champ_unavailable")

View file

@ -3,7 +3,7 @@
- content_for :footer do - content_for :footer do
= render partial: "root/footer" = render partial: "root/footer"
.container .container.prefill-description
.two-columns.procedure-context .two-columns.procedure-context
.columns-container .columns-container
.column.procedure-preview .column.procedure-preview

View file

@ -105,15 +105,33 @@ en:
edit: edit:
intro_html: "You'd like to allow your users to <strong>create a prefilled file</strong>, with data you already have, for the procedure « %{libelle} »." intro_html: "You'd like to allow your users to <strong>create a prefilled file</strong>, with data you already have, for the procedure « %{libelle} »."
info: Add the fields you want to prefill, thanks to the table below. Once it's over, copy the prefill link, replace the values and share the link. info: Add the fields you want to prefill, thanks to the table below. Once it's over, copy the prefill link, replace the values and share the link.
champs_title: Fields
champ_id: ID champ_id: ID
champ_type: Type champ_type: Type
champ_libelle: Label
champ_description: Description
champ_prefill: Prefillable
champ_add: Add champ_add: Add
champ_remove: Remove champ_remove: Remove
champ_unavailable: Unavailable champ_unavailable: Unavailable
possible_values:
title: Values
text: A short text
textarea: A long text
decimal_number: A decimal number
integer_number: An integer number
email: An email address
phone: A phone number
iban: An Iban number
yes_no: '"true" for Yes, "false" pour No'
checkbox: '"on" to check, "off" to uncheck'
examples:
title: Example
text: Short text
textarea: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
decimal_number: 3.14
integer_number: 42
email: personne@fournisseur.fr
phone: 0612345678
iban: FR7611315000011234567890138
yes_no: "true"
checkbox: "on"
prefill_link_title: Prefill link (GET) prefill_link_title: Prefill link (GET)
prefill_link_info: Use the button to copy the link, then remplace the values with your data. prefill_link_info: Use the button to copy the link, then remplace the values with your data.
prefill_link_too_long: Warning, the prefill link is too long and may not work on all browsers. prefill_link_too_long: Warning, the prefill link is too long and may not work on all browsers.

View file

@ -95,15 +95,33 @@ fr:
edit: edit:
intro_html: "Vous souhaitez permettre à vos usager·ères la <strong>création d'un dossier prérempli</strong>, à partir de données dont vous disposez déjà, pour la démarche « %{libelle} »." intro_html: "Vous souhaitez permettre à vos usager·ères la <strong>création d'un dossier prérempli</strong>, à partir de données dont vous disposez déjà, pour la démarche « %{libelle} »."
info: Pour cela, ajoutez les champs que vous souhaitez préremplir, grâce au tableau ci-dessous. Lorsque vous avez terminé, il ne vous reste plus qu'à copier le lien de préremplissage, à remplacer les valeurs et à le partager. info: Pour cela, ajoutez les champs que vous souhaitez préremplir, grâce au tableau ci-dessous. Lorsque vous avez terminé, il ne vous reste plus qu'à copier le lien de préremplissage, à remplacer les valeurs et à le partager.
champs_title: Champs de la démarche
champ_id: ID champ_id: ID
champ_type: Type champ_type: Type
champ_libelle: Libellé
champ_description: Description
champ_prefill: Préremplissable
champ_add: Ajouter champ_add: Ajouter
champ_remove: Retirer champ_remove: Retirer
champ_unavailable: Indisponible champ_unavailable: Indisponible
possible_values:
title: Valeurs
text: Un texte court
textarea: Un texte long
decimal_number: Un nombre décimal
integer_number: Un nombre entier
email: Une adresse email
phone: Un numéro de téléphone
iban: Un numéro Iban
yes_no: '"true" pour Oui, "false" pour Non'
checkbox: '"on" pour coché, "off" pour décoché'
examples:
title: Exemple
text: Texte court
textarea: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
decimal_number: 3.14
integer_number: 42
email: personne@fournisseur.fr
phone: 0612345678
iban: FR7611315000011234567890138
yes_no: "true"
checkbox: "on"
prefill_link_title: Lien de préremplissage (GET) prefill_link_title: Lien de préremplissage (GET)
prefill_link_info: Copiez le lien grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez. prefill_link_info: Copiez le lien grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
prefill_link_too_long: Attention, ce lien de préremplissage est trop long et risque de ne pas fonctionner sur certains navigateurs. prefill_link_too_long: Attention, ce lien de préremplissage est trop long et risque de ne pas fonctionner sur certains navigateurs.

View file

@ -68,8 +68,14 @@ describe PrefillDescriptionsController, type: :controller do
it "includes the prefill URL" do it "includes the prefill URL" do
expect(response.body).to include(commencer_path(path: procedure.path)) expect(response.body).to include(commencer_path(path: procedure.path))
expect(response.body).to include({ "champ_#{type_de_champ.to_typed_id}" => type_de_champ.libelle }.to_query) expect(response.body).to include(
expect(response.body).to include({ "champ_#{type_de_champ_to_add.to_typed_id}" => type_de_champ_to_add.libelle }.to_query) {
"champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
}.to_query
)
expect(response.body).to include({
"champ_#{type_de_champ_to_add.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
}.to_query)
end end
end end
@ -81,8 +87,12 @@ describe PrefillDescriptionsController, type: :controller do
it "includes the prefill URL" do it "includes the prefill URL" do
expect(response.body).to include(commencer_path(path: procedure.path)) expect(response.body).to include(commencer_path(path: procedure.path))
expect(response.body).to include({ "champ_#{type_de_champ.to_typed_id}" => type_de_champ.libelle }.to_query) expect(response.body).to include({
expect(response.body).not_to include({ "champ_#{type_de_champ_to_remove.to_typed_id}" => type_de_champ_to_remove.libelle }.to_query) "champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
}.to_query)
expect(response.body).not_to include({
"champ_#{type_de_champ_to_remove.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
}.to_query)
end end
end end

View file

@ -21,6 +21,17 @@ RSpec.describe PrefillDescription, type: :model do
let(:prefill_description) { described_class.new(procedure) } let(:prefill_description) { described_class.new(procedure) }
it { expect(prefill_description.types_de_champ).to match([type_de_champ]) } it { expect(prefill_description.types_de_champ).to match([type_de_champ]) }
shared_examples "filters out non fillable types de champ" do |type_de_champ_name|
context "when the procedure has a #{type_de_champ_name} champ" do
let(:non_fillable_type_de_champ) { create(type_de_champ_name, procedure: procedure) }
it { expect(prefill_description.types_de_champ).not_to include(non_fillable_type_de_champ) }
end
end
it_behaves_like "filters out non fillable types de champ", :type_de_champ_header_section
it_behaves_like "filters out non fillable types de champ", :type_de_champ_explication
end end
describe '#include?' do describe '#include?' do
@ -48,7 +59,7 @@ RSpec.describe PrefillDescription, type: :model do
before { prefill_description.update(selected_type_de_champ_ids: create_list(:type_de_champ_text, type_de_champs_count, procedure: procedure).map(&:id)) } before { prefill_description.update(selected_type_de_champ_ids: create_list(:type_de_champ_text, type_de_champs_count, procedure: procedure).map(&:id)) }
context 'when the prefill link is too long' do context 'when the prefill link is too long' do
let(:type_de_champs_count) { 60 } let(:type_de_champs_count) { 65 }
it { expect(too_long).to eq(true) } it { expect(too_long).to eq(true) }
end end
@ -71,7 +82,7 @@ RSpec.describe PrefillDescription, type: :model do
expect(prefill_description.prefill_link).to eq( expect(prefill_description.prefill_link).to eq(
commencer_url( commencer_url(
path: procedure.path, path: procedure.path,
"champ_#{type_de_champ.to_typed_id}" => type_de_champ.libelle "champ_#{type_de_champ.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
) )
) )
end end

View file

@ -246,8 +246,8 @@ describe TypeDeChamp do
it_behaves_like "a non-prefillable type de champ", :type_de_champ_number it_behaves_like "a non-prefillable type de champ", :type_de_champ_number
it_behaves_like "a non-prefillable type de champ", :type_de_champ_communes it_behaves_like "a non-prefillable type de champ", :type_de_champ_communes
it_behaves_like "a non-prefillable type de champ", :type_de_champ_dossier_link it_behaves_like "a non-prefillable type de champ", :type_de_champ_dossier_link
it_behaves_like "a non-prefillable type de champ", :type_de_champ_titre_identite
it_behaves_like "a non-prefillable type de champ", :type_de_champ_checkbox it_behaves_like "a non-prefillable type de champ", :type_de_champ_checkbox
it_behaves_like "a non-prefillable type de champ", :type_de_champ_titre_identite
it_behaves_like "a non-prefillable type de champ", :type_de_champ_civilite it_behaves_like "a non-prefillable type de champ", :type_de_champ_civilite
it_behaves_like "a non-prefillable type de champ", :type_de_champ_yes_no it_behaves_like "a non-prefillable type de champ", :type_de_champ_yes_no
it_behaves_like "a non-prefillable type de champ", :type_de_champ_date it_behaves_like "a non-prefillable type de champ", :type_de_champ_date