chore(attachments): always render allowed formats when list is short

Co-Authored-By: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
Colin Darie 2023-09-20 17:35:17 +02:00 committed by krichtof
parent 44578ba65c
commit 3e1678c17a
3 changed files with 12 additions and 10 deletions

View file

@ -204,12 +204,14 @@ class Attachment::EditComponent < ApplicationComponent
end
def allowed_formats
return nil unless champ&.titre_identite?
@allowed_formats ||= begin
content_type_validator.options[:in].filter_map do |content_type|
formats = content_type_validator.options[:in].filter_map do |content_type|
MiniMime.lookup_by_content_type(content_type)&.extension
end.uniq.sort_by { EXTENSIONS_ORDER.index(_1) || 999 }
# When too many formats are allowed, consider instead manually indicating
# above the input a more comprehensive of formats allowed, like "any image", or a simplified list.
formats.size > 5 ? [] : formats
end
end

View file

@ -23,7 +23,7 @@
%p.fr-text--sm.fr-text-mention--grey.fr-mb-1w
- if max_file_size.present?
= t('.max_file_size', max_file_size: number_to_human_size(max_file_size))
- if allowed_formats
- if allowed_formats.present?
= t('.allowed_formats', formats: allowed_formats.join(', '))

View file

@ -1,10 +1,10 @@
.card.mt-2
= render NestedForms::FormOwnerComponent.new
= form_with url: { action: :add_signature }, method: :post, html: { multipart: true, class: 'form' } do |f|
= form_with url: { action: :add_signature }, method: :post, html: { multipart: true } do |f|
.card-title Tampon de l'attestation
= render Attachment::EditComponent.new(attached_file: groupe_instructeur.signature, direct_upload: false)
%p.notice
Formats acceptés : JPG / JPEG / PNG.
%br
Dimensions conseillées : au minimum 500 px de largeur ou de hauteur, poids maximum : 0,5 Mo.
= f.submit 'Ajouter signature', class: 'fr-btn'
.fr-upload-group.fr-mb-4w
%p.fr-text--sm.fr-text-mention--grey.fr-mb-1w
Dimensions conseillées : au minimum 500 px de largeur ou de hauteur.
= render Attachment::EditComponent.new(attached_file: groupe_instructeur.signature, direct_upload: false)