-
-
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
Add optional target property in ReferenceArrayField component #3725
Comments
Indeed, the reference input and fields only use This is a strong opinionated choice from the core team as it makes a lot of things far easier (cache, optimistic, filters, etc) Any PR are welcome, but I guess this will not be an easy one. 📣 If someone does have a workaround for this use case, feel free to share! |
I'm closing since the core team won't implement that suggestion, but comments are still open. |
Here is my workaround: import keyBy from 'lodash/keyBy'
import { Loading, Datagrid, Query, TextField, Pagination } from 'react-admin'
const Tags = ({ tagNames }) => {
const [page, setPage] = useState(1)
const perPage = 50
return (
<Query
type="GET_LIST"
resource="tags"
payload={{
pagination: { page, perPage },
sort: { field: 'id', order: 'ASC' },
filter: { name: tagNames },
}}
>
{({ data, total, loading, error }) => {
if (loading) {
return <Loading />
}
if (error) {
return <p>ERROR: {error}</p>
}
return (
<>
<Datagrid
data={keyBy(data, 'id')}
ids={data.map(({ id }) => id)}
currentSort={{ field: 'id', order: 'ASC' }}
>
<TextField source="id" />
<TextField source="name" />
</Datagrid>
<Pagination
page={page}
perPage={perPage}
setPage={setPage}
total={total}
/>
</>
)
}}
</Query>
)
} I use it in the edit form: const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm>
<Tags tagNames={props.record.tagNames} />
</SimpleForm>
</Edit>
) Note: it's quite hard to find how to use |
We would love to. Any chance you leverage what you learned and start documenting it ? |
Is your feature request related to a problem? Please describe.
I need to link 2 resources but the link does not pass through the id of a resource.
Describe the solution you'd like
Let's consider 2 resources:
Tag(id: number, name: string)
Post(id: number, tagNames: string[]).
Note that the Post resource does not link to Tag via the id of the tag but the name of the tag.
I would like to be able to specify the target property when using ReferenceArrayField:
The text was updated successfully, but these errors were encountered: