marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.89k stars 5.23k forks source link

ReferenceOneField emptyContent instead of emptyText #10185

Open devcloud777 opened 1 month ago

devcloud777 commented 1 month ago

Is your feature request related to a problem? Please describe. In a many to many scenario where I have partner => channelPartner => paymentChannel tables.

channelPartner table stores additional information about the related records like commission rates.

I'm listing all the paymentChannels in the edit page of partner. In case there's no record in channelPartner which links these 2 records I want it to navigate to the create page of channelPartner with the foreignKeys are prefilled.

Describe the solution you'd like

ReferenceOneField links to edit page of the referenced resource by default which is great. But if there's no referenced record I want to create a record. If I could add a link to create page on empty records that'd be simple to implement this feature. Something like this:

function(){
return(
 <Edit resource={'partner'}>
            <SimpleForm>
                <TextInput source="name"/>

                <ListBase resource={"paymentChannel"}>
                    <Datagrid >
                        <TextField source="name"/>
                        {/*If there's no record in the junction table (channelPartner), I want to link to create page */}
                        <ReferenceOneField reference={"channelPartner"} target={"paymentChannelId"} label={'Deposit Commision'}
                                           //This would be great
                                           emptyContent={<Button to={'channelPartner/create'}/>}

                        />
                    </Datagrid>
                </ListBase>
            </SimpleForm>
        </Edit>
        )
        }

Describe alternatives you've considered I'm still exploring. Not found a solution yet.

djhi commented 1 month ago

Great idea! Can you open a pull request? This should target the next branch

devcloud777 commented 1 month ago

Actually it's only a type issue. I could still pass a component to emptyText. So probably just the naming and type should be changed.

I really like this library, so I'd like to contribute. I'll try sparing some time and create a pull request.