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

Allow Image Removal through Parent Component. #5282

Closed
talivodworks opened this issue Sep 21, 2020 · 4 comments
Closed

Allow Image Removal through Parent Component. #5282

talivodworks opened this issue Sep 21, 2020 · 4 comments

Comments

@talivodworks
Copy link

talivodworks commented Sep 21, 2020

Is your feature request related to a problem? Please describe.
I have a use case, let say I want to upload a file and for some reasons my onDrop function has gone into error state e.g Server responded with error. Now the Image thumbnail is still in the preview list. There is no way I can remove the file from the list or Identify that an error has occurred for that.

import React, {useState} from 'react';
import { ImageInput, ImageField } from 'react-admin';



export const UploadImage = (props) => {
	const [imageId, setImageId] = useState();
	return (
		<ImageInput
			accept="image/*"
			source="profileImage"
			reference="user"
			multiple={true}
			options={
				{
					onDrop: async ([file]) => {
						// Assume this will fail
						try {
							const id = await uploadToServer(file)
							setImageId(id);
						} catch (e) {
							// Remove Image Preview Here...
						}
					}
				}
			}
		>
			<ImageField source="profileImage" />
		</ImageInput>
	)
}

Describe the solution you'd like
I have seen this issue ImageInput keeps adding imagest to state, this works fine. It would be great if we have a way to trigger the removal process through JS (without clicking the remove button)

Describe alternatives you've considered
I can't think of any alternative solution to this issue as the state which is keeping the track of file items is maintain inside the FileInput.tsx

and there is no way to change that state.

@djhi
Copy link
Collaborator

djhi commented Sep 21, 2020

Please follow the issue template

@talivodworks
Copy link
Author

Please follow the issue template

Before I was not sure which template to follow that is why i tried my best to explain this in well formatted way. But I believe it is more of a feature request so I have followed the new feature template.

Thank you.

@Luwangel
Copy link
Contributor

You're right, it's between a feature and an issue. So I'm labelling this issue as an enhancement.

Have a good day,
Adrien

@WiXSL
Copy link
Contributor

WiXSL commented Jan 28, 2022

master branch is feature-freeze, but a solution for this has been implemented already in version 4 #7003.
So I'm closing this feature request as it has been implemented.

@WiXSL WiXSL closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants