chore(attachment): increase poll antivirus timeout and make it clear it's not blocker

This commit is contained in:
Colin Darie 2022-12-07 18:36:03 +01:00
parent 169d701a03
commit 7719ce1865
10 changed files with 55 additions and 9 deletions

View file

@ -84,6 +84,12 @@ class Attachment::EditComponent < ApplicationComponent
end
end
def poll_context
return :dossier if champ.present?
nil
end
def field_name
helpers.field_name(@form_object_name || ActiveModel::Naming.param_key(@attached_file.record), attribute_name)
end

View file

@ -28,7 +28,7 @@
= file_field(champ, field_name, **file_field_options)
- if persisted?
- Attachment::PendingPollComponent.new(attachment: attachment, poll_url:).then do |component|
- Attachment::PendingPollComponent.new(attachment: attachment, poll_url:, context: poll_context).then do |component|
.fr-mt-2w
= render component

View file

@ -43,4 +43,10 @@ class Attachment::MultipleComponent < ApplicationComponent
helpers.auto_attach_url(champ)
end
alias poll_url auto_attach_url
def poll_context
return :dossier if champ.present?
nil
end
end

View file

@ -10,4 +10,4 @@
= render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:)
// single poll and refresh message for all attachments
= render Attachment::PendingPollComponent.new(attachments: attachments, poll_url:)
= render Attachment::PendingPollComponent.new(attachments: attachments, poll_url:, context: poll_context)

View file

@ -1,11 +1,15 @@
class Attachment::PendingPollComponent < ApplicationComponent
def initialize(poll_url:, attachment: nil, attachments: nil)
attr_reader :attachments
def initialize(poll_url:, attachment: nil, attachments: nil, context: nil)
@poll_url = poll_url
@attachments = if attachment.present?
[attachment]
else
attachments
end
@context = context
end
def render?
@ -14,7 +18,7 @@ class Attachment::PendingPollComponent < ApplicationComponent
def long_pending?
@attachments.any? do
pending_attachment?(_1) && _1.created_at < 30.seconds.ago
pending_attachment?(_1) && _1.created_at < 60.seconds.ago
end
end
@ -25,6 +29,10 @@ class Attachment::PendingPollComponent < ApplicationComponent
}
end
def as_dossier?
@context == :dossier
end
private
def pending_attachment?(attachment)

View file

@ -1,4 +1,7 @@
---
en:
reload: Reload
explanation: Scanning for viruses and processing your attachment(s) takes longer than expected.
explanation:
one: Scanning for viruses and processing your attachment takes longer than expected.
other: Scanning for viruses and processing your attachments takes longer than expected.
dossier_submittable: This does not prevent you from submitting your file if you wish.

View file

@ -1,4 +1,8 @@
---
fr:
reload: Recharger
explanation: Lanalyse antivirus et le traitement de votre ou de vos pièces jointes prend plus de temps que prévu.
explanation:
one: Lanalyse antivirus et le traitement de votre pièce jointe prend plus de temps que prévu.
other: Lanalyse antivirus et le traitement de vos pièces jointes prend plus de temps que prévu.
dossier_submittable: Cela ne vous empêche pas de déposer votre dossier si vous le souhaitez.

View file

@ -2,6 +2,10 @@
- if long_pending?
= render Dsfr::CalloutComponent.new(title: nil) do |c|
- c.with_body do
= t(".explanation")
= t(".explanation", count: attachments.count)
- c.with_bottom do
= button_tag t(".reload"), type: "button", class: "fr-btn", data: { action: 'click->turbo-poll#refresh' }
- if as_dossier?
%p.fr-callout__text.fr-mt-4w= t(".dossier_submittable")

View file

@ -3,7 +3,8 @@ import { httpRequest } from '@utils';
import { ApplicationController } from './application_controller';
const DEFAULT_POLL_INTERVAL = 3000;
const DEFAULT_MAX_CHECKS = 5;
const DEFAULT_MAX_CHECKS = 10;
const DEFAULT_EXPONENTIAL_FACTOR = 1.2;
// Periodically check the state of a URL.
//
@ -65,7 +66,7 @@ export class TurboPollController extends ApplicationController {
if (!state) {
return this.resetState();
}
state.interval *= 1.5;
state.interval *= DEFAULT_EXPONENTIAL_FACTOR;
state.checks += 1;
if (state.checks <= this.maxChecksValue) {
return state;

View file

@ -56,4 +56,18 @@ RSpec.describe Attachment::PendingPollComponent, type: :component do
end
end
end
context "when it's a dossier context" do
before do
attachment.created_at = 5.minutes.ago
end
let(:component) {
described_class.new(poll_url: "poll-here", attachment:, context: :dossier)
}
it "indicates it's not blocker to submit" do
expect(subject).to have_content("déposer votre dossier")
end
end
end