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

Feature/custom get data transfer items #616

Conversation

MarinaZadoyanchuk
Copy link
Collaborator

@MarinaZadoyanchuk MarinaZadoyanchuk commented Jun 1, 2018

What kind of change does this PR introduce?

  • bugfix
  • feature
  • refactoring / style
  • build / chore
  • documentation

Did you add tests for your changes?

  • Yes, my code is well tested
  • Not relevant

If relevant, did you update the documentation?

  • Yes, I've updated the documentation
  • Not relevant

Summary

Here is a very basic idea of how plugin interface could be implemented (as was suggested by @okonet in #609), basically we are giving the user an ability to specify it's own function getDataTransferItems instead of default one. Would be great to hear some thoughts and suggestions on this.

Does this PR introduce a breaking change?
No

Closes #609

@Nodman Nodman removed the question label Jun 1, 2018
@okonet
Copy link
Collaborator

okonet commented Jun 2, 2018

Great work on this! I really like how it's shaping.

  • Please reformat the code so CI is green. It should have happen during the pre-commit hook. Did you skip it?
  • The documentation needs to be updated to explain the change and we'll need example with reading directories.

@okonet
Copy link
Collaborator

okonet commented Jun 2, 2018

Inviting @quarklemotion to review and comment. Also, it would be great to sync the release of the directories reader to fit the API.

fileList.forEach(file => {
if (!disablePreview) {
try {
file.preview = window.URL.createObjectURL(file) // eslint-disable-line no-param-reassign
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd propose to create an additional "plugin" called getDataTransferItemsWithPreview and move this code there. Ideally the core of this library should be not concerned about anything but drag'n'drop.

I'd even go with a breaking change there since I believe most users don't need preview generation by default and it's a runtime cost and a potential memory leak.

Copy link
Collaborator

@Nodman Nodman Jun 6, 2018

Choose a reason for hiding this comment

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

It’s not clear to me about how getDataTransferItemsWithPreview should be separated into an additional plugin. In the previous implementation, we use to have disablePreview prop which would enable/disable preview generation, so if we will take this code away, how would the user be able to generate previews with a plugin? I mean, importing plugin and passing it as getDataTransferItems will replace original function with all the core functionality, in this case, we should also export default getDataTransferItems plugin so the user can make a composition of those, or maybe add an additional prop that will take function to invoke with file list after getDataTransferItems ?

Sorry if I am missing something!

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Nodman I think exporting the default implementation + additional plugins is a way to go. Composition should be the right way of doing this. We should also add examples of how to achieve this.

@@ -585,5 +606,6 @@ Dropzone.defaultProps = {
disableClick: false,
multiple: true,
maxSize: Infinity,
minSize: 0
minSize: 0,
getDataTransferItems: defaultGetDataTransferItem
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a signature of the function here as a JSDoc to make it easier for plugins authors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have described it in the propTypes section, should I describe it here too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry I thought that is the propTypes. No, the way you did it is perfect! Thanks!

@quarklemotion
Copy link

quarklemotion commented Jun 4, 2018

@okonet this implementation makes sense to me. I like the use of Promise.resolve(this.props.getDataTransferItems(evt)) which allows for both synchronous and async implementations of props.getDataTransferItems. With the implementation in this pull request, I don't think there are any changes required to html5-file-selector to support this plugin interface - the getDroppedOrSelectedFiles(event) exported function can be used as the getDataTransferItems prop. I'm happy to add a new exported function getDroppedOrSelectedFilesWithPreview(event) to the file selector module if everyone thinks that is the best place to locate this wrapper function to provide preview support?

@okonet
Copy link
Collaborator

okonet commented Jun 4, 2018

I think the preview plugin should live in this repo. I’d even say your plugin should probably too. I’m not sure how much overhead setting up multiple packages would be, though. Yarn workspaces should solve it, right?

@okonet okonet mentioned this pull request Jun 5, 2018
9 tasks
@quarklemotion
Copy link

@okonet Ah, I see - I think that could make sense to convert react-dropzone to multi-package. Were you thinking that the folder drop plugin package would be a small wrapper of html5-file-selector, or html5-file-selector would move into the react-dropzone repo? One thing to consider is that the file selector module was built to support both dropzones and file input fields, whereas react-dropzone only cares about the dropzone support. There are other projects using the file selector module, and I want to make sure they can continue to use it. As for multi-package setup, I haven't used yarn workspaces before, only lerna, but happy to help with this effort!

@okonet
Copy link
Collaborator

okonet commented Jun 5, 2018

Totally makes sense to me. Let’s keep thing simple for now and add your module to documentation.

@codecov
Copy link

codecov bot commented Jun 5, 2018

Codecov Report

Merging #616 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #616      +/-   ##
==========================================
+ Coverage   99.01%   99.02%   +<.01%     
==========================================
  Files           3        3              
  Lines         204      205       +1     
  Branches       59       59              
==========================================
+ Hits          202      203       +1     
  Misses          2        2
Impacted Files Coverage Δ
src/utils/index.js 96.42% <ø> (ø) ⬆️
src/index.js 99.42% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28526fe...de79247. Read the comment docs.

@okonet
Copy link
Collaborator

okonet commented Jun 15, 2018

I think the most important part we're missing is the documentation. Can you please add it and we could merge it as is. After that we could extract bits for preview.

@MarinaZadoyanchuk
Copy link
Collaborator Author

Ok, I'm going to write a usage of getDataTransferItems soon.

@okonet
Copy link
Collaborator

okonet commented Jun 19, 2018

@MarinaZadoyanchuk thanks!

@dejongch
Copy link

Any update on when this might be merged in?

@arunchouhan163
Copy link

Please merge this PR. ASAP.

Thanks.

@okonet
Copy link
Collaborator

okonet commented Aug 6, 2018

Since this one is stalling, I decided to proceed and merge it. Anyone wants to work on the documentation? @quarklemotion do you want to add an example?

@ralexrdz
Copy link

I'm not succeding implementing getDataTransferItems. Do you have a example I can follow?

@rolandjitsu
Copy link
Collaborator

@ralexrdz here you go: using-third-party-plugins.

@ralexrdz
Copy link

@rolandjitsu thanks a lot. It was the Promise / async I was missing ;)

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

Successfully merging this pull request may close these issues.

Introduce plugin interface for resolving files from drop event
8 participants