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

[RFR] FileInput #684

Merged
merged 2 commits into from
May 30, 2017
Merged

[RFR] FileInput #684

merged 2 commits into from
May 30, 2017

Conversation

djhi
Copy link
Contributor

@djhi djhi commented May 19, 2017

  • Refactored the existing ImageInput into FileInput (but kept an exported ImageInput component in order to not break backward compatibilty)
  • Added a new FileField component (similar to ImageField but displays a link instead of an image)
  • FileField and ImageField can handle array sources now
  • FileField and ImageField now have access to the raw File object for newly dropped files (Fix ImageInput doesn't pass useful properties to children #680)
  • Cleans up URLs generated for preview (Fixes ImageInput not cleaning up object urls #681)
  • Tests

@djhi djhi changed the title [WIP] FileInput [RFR] FileInput May 19, 2017
@djhi djhi changed the title [RFR] FileInput [WIP] FileInput May 19, 2017
@djhi djhi changed the title [WIP] FileInput [RFR] FileInput May 22, 2017
Copy link
Contributor

@jpetitcolas jpetitcolas left a comment

Choose a reason for hiding this comment

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

Shouldn't we keep the ImageInputPreview and deprecating it the React way, triggering a warning in the console?

docs/Fields.md Outdated

## `<FileField>`

If you need to display an file provided by your API, you can use the `<FileField />` component:
Copy link
Contributor

Choose a reason for hiding this comment

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

s/an file/a file/

docs/Inputs.md Outdated
This component accepts all [react-dropzone properties](https://github.com/okonet/react-dropzone#features), in addition to those of admin-on-rest. For instance, if you need to upload several images at once, just add the `multiple` DropZone attribute to your `<ImageInput />` field.
Writing a custom field component for displaying the current value(s) is easy: it's a standard [field](./Fields.html#writing_your_own_field_component).

When receiving **new** files, `ImageInput` will add a `rawFile` property to the object passed as the `record` prop of children. This `rawFile` will the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance of the newly added file. This can be useful to display informations about size or mimetype inside a custom field.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/will the [File]/is the [File]/

file: {
upload_several: 'Drop some files to upload, or click to select one.',
upload_single: 'Drop a file to upload, or click to select it.',
},
image: {
upload_several: 'Drop some files to upload, or click to select one.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps can we rename files to pictures here?

@@ -25,6 +25,10 @@ export default {
dashboard: 'Dashboard',
},
input: {
file: {
upload_several: 'Drop some files to upload, or click to select one.',
Copy link
Contributor

Choose a reason for hiding this comment

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

import PropTypes from 'prop-types';
import get from 'lodash.get';

export const FileField = ({ elStyle = { display: 'inline-block' }, record, source, title, src }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use defaultProps instead of default values.


constructor(props) {
super(props);
console.log({ props });
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug spotted

componentWillUnmount() {
const { file } = this.props;

if (file && file.preview && window && window.URL && window.URL.revokeObjectURL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can prevent of all these checks as support seems quite nice: https://developer.mozilla.org/fr/docs/Web/API/URL/revokeObjectURL

@djhi
Copy link
Contributor Author

djhi commented May 24, 2017

Is the ImageInputPreview meant to be used directly ?

@jpetitcolas
Copy link
Contributor

@djhi: we didn't encourage it in the documentation, yet some devs may use it. So, let's deprecate it the soft way for now. :)

@djhi
Copy link
Contributor Author

djhi commented May 24, 2017

Ok, I'll try to keep it as I did for the ImageInput then

- [x] Refactored the existing ImageInput into FileInput (but kept an exported ImageInput component in order to not break backward compatibilty)
- [x] Added a new `FileField` component (similar to `ImageField` but displays a link instead of an image)
- [x] `FileField` and `ImageField` can handle array sources now
- [x] `FileField` and `ImageField` now have access to the raw [File](https://developer.mozilla.org/en/docs/Web/API/File) object for newly dropped files (Fix #680)
- [x] Cleans up URLs generated for preview (Fixes #681)
- [x] Tests
docs/Inputs.md Outdated

Writing a custom field component for displaying the current value(s) is easy: it's a standard [field](./Fields.html#writing_your_own_field_component).

When receiving **new** files, `FileInput` will add a `rawFile` property to the object passed as the `record` prop of children. This `rawFile` will the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance of the newly added file. This can be useful to display informations about size or mimetype inside a custom field.
Copy link
Member

Choose a reason for hiding this comment

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

s/This rawFile will the/This rawFile is the/

docs/Inputs.md Outdated

The `FileInput` component accepts all [react-dropzone properties](https://github.com/okonet/react-dropzone#features), in addition to those of admin-on-rest. For instance, if you need to upload several files at once, just add the `multiple` DropZone attribute to your `<FileInput />` field.

If the default Dropzone label don't fit with your need, you can pass a `placeholder` attribute to overwrite it. The attribute can be anything React can render (`PropTypes.node`):
Copy link
Member

Choose a reason for hiding this comment

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

s/the default Dropzone label don't fit/the default Dropzone label doesn't fit/

@fzaninotto fzaninotto merged commit a165928 into next May 30, 2017
@fzaninotto fzaninotto modified the milestones: 1.1.1, 1.2.0 May 30, 2017
@djhi djhi mentioned this pull request Jun 8, 2017
@fzaninotto fzaninotto deleted the file-inputs branch September 13, 2017 13:18
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.

3 participants