From 8c08d0295bda3f87b6b365995470c8f05edd9a8c Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 12 Jul 2022 11:09:04 +0200 Subject: [PATCH 1/2] Revert "feat(champ): customizable placeholders for text & textarea champs" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9e26ee932e0886f1f9178751f30ac02eabf6cff6. Finalement les champs génériques ne doivent pas avoir de placeholder personnalisable, ce sera uniquement via la description. --- .../champ_component/champ_component.html.haml | 7 ----- .../types_de_champ_controller.rb | 1 - app/models/type_de_champ.rb | 15 +-------- .../dossiers/editable_champs/_text.html.haml | 2 +- .../editable_champs/_textarea.html.haml | 2 +- config/locales/fr.yml | 6 ---- .../types_de_champ_controller_spec.rb | 1 - .../administrateurs/types_de_champ_spec.rb | 31 ------------------- .../shared/dossiers/_edit.html.haml_spec.rb | 18 ----------- 9 files changed, 3 insertions(+), 80 deletions(-) diff --git a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml index ec2aaff5d..dafc05bcf 100644 --- a/app/components/types_de_champ_editor/champ_component/champ_component.html.haml +++ b/app/components/types_de_champ_editor/champ_component/champ_component.html.haml @@ -34,13 +34,6 @@ = form.label :description, "Description du champ (optionnel)", for: dom_id(type_de_champ, :description) = form.text_area :description, class: 'small-margin small width-100', rows: 3, id: dom_id(type_de_champ, :description) - - if type_de_champ.generic? - .cell.mt-1 - = form.label :placeholder, t(".generic.custom_placeholder_title"), class: 'flex-grow', for: dom_id(type_de_champ, :placeholder) - = form.text_field :placeholder, class: 'small-margin small width-100', placeholder: t("#{type_de_champ.type_champ}.placeholder", scope: "shared.dossiers.editable_champs"), id: dom_id(type_de_champ, :placeholder) - %p - = t(".generic.custom_placeholder_hint") - .flex.justify-start.mt-1 - if type_de_champ.drop_down_list? .flex.column.justify-start.width-33 diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index d0618d821..dc7501e81 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -96,7 +96,6 @@ module Administrateurs :drop_down_secondary_libelle, :drop_down_secondary_description, :piece_justificative_template, - :placeholder, editable_options: [ :cadastres, :unesco, diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 851d0f7e9..c771340a9 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -58,16 +58,7 @@ class TypeDeChamp < ApplicationRecord mesri: 'mesri' } - store_accessor :options, :cadastres, - :drop_down_options, - :drop_down_other, - :drop_down_secondary_description, - :drop_down_secondary_libelle, - :old_pj, - :placeholder, - :skip_content_type_pj_validation, - :skip_pj_validation - + store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation, :skip_content_type_pj_validation, :drop_down_secondary_libelle, :drop_down_secondary_description, :drop_down_other has_many :revision_types_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ has_one :revision_type_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: false has_many :revisions, -> { ordered }, through: :revision_types_de_champ @@ -226,10 +217,6 @@ class TypeDeChamp < ApplicationRecord type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list) end - def generic? - type_champ == TypeDeChamp.type_champs.fetch(:text) || type_champ == TypeDeChamp.type_champs.fetch(:textarea) - end - def exclude_from_view? type_champ == TypeDeChamp.type_champs.fetch(:explication) end diff --git a/app/views/shared/dossiers/editable_champs/_text.html.haml b/app/views/shared/dossiers/editable_champs/_text.html.haml index c05eac8f6..0408b7bad 100644 --- a/app/views/shared/dossiers/editable_champs/_text.html.haml +++ b/app/views/shared/dossiers/editable_champs/_text.html.haml @@ -1,5 +1,5 @@ = form.text_field :value, id: champ.input_id, - placeholder: champ.type_de_champ.placeholder.presence || t(".placeholder"), + placeholder: t(".placeholder"), required: champ.mandatory?, aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_textarea.html.haml b/app/views/shared/dossiers/editable_champs/_textarea.html.haml index 894a3ddbe..2d666a10a 100644 --- a/app/views/shared/dossiers/editable_champs/_textarea.html.haml +++ b/app/views/shared/dossiers/editable_champs/_textarea.html.haml @@ -4,4 +4,4 @@ rows: 6, required: champ.mandatory?, value: html_to_string(champ.value), - placeholder: champ.type_de_champ.placeholder.presence || t(".placeholder") + placeholder: t(".placeholder") diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 8e74c0884..b83bf48fd 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -575,9 +575,3 @@ fr: weekly_distribution_details: "au cours des 6 derniers mois" procedure_description: estimated_fill_duration: "Temps de remplissage estimé : %{estimated_minutes} mn" - - types_de_champ_editor: - champ_component: - generic: - custom_placeholder_title: "Spécimen de saisie (optionnel)" - custom_placeholder_hint: Modèle de réponse visible dans le champ avant la saisie par l'usager diff --git a/spec/controllers/administrateurs/types_de_champ_controller_spec.rb b/spec/controllers/administrateurs/types_de_champ_controller_spec.rb index 50822051f..cf801428f 100644 --- a/spec/controllers/administrateurs/types_de_champ_controller_spec.rb +++ b/spec/controllers/administrateurs/types_de_champ_controller_spec.rb @@ -30,7 +30,6 @@ describe Administrateurs::TypesDeChampController, type: :controller do type_de_champ: { type_champ: type_champ, libelle: 'l1.5', - placeholder: "custom placeholder", after_stable_id: first_coordinate.stable_id } } diff --git a/spec/system/administrateurs/types_de_champ_spec.rb b/spec/system/administrateurs/types_de_champ_spec.rb index a9c70656c..6b19f932e 100644 --- a/spec/system/administrateurs/types_de_champ_spec.rb +++ b/spec/system/administrateurs/types_de_champ_spec.rb @@ -165,35 +165,4 @@ describe 'As an administrateur I can edit types de champ', js: true do end expect(page).not_to have_content('Durée de remplissage estimée') end - - describe "placeholders for generic types" do - let(:placeholder) { "my placeholder" } - before do - add_champ - end - - it "text champ" do - select('Texte', from: 'Type de champ') - expect(page).to have_content('Spécimen de saisie') - - fill_in 'Spécimen de saisie', with: placeholder - - wait_until { procedure.draft_types_de_champ.first.placeholder == placeholder } - - page.refresh - expect(page).to have_selector("input[value='#{placeholder}']") - end - - it "textarea champ" do - select('Zone de texte', from: 'Type de champ') - expect(page).to have_content('Spécimen de saisie') - - fill_in 'Spécimen de saisie', with: placeholder - - wait_until { procedure.draft_types_de_champ.first.placeholder == placeholder } - - page.refresh - expect(page).to have_selector("input[value='#{placeholder}']") - end - end end diff --git a/spec/views/shared/dossiers/_edit.html.haml_spec.rb b/spec/views/shared/dossiers/_edit.html.haml_spec.rb index df0272d13..e78357916 100644 --- a/spec/views/shared/dossiers/_edit.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_edit.html.haml_spec.rb @@ -34,24 +34,6 @@ describe 'shared/dossiers/edit.html.haml', type: :view do expect(subject).to have_css('input[type="tel"][placeholder^="0612"]') end end - - context "with generic champs" do - let(:champ_text) { create(:champ_text, dossier: dossier) } - let(:champs) { [champ_text, champ_textarea] } - - it "renders default placeholders" do - expect(subject).to have_css('input[placeholder*="réponse"]') - expect(subject).to have_css('textarea[placeholder*="réponse"]') - end - - it "renders customized placeholders" do - champ_text.type_de_champ.placeholder = "custom1 placeholder" - champ_textarea.type_de_champ.placeholder = "custom2 placeholder" - - expect(subject).to have_css('input[placeholder*="custom1"]') - expect(subject).to have_css('textarea[placeholder*="custom2"]') - end - end end context 'with a single-value list' do From d805114a728f3f7045215277deadde4f8af0f2ed Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 12 Jul 2022 11:10:01 +0200 Subject: [PATCH 2/2] Revert "feat(revision): list updated placeholder option for generic type de champ" This reverts commit fe0282e9044f6fa91de0846b5803d497f40b6c8f. Continue 2bd33ada45b036f73f3fc78150621092e0667693 --- app/models/procedure_revision.rb | 12 ------------ .../_revision_change_type_de_champ.html.haml | 2 -- .../views/administrateurs/revision_changes/fr.yml | 1 - spec/models/procedure_revision_spec.rb | 12 +----------- 4 files changed, 1 insertion(+), 26 deletions(-) diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 1ef377909..59070bcca 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -385,18 +385,6 @@ class ProcedureRevision < ApplicationRecord stable_id: from_type_de_champ.stable_id } end - if from_type_de_champ.placeholder != to_type_de_champ.placeholder - changes << { - model: :type_de_champ, - op: :update, - attribute: :placeholder, - label: from_type_de_champ.libelle, - private: from_type_de_champ.private?, - from: from_type_de_champ.placeholder, - to: to_type_de_champ.placeholder, - stable_id: from_type_de_champ.stable_id - } - end if to_type_de_champ.drop_down_list? if from_type_de_champ.drop_down_list_options != to_type_de_champ.drop_down_list_options changes << { diff --git a/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml b/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml index ff27a8b2f..dd043c6f7 100644 --- a/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml +++ b/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml @@ -44,8 +44,6 @@ %li.mb-1= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.enabled", label: change[:label]) - else %li.mb-1= t("administrateurs.revision_changes.update_drop_down_other#{postfix}.disabled", label: change[:label]) - - when :placeholder - %li.mb-1= t("update_placeholder#{postfix}", label: change[:label], to: change[:to], scope: [:administrateurs, :revision_changes]) - when :carte_layers - added = change[:to].sort - change[:from].sort - removed = change[:from].sort - change[:to].sort diff --git a/config/locales/views/administrateurs/revision_changes/fr.yml b/config/locales/views/administrateurs/revision_changes/fr.yml index 128b5e2c9..9c9e8b9e6 100644 --- a/config/locales/views/administrateurs/revision_changes/fr.yml +++ b/config/locales/views/administrateurs/revision_changes/fr.yml @@ -28,7 +28,6 @@ fr: enabled: Le champ « %{label} » comporte maintenant un choix « Autre » disabled: Le champ « %{label} » ne comporte plus de choix « Autre » update_carte_layers: Les référentiels cartographiques du champ « %{label} » ont été modifiés - update_placeholder: Le spécimen de saisie du champ « %{label} » a été modifié. Le nouveau spécimen est « %{to} ». add_private: L’annotation privée « %{label} » a été ajoutée remove_private: L’annotation privée « %{label} » a été supprimée move_private: diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb index dc04683b3..2f524de82 100644 --- a/spec/models/procedure_revision_spec.rb +++ b/spec/models/procedure_revision_spec.rb @@ -357,7 +357,7 @@ describe ProcedureRevision do before do updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id) - updated_tdc.update(libelle: 'modifier le libelle', description: 'une description', mandatory: !updated_tdc.mandatory, placeholder: "new placeholder") + updated_tdc.update(libelle: 'modifier le libelle', description: 'une description', mandatory: !updated_tdc.mandatory) end it do @@ -391,16 +391,6 @@ describe ProcedureRevision do from: false, to: true, stable_id: first_tdc.stable_id - }, - { - model: :type_de_champ, - op: :update, - attribute: :placeholder, - label: first_tdc.libelle, - private: false, - from: first_tdc.placeholder, - to: "new placeholder", - stable_id: first_tdc.stable_id } ]) end