-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[New Feature] Add validateFileRemoval prop to FileInput for handling remove files with confirming #7003
[New Feature] Add validateFileRemoval prop to FileInput for handling remove files with confirming #7003
Conversation
9311360
to
4587a5a
Compare
…_on_remove_with_confirm
Looks pretty good! |
@@ -247,6 +251,208 @@ describe('<FileInput />', () => { | |||
}); | |||
}); | |||
|
|||
describe('should stop to remove file field onSubmitReview return false', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('should stop to remove file field onSubmitReview return false', () => { | |
describe('should call onSubmitReview on removal to allow developers to conditionally prevent the removal', () => { |
@@ -33,6 +33,7 @@ export const FileInput = ( | |||
maxSize, | |||
minSize, | |||
multiple = false, | |||
onSubmitRemove, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call it validateFileRemoval
, and make it return either an empty promise (validated) or a rejected promise (failed).
docs/Inputs.md
Outdated
@@ -278,6 +278,7 @@ To override the style of all instances of `<ImageInput>` using the [material-ui | |||
| `labelSingle` | Optional | `string` | 'ra.input.file. upload_single' | Invite displayed in the drop zone if the input accepts one file | | |||
| `labelMultiple` | Optional | `string` | 'ra.input.file. upload_several' | Invite displayed in the drop zone if the input accepts several files | | |||
| `placeholder` | Optional | `ReactNode` | - | Invite displayed in the drop zone, overrides `labelSingle` and `labelMultiple` | | |||
| `onSubmitRemove` | Optional | `Function` | - | Set remove button click handler. Main difference from options.onRemove is able to cancel to remove the file's list item if it returns false `(file) => boolean \| Promise<boolean>` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the bevaiour that you describe a bit odd. If, ofr any reason, the onSubmitRemove
returns false
, then nothing happens... It's confusing for the end user.
Shouldn't the component show an error notification in that case?
docs/Inputs.md
Outdated
@@ -278,6 +278,7 @@ To override the style of all instances of `<ImageInput>` using the [material-ui | |||
| `labelSingle` | Optional | `string` | 'ra.input.file. upload_single' | Invite displayed in the drop zone if the input accepts one file | | |||
| `labelMultiple` | Optional | `string` | 'ra.input.file. upload_several' | Invite displayed in the drop zone if the input accepts several files | | |||
| `placeholder` | Optional | `ReactNode` | - | Invite displayed in the drop zone, overrides `labelSingle` and `labelMultiple` | | |||
| `onSubmitRemove` | Optional | `Function` | - | Set remove button click handler. Main difference from options.onRemove is able to cancel to remove the file's list item if it returns false `(file) => boolean \| Promise<boolean>` | | |||
| `options` | Optional | `Object` | `{}` | Additional options passed to react-dropzone's `useDropzone()` hook. See [the react-dropzone source](https://github.com/react-dropzone/react-dropzone/blob/master/src/index.js) for details . | | |||
|
|||
`<FileInput>` also accepts the [common input props](./Inputs.md#common-input-props). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to give an example usage for the new prop (kind of what you added to the GitHub issue)
}); | ||
it('error occurs', async done => { | ||
const onSubmit = jest.fn(); | ||
// NOTE: We couldn't handle UnhandledPromiseRejection and make |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fixed by the approach I suggest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is no longer needed thanks to your suggestion. It is enough only to test when throwing exception and it is now already implemented.
…_on_remove_with_confirm
Co-authored-by: Francois Zaninotto <fzaninotto@gmail.com>
…kow/react-admin into feat/6998_on_remove_with_confirm
…n cancel removal action using promise
c9a38a7
to
4399a1d
Compare
4399a1d
to
f0fc51c
Compare
f0fc51c
to
b1df2c8
Compare
@fzaninotto |
…_on_remove_with_confirm
@fzaninotto |
Thanks! |
closes #6998
Add onSubmitRemove prop to FileInput for handling remove files with confirming.
We can add confirm process with immediately removing files cases.
See the detail in #6998.