AppliedMathematicsANU / plexus-form

A dynamic form component for react using JSON-Schema.
MIT License
134 stars 31 forks source link

Rethink file uploads #10

Closed odf closed 9 years ago

odf commented 10 years ago

I am not too happy with the way file uploads currently work, especially the fact that FileField instances need to call makeFieldset and the haphazard mix of user-defined and implied properties for upload elements. Maybe it would be cleaner to have a separate element type x-upload (prefixed because it is not part of json-schema) that is treated like a primitive type.

bebraw commented 9 years ago

On general level it could be handy if it was possible to implement custom types and renderers for them. Maybe this is possible already.

odf commented 9 years ago

Yes, it's possible to define per-field custom handlers, and one can also abstract the necessary boilerplate using JSON-Schema's references. I've found that this works really nicely for things like file uploads. So I think I'll probably rip out the built-in file upload mechanism and update the example code to use a simple custom handler for uploading files.

bebraw commented 9 years ago

Cool. That sounds like a good idea.

I guess you could push each type/renderer pair out of core into separate modules if you wanted to. That would improve the structure of the project but you would need to setup a build.

odf commented 9 years ago

I agree that it could be useful to separate those out.

bebraw commented 9 years ago

Do you want me to give it a go?

I would set up a build using Webpack. There would be extra step before publishing a release (need to update the dist version, i guess there's a prepublish hook to achieve the same but then the dist won't be at repo, just NPM).

odf commented 9 years ago

Sure, knock yourself out! I already have a Webpack-based setup for a library that needs a build step here: https://github.com/AppliedMathematicsANU/plexus-csp. I'll probably switch that over from Regenerator to Babel the next time I use it, since I'm fairly keen to start using ES6 goodies. I usually don't put the compiled code into the repo, but I'm not fundamentally opposed to it.

odf commented 9 years ago

I'd really like to deprecate the build-in file uploader soon and maybe put example code for a very simple user-defined uploader into the documentation. Any objections?

bebraw commented 9 years ago

Nope, sounds good!

odf commented 9 years ago

Done! I've added a deprecation warning when this feature is used, removed the file upload part from the demo and changed the user-defined input component example in the readme from a mouse position tracer to a (very simplistic) file uploader. I reckon I'll leave the file field code in for v0.1.1, just in case, and remove it in v0.1.2.