refactor(attachment): remove useless id arg

This commit is contained in:
Colin Darie 2022-11-21 16:06:32 +01:00
parent 0a114270af
commit df135b080b
4 changed files with 7 additions and 13 deletions

View file

@ -9,13 +9,12 @@ class Attachment::EditComponent < ApplicationComponent
EXTENSIONS_ORDER = ['jpeg', 'png', 'pdf', 'zip'].freeze 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 @as_multiple = as_multiple
@attached_file = attached_file @attached_file = attached_file
@auto_attach_url = auto_attach_url @auto_attach_url = auto_attach_url
@champ = champ @champ = champ
@direct_upload = direct_upload @direct_upload = direct_upload
@id = id
@index = index @index = index
@user_can_download = user_can_download @user_can_download = user_can_download
@ -62,7 +61,7 @@ class Attachment::EditComponent < ApplicationComponent
{ {
class: "fr-upload attachment-input #{attachment_input_class} #{persisted? ? 'hidden' : ''}", class: "fr-upload attachment-input #{attachment_input_class} #{persisted? ? 'hidden' : ''}",
direct_upload: @direct_upload, direct_upload: @direct_upload,
id: input_id(@id), id: input_id,
aria: { describedby: champ&.describedby_id }, aria: { describedby: champ&.describedby_id },
data: { data: {
auto_attach_url: auto_attach_url:
@ -144,9 +143,7 @@ class Attachment::EditComponent < ApplicationComponent
private private
def input_id(given_id) def input_id
return given_id if given_id.present?
if champ.present? if champ.present?
# Single or first attachment input must match label "for" attribute. Others must remain unique. # Single or first attachment input must match label "for" attribute. Others must remain unique.
return champ.input_id if @index.zero? return champ.input_id if @index.zero?

View file

@ -4,17 +4,15 @@ class Attachment::MultipleComponent < ApplicationComponent
attr_reader :form attr_reader :form
attr_reader :attached_file attr_reader :attached_file
attr_reader :id
attr_reader :user_can_destroy attr_reader :user_can_destroy
attr_reader :max attr_reader :max
delegate :count, :empty?, to: :attachments, prefix: true 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 @form = form
@attached_file = attached_file @attached_file = attached_file
@user_can_destroy = user_can_destroy @user_can_destroy = user_can_destroy
@id = id
@max = max || 10 @max = max || 10
@attachments = attached_file.attachments || [] @attachments = attached_file.attachments || []

View file

@ -3,10 +3,10 @@
- each_attachment do |attachment, index| - each_attachment do |attachment, index|
%div{ id: dom_id(attachment) } %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?) } %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 // single poll and refresh message for all attachments
- if in_progress? - if in_progress?

View file

@ -77,8 +77,7 @@ class TypesDeChampEditor::ChampComponent < ApplicationComponent
def piece_justificative_template_options def piece_justificative_template_options
{ {
attached_file: type_de_champ.piece_justificative_template, attached_file: type_de_champ.piece_justificative_template,
auto_attach_url: helpers.auto_attach_url(type_de_champ), auto_attach_url: helpers.auto_attach_url(type_de_champ)
id: dom_id(type_de_champ, :piece_justificative_template)
} }
end end