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(', '))