Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selected file representation after reselect #407

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/polaris_view_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ class Dropzone extends Controller {
onChange(e) {
this.stopEvent(e);
if (this.disabled) return;
this.clearFiles();
const fileList = getDataTransferFiles(e);
this.clearFiles();
const {files: files, acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles} = this.getValidatedFiles(fileList);
this.dragTargets = [];
this.files = files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export default class extends Controller {
this.stopEvent(e)
if (this.disabled) return

const fileList = getDataTransferFiles(e)
this.clearFiles()

const fileList = getDataTransferFiles(e)
const { files, acceptedFiles, rejectedFiles } = this.getValidatedFiles(fileList)
this.dragTargets = []

Expand Down
29 changes: 29 additions & 0 deletions test/system/dropzone_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@ def test_multiple_direct_uploads
assert_text "Attachments (2)"
end

def test_reselect_file
with_preview("dropzone_component/with_file_upload")

find(".Polaris-DropZone").drop(fixture_file("file.txt"), fixture_file("image.png"))
assert_selector ".Polaris-DropZone__Preview > .Polaris-LegacyStack > .Polaris-LegacyStack__Item", count: 2
within ".Polaris-DropZone__Preview > .Polaris-LegacyStack" do
assert_selector ".Polaris-LegacyStack__Item:nth-child(1)" do
assert_text "file.txt"
assert_text "10 Bytes"
end
assert_selector ".Polaris-LegacyStack__Item:nth-child(2)" do
assert_text "image.png"
assert_text "11.37 KB"
end
end

page.attach_file(fixture_file("image.png")) do
page.find(".Polaris-DropZone").click
end

assert_selector ".Polaris-DropZone__Preview > .Polaris-LegacyStack > .Polaris-LegacyStack__Item", count: 1
within ".Polaris-DropZone__Preview > .Polaris-LegacyStack" do
assert_selector ".Polaris-LegacyStack__Item:nth-child(1)" do
assert_text "image.png"
assert_text "11.37 KB"
end
end
end

def fixture_file(name)
Rails.root.join("../test/fixtures/#{name}")
end
Expand Down
Loading