refactor(attachment): remove some dead code from components

This commit is contained in:
Paul Chavard 2024-11-26 14:25:16 +01:00
parent c2c26719d3
commit 3e6f074f31
No known key found for this signature in database
7 changed files with 4 additions and 22 deletions

View file

@ -12,14 +12,13 @@ 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, attached_file:, direct_upload: true, index: 0, as_multiple: false, view_as: :link, user_can_destroy: true, user_can_replace: false, attachments: [], max: nil, **kwargs) def initialize(champ: nil, auto_attach_url: nil, attached_file:, direct_upload: true, index: 0, as_multiple: false, view_as: :link, user_can_destroy: true, attachments: [], max: nil, **kwargs)
@champ = champ @champ = champ
@attached_file = attached_file @attached_file = attached_file
@direct_upload = direct_upload @direct_upload = direct_upload
@index = index @index = index
@view_as = view_as @view_as = view_as
@user_can_destroy = user_can_destroy @user_can_destroy = user_can_destroy
@user_can_replace = user_can_replace
@as_multiple = as_multiple @as_multiple = as_multiple
@auto_attach_url = auto_attach_url @auto_attach_url = auto_attach_url

View file

@ -17,7 +17,7 @@ class Attachment::MultipleComponent < ApplicationComponent
delegate :count, :empty?, to: :attachments, prefix: true delegate :count, :empty?, to: :attachments, prefix: true
def initialize(champ: nil, attached_file:, form_object_name: nil, view_as: :link, user_can_destroy: true, user_can_replace: false, max: nil) def initialize(champ: nil, attached_file:, form_object_name: nil, view_as: :link, user_can_destroy: true, max: nil)
@champ = champ @champ = champ
@attached_file = attached_file @attached_file = attached_file
@form_object_name = form_object_name @form_object_name = form_object_name

View file

@ -13,10 +13,6 @@ class EditableChamp::PieceJustificativeComponent < EditableChamp::EditableChampB
end end
end end
def user_can_destroy?
!@champ.mandatory? || @champ.dossier.brouillon?
end
def max def max
[true, nil].include?(@champ.procedure&.piece_justificative_multiple?) ? Attachment::MultipleComponent::DEFAULT_MAX_ATTACHMENTS : 1 [true, nil].include?(@champ.procedure&.piece_justificative_multiple?) ? Attachment::MultipleComponent::DEFAULT_MAX_ATTACHMENTS : 1
end end

View file

@ -1,4 +1,4 @@
= render Attachment::MultipleComponent.new(champ: @champ, attached_file: @champ.piece_justificative_file, form_object_name: @form.object_name, view_as:, user_can_destroy: user_can_destroy?, max:) do |c| = render Attachment::MultipleComponent.new(champ: @champ, attached_file: @champ.piece_justificative_file, form_object_name: @form.object_name, view_as:, max:) do |c|
- if @champ.type_de_champ.piece_justificative_template&.attached? - if @champ.type_de_champ.piece_justificative_template&.attached?
- c.with_template do - c.with_template do
= render partial: "shared/piece_justificative_template", locals: { champ: @champ } = render partial: "shared/piece_justificative_template", locals: { champ: @champ }

View file

@ -4,8 +4,4 @@ class EditableChamp::TitreIdentiteComponent < EditableChamp::EditableChampBaseCo
def dsfr_input_classname def dsfr_input_classname
'fr-input' 'fr-input'
end end
def user_can_destroy?
!@champ.mandatory? || @champ.dossier.brouillon?
end
end end

View file

@ -1,4 +1,3 @@
- if @champ.type_de_champ.piece_justificative_template&.attached? - if @champ.type_de_champ.piece_justificative_template&.attached?
= render partial: "shared/piece_justificative_template", locals: { champ: @champ } = render partial: "shared/piece_justificative_template", locals: { champ: @champ }
= render Attachment::EditComponent.new(champ: @form.object, attached_file: @champ.piece_justificative_file, attachment: @champ.piece_justificative_file[0], form_object_name: @form.object_name, = render Attachment::EditComponent.new(champ: @form.object, attached_file: @champ.piece_justificative_file, attachment: @champ.piece_justificative_file[0], form_object_name: @form.object_name)
user_can_destroy: user_can_destroy?)

View file

@ -96,14 +96,6 @@ RSpec.describe Attachment::MultipleComponent, type: :component do
end end
end end
context 'when user can replace' do
let(:kwargs) { { user_can_replace: true } }
before do
attach_to_champ(attached_file, champ)
end
end
def attach_to_champ(attached_file, champ) def attach_to_champ(attached_file, champ)
attached_file.attach( attached_file.attach(
io: StringIO.new("x" * 2), io: StringIO.new("x" * 2),