uptick / react-keyed-file-browser

Folder based file browser given a flat keyed list of objects, powered by React.
MIT License
301 stars 144 forks source link

On selection callback? #115

Closed brennanbatalla closed 3 years ago

brennanbatalla commented 4 years ago

I am not sure if this exists, but I was looking through the code and was unable to find a callback when you click on a file or folder that returns the file object.

klm-lab commented 4 years ago

HI @brennanbatalla

<FileBrowser onSelectFile={this.handleSelectFile} onSelectFolder={this.handleSelectFolder} />

vinicvaz commented 4 years ago

Hello. I need to get the path to a selected folder or file. onSelectFile is working fine but onSelectFolder event is returning undefined, any sugestions please? Thanks

harsh-tamr commented 3 years ago

Duplicates: https://github.com/uptick/react-keyed-file-browser/issues/143

harsh-tamr commented 3 years ago

Ok looking at the code I've discovered how the onSelect callback works. If you files look like /a/b/c.txt, /a/b/d.txt, then you will get undefined for the folder calls because no folders have been defined.

If you have /a/, a/b/, /a/b/c.txt, /a/b/d.txt then you will not get undefined but the folder you are looking for.

The problem lies in https://github.com/uptick/react-keyed-file-browser/blob/master/src/browser.js#L178 where .find is looking for an exact match.

I would argue that a user should not have to specify all the folders and if a prefix exists, return a select with a folder and no modified, size. I'll create a PR to do just this.

harsh-tamr commented 3 years ago

also solved by https://github.com/uptick/react-keyed-file-browser/pull/149