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

[New Feature] Add validateFileRemoval prop to FileInput for handling remove files with confirming #7003

Merged
merged 13 commits into from
Jan 18, 2022

Conversation

tkow
Copy link

@tkow tkow commented Dec 16, 2021

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.

@vercel vercel bot temporarily deployed to Preview – react-admin December 16, 2021 12:22 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook December 16, 2021 12:22 Inactive
@tkow tkow force-pushed the feat/6998_on_remove_with_confirm branch from 9311360 to 4587a5a Compare December 16, 2021 12:27
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook December 16, 2021 12:27 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin December 16, 2021 12:30 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin December 16, 2021 12:58 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook December 16, 2021 12:58 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook December 16, 2021 13:01 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin December 16, 2021 13:06 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin December 16, 2021 13:24 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook December 16, 2021 13:24 Inactive
@tkow tkow changed the title [New Feature] Add onSubmitRemote prop to FileInput for handling remove files with confirming [New Feature] Add onSubmitRemove prop to FileInput for handling remove files with confirming Jan 5, 2022
@WiXSL
Copy link
Contributor

WiXSL commented Jan 10, 2022

Looks pretty good!

@@ -247,6 +251,208 @@ describe('<FileInput />', () => {
});
});

describe('should stop to remove file field onSubmitReview return false', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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,
Copy link
Member

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).

packages/ra-ui-materialui/src/input/FileInput.tsx Outdated Show resolved Hide resolved
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>` |
Copy link
Member

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).
Copy link
Member

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
Copy link
Member

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

Copy link
Author

@tkow tkow Jan 12, 2022

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.

@vercel vercel bot temporarily deployed to Preview – react-admin January 12, 2022 18:32 Inactive
@vercel vercel bot temporarily deployed to Preview – react-admin-storybook January 12, 2022 18:32 Inactive
@tkow tkow force-pushed the feat/6998_on_remove_with_confirm branch from f0fc51c to b1df2c8 Compare January 12, 2022 20:38
@vercel vercel bot temporarily deployed to Preview – react-admin January 12, 2022 20:41 Inactive
@tkow
Copy link
Author

tkow commented Jan 12, 2022

@fzaninotto
I have fixed almost problems you have reviewed. Thank you.

@tkow
Copy link
Author

tkow commented Jan 18, 2022

@fzaninotto
Could you check when you have time?

@fzaninotto fzaninotto merged commit f17c490 into marmelab:next Jan 18, 2022
@fzaninotto
Copy link
Member

Thanks!

@fzaninotto fzaninotto added this to the 4.0.0-alpha.2 milestone Jan 18, 2022
@WiXSL WiXSL changed the title [New Feature] Add onSubmitRemove prop to FileInput for handling remove files with confirming [New Feature] Add validateFileRemoval prop to FileInput for handling remove files with confirming Jan 25, 2022
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