Skip to content

Commit d2d81eb

Browse files
authored
Merge pull request #12799 from mfo/US/preserve-progress-bar
correctif: l'upload multiple ne devrait pas supprimer une progress bar quand un upload est terminé
2 parents 86742f2 + fcffcc2 commit d2d81eb

6 files changed

Lines changed: 29 additions & 5 deletions

File tree

app/components/attachment/file_field_component.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def empty_component_id
7979
champ.present? ? "attachment-empty-#{champ.public_id}" : "attachment-empty-generic"
8080
end
8181

82+
def progress_container_id
83+
champ.present? ? "attachment-progress-#{champ.public_id}" : "attachment-progress-generic"
84+
end
85+
8286
def describedby_hint_id
8387
return nil if champ.nil?
8488
"#{champ.focusable_input_id}-hint"

app/components/attachment/file_field_component/file_field_component.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
<%# Error wrapper %>
5151
<%= render Attachment::ErrorWrapperComponent.new(with_top_margin: !show_uploader?) %>
5252

53+
<%# Progress bars container — preserved during turbo morph %>
54+
<div
55+
id="<%= progress_container_id %>"
56+
data-turbo-force="browser"
57+
data-progress-container
58+
></div>
59+
5360
<%# Existing files %>
5461
<% if @attachments.any? %>
5562
<% if show_as_list? %>

app/javascript/shared/activestorage/progress-bar.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ export default class ProgressBar {
2020
static init(input: HTMLInputElement, id: string, file: File) {
2121
clearErrors(input);
2222
const html = this.render(id, file.name);
23-
input.before(html);
23+
const progressContainer = input
24+
.closest('.attachment-field')
25+
?.querySelector<HTMLElement>('[data-progress-container]');
26+
if (progressContainer) {
27+
progressContainer.append(html);
28+
} else {
29+
input.before(html);
30+
}
2431
}
2532

2633
static start(id: string) {
@@ -128,8 +135,11 @@ export default class ProgressBar {
128135
}
129136

130137
function clearErrors(input: HTMLInputElement) {
131-
const errorElements =
132-
input.parentElement?.querySelectorAll(`.${ERROR_CLASS}`) ?? [];
138+
const container =
139+
input
140+
.closest('.attachment-field')
141+
?.querySelector('[data-progress-container]') ?? input.parentElement;
142+
const errorElements = container?.querySelectorAll(`.${ERROR_CLASS}`) ?? [];
133143
for (const element of errorElements) {
134144
element.remove();
135145
}

app/javascript/shared/activestorage/uploader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export default class Uploader {
5555

5656
if (this.autoAttachUrl) {
5757
await this.attach(blobSignedId, this.autoAttachUrl);
58-
// On response, the attachment HTML fragment will replace the progress bar.
58+
this.progressBar.end();
59+
this.progressBar.destroy();
5960
} else {
6061
this.progressBar.end();
6162
this.progressBar.destroy();

app/views/champs/repetition/add.turbo_stream.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<% if @row_id.present? %>
22
<%= fields_for @champ.input_name, @champ do |form| %>
33
<%= turbo_stream.append dom_id(@champ, :rows), render(EditableChamp::RepetitionRowComponent.new(form: form, dossier: @champ.dossier, champ: @champ, row_id: @row_id, row_number: @row_number, expanded: true)) %>
4+
45
<% if @first_champ_id %>
56
<%= turbo_stream.focus(@first_champ_id, delay: 50) %>
67
<% end %>

app/views/champs/repetition/remove.turbo_stream.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<% end %>
88

99
<% if @deleted_row_number %>
10-
<%= turbo_stream.append dom_id(@champ, :deletion_announcement), delay: 1000 do %> <%# the delay is to ensure there is not conflict with the focus %>
10+
<%= turbo_stream.append dom_id(@champ, :deletion_announcement), delay: 1000 do %>
11+
<%# the delay is to ensure there is not conflict with the focus %>
1112
<%= t('editable_champ.repetition_component.deleted', row_number: @deleted_row_number, libelle: @champ.row_libelle) %>
1213
<% end %>
1314
<% end %>

0 commit comments

Comments
 (0)