Skip to content

Commit 2159733

Browse files
mfoclaude
andcommitted
Tech: migrate all attachment usages to new components
Migrate all existing usages: - MultipleComponent → FileFieldComponent with drop_zone: :integrated - UniqueComponent → FileFieldComponent with drop_zone: :none All functionality preserved, architecture simplified. Affects 17 files across views and components. Part of attachment components refactoring (#5/7) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6b61732 commit 2159733

20 files changed

Lines changed: 51 additions & 40 deletions

File tree

app/components/attachment/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Value object for attachment component configuration.
4-
# Eliminates parameter duplication (12→5 params for ButtonUploaderComponent).
4+
# Eliminates parameter duplication across attachment components.
55
class Attachment::Context
66
attr_reader :champ, :attached_file, :auto_attach_url, :direct_upload, :view_as,
77
:user_can_destroy, :form_object_name, :aria_labelledby,

app/components/attachment/file_field_component.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ class Attachment::FileFieldComponent < ApplicationComponent
3030

3131
renders_one :template
3232

33-
attr_reader :context, :max, :drop_zone, :attachments, :current_count
33+
attr_reader :context, :max, :drop_zone, :attachments, :current_count, :hidden, :input_id
3434

3535
delegate :champ, :form_object_name, :view_as, :user_can_destroy?, :aria_labelledby, :attached_file,
3636
to: :context
3737

38-
def initialize(context:, drop_zone:, max: nil, attachments: nil)
38+
def initialize(context:, drop_zone:, max: nil, attachments: nil, hidden: false, id: nil)
3939
@context = context
4040
@drop_zone = drop_zone
41+
@hidden = hidden
42+
@input_id = id
4143

4244
# Get attachments
4345
@attachments = if attachments
@@ -95,7 +97,9 @@ def file_input_component
9597
Attachment::FileInputComponent.new(
9698
context:,
9799
max: @max,
98-
current_count: @current_count
100+
current_count: @current_count,
101+
hidden: @hidden,
102+
id: @input_id
99103
)
100104
end
101105

app/components/editable_champ/piece_justificative_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def max
1717
if @champ.RIB? || @champ.titre_identite_nature?
1818
1
1919
elsif [true, nil].include?(@champ.procedure&.piece_justificative_multiple?)
20-
Attachment::MultipleComponent::DEFAULT_MAX_ATTACHMENTS
20+
Attachment::FileFieldComponent::DEFAULT_MAX_ATTACHMENTS
2121
else
2222
1
2323
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= render Attachment::MultipleComponent.new(context: attachment_context, max:) do |c|
1+
= render Attachment::FileFieldComponent.new(context: attachment_context, max:, drop_zone: :integrated) do |c|
22
- if @champ.type_de_champ.piece_justificative_template&.attached?
33
- c.with_template do
44
= render partial: "shared/piece_justificative_template", locals: { champ: @champ }

app/components/editable_champ/quotient_familial_component/quotient_familial_component.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
- if render_piece_justificative_champ?
4545
= t('.piece_justificative_champ.libelle')
4646
= render EditableChamp::AsteriskMandatoryComponent.new
47-
= render Attachment::MultipleComponent.new(context: Attachment::Context.new(champ: @champ, form_object_name: @form.object_name, aria_labelledby: labelledby_id), max: 1)
47+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(champ: @champ, form_object_name: @form.object_name, aria_labelledby: labelledby_id), max: 1), drop_zone: :integrated

app/components/editable_champ/titre_identite_component/titre_identite_component.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
= t('.allowed_formats', formats: allowed_formats.join(', '))
77

88
- attachment = @champ.piece_justificative_file[0]
9-
= render Attachment::UniqueComponent.new(context: attachment_context, attachment:)
9+
= render Attachment::FileFieldComponent.new(context: attachment_context, attachments: attachment ? [attachment] : [], drop_zone: :integrated, max: 1)

app/components/referentiels/new_form_component/new_form_component.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
= form.label :piece_justificative_template, class: 'fr-label', for: dom_id(@type_de_champ, :piece_justificative_template) do
3232
Fichier CSV
3333
%span.fr-text-hint Utilisez le modèle du fichier CSV fourni ci-dessous pour construire votre référentiel (le nombre de colonne n'est pas limité).
34-
= render Attachment::UniqueComponent.new(context: Attachment::Context.new(attached_file: @type_de_champ.piece_justificative_template, view_as: :link))
34+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(attached_file: @type_de_champ.piece_justificative_template, view_as: :link), drop_zone: :none)
3535

3636
%hr.fr-hr.fr-my-5w
3737

app/components/types_de_champ_editor/champ_component/champ_component.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
= form.text_area :collapsible_explanation_text, class: "fr-input small-margin small", id: dom_id(type_de_champ, :collapsible_explanation_text)
6868
.cell.fr-mt-1w
6969
= form.label :notice_explicative, "Notice explicative", for: dom_id(type_de_champ, :notice_explicative)
70-
= render Attachment::UniqueComponent.new(context: Attachment::Context.new(**notice_explicative_options))
70+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(**notice_explicative_options), drop_zone: :none)
7171

7272
- if type_de_champ.piece_justificative?
7373
.cell.fr-mt-1w
@@ -145,7 +145,7 @@
145145
.cell
146146
= form.label :piece_justificative_template, t('.template_label'), for: dom_id(type_de_champ, :piece_justificative_template)
147147
%p.fr-hint-text= t('.max_file_size_hint', max_file_size: number_to_human_size(type_de_champ.max_file_size_bytes))
148-
= render Attachment::UniqueComponent.new(context: Attachment::Context.new(**piece_justificative_template_options))
148+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(**piece_justificative_template_options), drop_zone: :none)
149149

150150
- if type_de_champ.titre_identite?
151151
.cell.fr-mt-1w

app/views/administrateurs/attestation_template_v2s/_form.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Dimensions conseillées : au minimum 500px de largeur ou de hauteur.
6161

6262
%div{ id: h(dom_id(attestation_template, :logo_attachment)) }
63-
= render Attachment::UniqueComponent.new(context: Attachment::Context.new(attached_file: attestation_template.logo, direct_upload: false))
63+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(attached_file: attestation_template.logo, direct_upload: false)), drop_zone: :none
6464

6565
.fr-fieldset__element
6666
= render Dsfr::InputComponent.new(form: f, attribute: :label_direction, input_type: :text_area, required: false, opts: { rows: 2, data: { controller: :textarea, textarea_max_rows_value: 2 } }) do |c|
@@ -103,7 +103,7 @@
103103
Dimensions conseillées : au minimum 500px de largeur ou de hauteur.
104104

105105
%div{ id: h(dom_id(attestation_template, :signature_attachment)) }
106-
= render Attachment::UniqueComponent.new(context: Attachment::Context.new(attached_file: attestation_template.signature, direct_upload: false))
106+
= render Attachment::FileFieldComponent.new(context: Attachment::Context.new(attached_file: attestation_template.signature, direct_upload: false)), drop_zone: :none
107107

108108
.fr-fieldset__element
109109
= render Dsfr::InputComponent.new(form: f, attribute: :footer, input_type: :text_area, required: false, opts: { rows: 3, data: { controller: :textarea, textarea_max_rows_value: 3 } }) do |c|

app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
- if @attestation_template.logo_blob&.previously_new_record?
99
= turbo_stream.update dom_id(@attestation_template, :logo_attachment) do
10-
= render(Attachment::UniqueComponent.new(context: Attachment::Context.new(attached_file: @attestation_template.logo, direct_upload: false)))
10+
= render(Attachment::FileFieldComponent.new(context: Attachment::Context.new(attached_file: @attestation_template.logo, direct_upload: false), drop_zone: :none))
1111

1212
- if @attestation_template.signature_blob&.previously_new_record?
1313
= turbo_stream.update dom_id(@attestation_template, :signature_attachment) do
14-
= render(Attachment::UniqueComponent.new(context: Attachment::Context.new(attached_file: @attestation_template.signature, direct_upload: false)))
14+
= render(Attachment::FileFieldComponent.new(context: Attachment::Context.new(attached_file: @attestation_template.signature, direct_upload: false), drop_zone: :none))
1515

1616
- body_id = "attestation-template-json-body-messages"
1717
- if @attestation_template.errors.include?(:json_body)

0 commit comments

Comments
 (0)