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

Dashboard onDrop Event - Does Not Contain Items #5618

Open
2 tasks done
Romeithius opened this issue Jan 22, 2025 · 2 comments
Open
2 tasks done

Dashboard onDrop Event - Does Not Contain Items #5618

Romeithius opened this issue Jan 22, 2025 · 2 comments
Labels

Comments

@Romeithius
Copy link

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

No response

Steps to reproduce

  1. Configure Uppy with the Dashboard onDrop event (https://uppy.io/docs/dashboard/#ondropevent).

     this.uppy
         .use(Dashboard, {
             onDrop: async (event: DragEvent): Promise<void> => {
                 console.log('onDrop', event);
    
                 // Get the original list of items
                 const dataTransferItems: DataTransferItem[] = Array.from(event.dataTransfer.items);
         
                 const rootDirectory: DirectoryEntry = {
                     name: 'root',
                     path: '',
                     files: [],
                     directories: [],
                 };
         
                 for (const dataTransferItem of dataTransferItems) {
                     const fileSystemEntry: FileSystemEntry = dataTransferItem.webkitGetAsEntry();
                     if (fileSystemEntry) {
                         await this.fileService.traverseFileSystem(fileSystemEntry, rootDirectory);
                     }
                 }
         
                 console.log('Directory Structure:', rootDirectory);
             }
         });
    
     public async traverseFileSystem(
         fileSystemEntry: FileSystemEntry,
         parentDirectory: DirectoryEntry,
     ): Promise<void> {
         if (fileSystemEntry.isFile) {
             // Handle file
             await this.addFileToDirectory(fileSystemEntry as FileSystemFileEntry, parentDirectory);
         }
         else if (fileSystemEntry.isDirectory) {
             // Handle directory
             const directory: DirectoryEntry = {
                 name: fileSystemEntry.name,
                 path: `${parentDirectory.path}/${fileSystemEntry.name}`,
                 files: [],
                 directories: [],
             };
             parentDirectory.directories.push(directory);
    
             // Read directory contents
             await this.readDirectoryContents(fileSystemEntry as FileSystemDirectoryEntry, directory);
         }
     }
    
     private async addFileToDirectory(
         fileSystemFileEntry: FileSystemFileEntry,
         parentDirectory: DirectoryEntry,
     ): Promise<void> {
         return new Promise<void>((resolve, reject) => {
             fileSystemFileEntry.file(
                 (file) => {
                     parentDirectory.files.push(file);
                     resolve();
                 },
                 (error) => {
                     console.error('Error reading file:', error);
                     reject(error);
                 },
             );
         });
     }
    
     private async readDirectoryContents(
         fileShareDirectoryEntry: FileSystemDirectoryEntry,
         parentDirectory: DirectoryEntry,
     ): Promise<void> {
         const reader = fileShareDirectoryEntry.createReader();
    
         return new Promise<void>((resolve, reject) => {
             const readEntries = () => {
                 reader.readEntries(
                     async (entries) => {
                         if (entries.length === 0) {
                             resolve(); // No more entries
                             return;
                         }
    
                         for (const entry of entries) {
                             await this.traverseFileSystem(entry, parentDirectory);
                         }
    
                         // Continue reading if there are more entries
                         readEntries();
                     },
                     (error) => {
                         console.error('Error reading directory:', error);
                         reject(error);
                     },
                 );
             };
    
             readEntries();
         });
     }
    
  2. Create Folder 1 with 2 subfolders (Folder 2 and Folder 3), put a file in Folder 3.

  3. Drag and drop Folder 1.

Expected behavior

The directory structure should show the directories and the files in the defined rootDirectory.

Actual behavior

The rootDirectory is empty.

@Romeithius Romeithius added the Bug label Jan 22, 2025
@Murderlon
Copy link
Member

I'm not sure what you are trying to do? Why are you implementing all this logic yourself if that's what dashboard is precisely supposed to do for you?

@Romeithius
Copy link
Author

Romeithius commented Feb 5, 2025

I'm not sure what you are trying to do? Why are you implementing all this logic yourself if that's what dashboard is precisely supposed to do for you?

The goal is to get the entry directory structure including empty folders. Dashboard is ignoring empty folders, so you cannot get the entire folder structure including the empty folders as part of the built-in onDrop event. It seems like the Dashboard onDrop is acting different than a standard onDrop is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants