-
-
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
[Feature Request] Add onRemove props to FileInput so that we can confirm delete action #6998
Comments
Good idea! The core team won't work on it for the foreseeable future, but any third-paty contribution is welcome. |
@fzaninotto |
We've come across the same problem recently too. Until recently, the list of files to be uploaded would get removed after firing a |
@fzaninotto I make it work using confirm dialog with promise handling by the component in the PR. // ... partial hooks code
const [removeImageConfirmEvent, setRemoveFileConfirmEvent] =
useState<any>(null);
const [isRemoveImageModalOpen, setIsRemoveImageModalOpen] = useState(false);
// ... partial render code
<ImageInput
source={PROPERTIES.images}
src="image"
validateFileRemoval={(file: any, record: any) => {
const promise = new Promise<boolean>((_resolve, reject) => {
setRemoveFileConfirmEvent({
fileName: `ReviewImage ID: ${file.id}`,
resolve: async (result: boolean) => {
await Api.deleteReviewImages({ ids: [file.id] });
return _resolve(result);
},
reject,
});
});
setIsRemoveImageModalOpen(true);
return promise.then((result: boolean) => {
// Success Action if you want
});
}}
/>
<FormDataConsumer>
{({
formData, // The whole form data
scopedFormData, // The data for this item of the ArrayInput
getSource, // A function to get the valid source inside an ArrayInput
...rest
}) => (
<SomeConfirmModal
isOpen={isRemoveImageModalOpen}
title="delete image"
message={`${
removeImageConfirmEvent?.fileName} will be deleted`}
onSubmit={() => {
setIsRemoveImageModalOpen(false);
removeImageConfirmEvent?.resolve();
}}
onClose={() => {
setIsRemoveImageModalOpen(false);
removeImageConfirmEvent?.reject();
}}
/>
)}
</FormDataConsumer> |
Fixed by #7003 |
Is your feature request related to a problem? Please describe.
FileInput always delete preview components state. So, we can't implement it to confirm logic though we can remove files immediately before submitting form through options.onRemove prop. Also, we can't handle appropriately errors outer of FileInput if we have removing files' errors, because we can't restore previous ui state having state removed completely before handling errors.
Describe the solution you'd like
A solution is that we could add onRemove props FileInput it is different from options.onRemove for back compatibility and this function allow to return boolean or Promise<boolean>. This function is called before file input state removed, then when this returned value is false, interrupt removing state like this.
Describe alternatives you've considered
Enable to replace all children components of FileInput.
Additional context
The text was updated successfully, but these errors were encountered: