Skip to content

✨(frontend) preserve empty folders on drag & drop upload#655

Merged
PanchoutNathan merged 3 commits intomainfrom
feature/drop-empty-folders
Apr 16, 2026
Merged

✨(frontend) preserve empty folders on drag & drop upload#655
PanchoutNathan merged 3 commits intomainfrom
feature/drop-empty-folders

Conversation

@PanchoutNathan
Copy link
Copy Markdown
Contributor

Summary

  • Add a custom getFilesFromEvent for react-dropzone that walks the
    drop tree ourselves and emits a zero-byte marker file for every
    empty folder, so empty directories dropped into the explorer are
    now created instead of being silently dropped.
  • Update useUpload to materialize the folder chain from markers via
    getFolderByPath, then filter them out before any size validation
    or backend upload. When a drop contains only markers, the file
    upload toast is suppressed and a dedicated success toast is shown
    once the folders have been created.
  • Add unit tests covering marker creation, the batched
    readEntries() loop, recursive entry walking, and the
    customGetFilesFromEvent entry point.

Input change events (folder/file buttons) remain delegated to
file-selector: the browser does not expose empty folders through
<input webkitdirectory>, matching the Google Drive / Proton Drive
limitation.

Test plan

  • Drop an empty folder into the explorer and confirm it is
    created with the success toast.
  • Drop a folder tree mixing empty and non-empty subfolders and
    confirm both the files and the empty folders land correctly.
  • Drop a single file and confirm the regular upload toast still
    shows progress.
  • Use the "Import folder" button with a non-empty folder and
    confirm the existing behavior is unchanged.
  • Run the new unit tests in
    dropTraversal.test.ts.

@PanchoutNathan PanchoutNathan requested a review from NathanVss April 9, 2026 12:15
@PanchoutNathan PanchoutNathan self-assigned this Apr 9, 2026
@PanchoutNathan PanchoutNathan linked an issue Apr 9, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@NathanVss NathanVss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat !! :)

React-dropzone's default traversal silently drops empty directories
because webkitGetAsEntry()'s readEntries() yields no entry for them.

Add a custom getFilesFromEvent that walks the drop tree ourselves
and emits a zero-byte marker file for every empty folder. The marker
carries an isEmptyFolder flag and a path so useUpload can materialize
the folder chain via getFolderByPath, then skip the marker before any
size validation or backend upload.

When a drop contains only empty-folder markers, the file upload toast
is suppressed and a dedicated success toast is shown once the folders
have been created. Input change events (folder/file buttons) are
delegated to file-selector, matching the Google Drive / Proton Drive
limitation around <input webkitdirectory>.
Cover the custom drop traversal helpers: empty-folder marker
creation, batched readEntries() loop, recursive entry walking
for files, nested non-empty folders, and empty directories, plus
the customGetFilesFromEvent entry point for drop events and its
delegation to file-selector for non-drag inputs.
Use String.localeCompare in three test sort() calls to satisfy
the reliability rule S2871, and drop the redundant Event branch
of the Event | unknown parameter type in customGetFilesFromEvent
(S6571).
@PanchoutNathan PanchoutNathan force-pushed the feature/drop-empty-folders branch from 87cebad to 51552ac Compare April 16, 2026 12:26
@sonarqubecloud
Copy link
Copy Markdown

@PanchoutNathan PanchoutNathan merged commit 51552ac into main Apr 16, 2026
32 checks passed
@PanchoutNathan PanchoutNathan deleted the feature/drop-empty-folders branch April 16, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

You can't upload an empty folder tree

2 participants