chore(attachment): increase poll antivirus timeout and make it clear it's not blocker
This commit is contained in:
parent
169d701a03
commit
7719ce1865
10 changed files with 55 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
---
|
||||
fr:
|
||||
reload: Recharger
|
||||
explanation: L’analyse antivirus et le traitement de votre ou de vos pièces jointes prend plus de temps que prévu.
|
||||
explanation:
|
||||
one: L’analyse antivirus et le traitement de votre pièce jointe prend plus de temps que prévu.
|
||||
other: L’analyse 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.
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue