From df135b080ba109fd3638dad996aa2d1fe1639d48 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 21 Nov 2022 16:06:32 +0100 Subject: [PATCH] refactor(attachment): remove useless `id` arg --- app/components/attachment/edit_component.rb | 9 +++------ app/components/attachment/multiple_component.rb | 4 +--- .../multiple_component/multiple_component.html.haml | 4 ++-- app/components/types_de_champ_editor/champ_component.rb | 3 +-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index 01421c21a..7b19a4889 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -9,13 +9,12 @@ class Attachment::EditComponent < ApplicationComponent EXTENSIONS_ORDER = ['jpeg', 'png', 'pdf', 'zip'].freeze - def initialize(champ: nil, auto_attach_url: nil, field_name: nil, attached_file:, direct_upload: true, id: nil, index: 0, as_multiple: false, user_can_download: false, **kwargs) + def initialize(champ: nil, auto_attach_url: nil, field_name: nil, attached_file:, direct_upload: true, index: 0, as_multiple: false, user_can_download: false, **kwargs) @as_multiple = as_multiple @attached_file = attached_file @auto_attach_url = auto_attach_url @champ = champ @direct_upload = direct_upload - @id = id @index = index @user_can_download = user_can_download @@ -62,7 +61,7 @@ class Attachment::EditComponent < ApplicationComponent { class: "fr-upload attachment-input #{attachment_input_class} #{persisted? ? 'hidden' : ''}", direct_upload: @direct_upload, - id: input_id(@id), + id: input_id, aria: { describedby: champ&.describedby_id }, data: { auto_attach_url: @@ -144,9 +143,7 @@ class Attachment::EditComponent < ApplicationComponent private - def input_id(given_id) - return given_id if given_id.present? - + def input_id if champ.present? # Single or first attachment input must match label "for" attribute. Others must remain unique. return champ.input_id if @index.zero? diff --git a/app/components/attachment/multiple_component.rb b/app/components/attachment/multiple_component.rb index 75caae41c..73efac37f 100644 --- a/app/components/attachment/multiple_component.rb +++ b/app/components/attachment/multiple_component.rb @@ -4,17 +4,15 @@ class Attachment::MultipleComponent < ApplicationComponent attr_reader :form attr_reader :attached_file - attr_reader :id attr_reader :user_can_destroy attr_reader :max delegate :count, :empty?, to: :attachments, prefix: true - def initialize(form:, attached_file:, user_can_destroy: false, id: nil, max: nil) + def initialize(form:, attached_file:, user_can_destroy: false, max: nil) @form = form @attached_file = attached_file @user_can_destroy = user_can_destroy - @id = id @max = max || 10 @attachments = attached_file.attachments || [] diff --git a/app/components/attachment/multiple_component/multiple_component.html.haml b/app/components/attachment/multiple_component/multiple_component.html.haml index 7b493ae28..5304f8ec5 100644 --- a/app/components/attachment/multiple_component/multiple_component.html.haml +++ b/app/components/attachment/multiple_component/multiple_component.html.haml @@ -3,10 +3,10 @@ - each_attachment do |attachment, index| %div{ id: dom_id(attachment) } - = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, id:, index:, as_multiple: true) + = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, index:, as_multiple: true) %div{ id: empty_component_id, class: class_names("hidden": !can_attach_next?) } - = render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, id:, index: attachments_count) + = render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, index: attachments_count) // single poll and refresh message for all attachments - if in_progress? diff --git a/app/components/types_de_champ_editor/champ_component.rb b/app/components/types_de_champ_editor/champ_component.rb index cb8d4a1df..f64abb9f1 100644 --- a/app/components/types_de_champ_editor/champ_component.rb +++ b/app/components/types_de_champ_editor/champ_component.rb @@ -77,8 +77,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent def piece_justificative_template_options { attached_file: type_de_champ.piece_justificative_template, - auto_attach_url: helpers.auto_attach_url(type_de_champ), - id: dom_id(type_de_champ, :piece_justificative_template) + auto_attach_url: helpers.auto_attach_url(type_de_champ) } end