React-admin: Allow Image Removal through Parent Component.

Created on 21 Sep 2020  路  3Comments  路  Source: marmelab/react-admin

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.

enhancement

Most helpful comment

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.

All 3 comments

Please follow the issue template

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

9747749366 picture 9747749366  路  3Comments

ericwb picture ericwb  路  3Comments

kopax picture kopax  路  3Comments

ilaif picture ilaif  路  3Comments

kikill95 picture kikill95  路  3Comments