Skip to content

Commit 8eea15a

Browse files
committed
update fields
1 parent a2dffea commit 8eea15a

File tree

10 files changed

+389
-999
lines changed

10 files changed

+389
-999
lines changed

docs_headless/src/content/docs/fields/Fields.md

Lines changed: 30 additions & 502 deletions
Large diffs are not rendered by default.

docs_headless/src/content/docs/fields/FieldsForRelationships.md

Lines changed: 172 additions & 216 deletions
Large diffs are not rendered by default.

docs_headless/src/content/docs/fields/ReferenceArrayFieldBase.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
---
22
layout: default
3-
title: "The ReferenceArrayFieldBase Component"
3+
title: "<ReferenceArrayFieldBase>"
44
storybook_path: ra-core-fields-referencearrayfieldbase--basic
55
---
66

7-
# `<ReferenceArrayFieldBase>`
8-
97
Use `<ReferenceArrayFieldBase>` to display a list of related records, via a one-to-many relationship materialized by an array of foreign keys.
108

11-
`<ReferenceArrayFieldBase>` fetches a list of referenced records (using the `dataProvider.getMany()` method), and puts them in a [`ListContext`](./useListContext.md). This component is headless, and its children need to use the data from this context to render the desired ui.
12-
13-
**Tip**: For a rendering a list of chips by default, use [the `<ReferenceArrayField>` component](./ReferenceArrayField.md) instead.
9+
`<ReferenceArrayFieldBase>` fetches a list of referenced records (using the `dataProvider.getMany()` method), and puts them in a [`ListContext`](../list/useListContext.md). This component is headless, and its children need to use the data from this context to render the desired ui.
1410

1511
**Tip**: If the relationship is materialized by a foreign key on the referenced resource, use [the `<ReferenceManyFieldBase>` component](./ReferenceManyFieldBase.md) instead.
1612

@@ -45,7 +41,7 @@ A typical `post` record therefore looks like this:
4541
In that case, use `<ReferenceArrayFieldBase>` to display the post tag names as a list of chips, as follows:
4642

4743
```jsx
48-
import { ListBase, ListIterator, ReferenceArrayFieldBase } from 'react-admin';
44+
import { ListBase, ListIterator, ReferenceArrayFieldBase } from 'ra-core';
4945

5046
export const PostList = () => (
5147
<ListBase>
@@ -81,7 +77,7 @@ const TagList = (props: { children: React.ReactNode }) => {
8177
8278
`<ReferenceArrayFieldBase>` fetches the `tag` resources related to each `post` resource by matching `post.tag_ids` to `tag.id`.
8379
84-
You can change how the list of related records is rendered by passing a custom child reading the `ListContext` (e.g. a [`<DataTable>`](./DataTable.md)) or a render function prop. See the [`children`](#children) and the [`render`](#render) sections for details.
80+
You can change how the list of related records is rendered by passing a custom child reading the `ListContext` (e.g. a `<DataTable>` component) or a render function prop. See the [`children`](#children) and the [`render`](#render) sections for details.
8581
8682
## Props
8783
@@ -164,7 +160,6 @@ Alternatively to `children`, you can pass a `render` function prop to `<Referenc
164160
165161
For instance, to render only tags that are 'published', you can use the following code:
166162
167-
{% raw %}
168163
```jsx
169164
<ReferenceArrayFieldBase
170165
label="Tags"
@@ -173,7 +168,6 @@ For instance, to render only tags that are 'published', you can use the followin
173168
filter={{ is_published: true }}
174169
/>
175170
```
176-
{% endraw %}
177171
178172
## `perPage`
179173
@@ -187,15 +181,13 @@ For instance, to limit the display of related records to 10, you can use the fol
187181
188182
## `queryOptions`
189183
190-
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](./useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
184+
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](../data-fetching/useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
191185
192-
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
186+
For instance, to pass [a custom `meta`](../data-fetching/Actions.md#meta-parameter):
193187
194-
{% raw %}
195188
```jsx
196189
<ReferenceArrayFieldBase queryOptions={{ meta: { foo: 'bar' } }} />
197190
```
198-
{% endraw %}
199191
200192
## `reference`
201193
@@ -215,7 +207,6 @@ By default, the related records are displayed in the order in which they appear
215207
216208
For instance, to sort tags by title in ascending order, you can use the following code:
217209
218-
{% raw %}
219210
```jsx
220211
<ReferenceArrayFieldBase
221212
label="Tags"
@@ -224,4 +215,3 @@ For instance, to sort tags by title in ascending order, you can use the followin
224215
sort={{ field: 'title', order: 'ASC' }}
225216
/>
226217
```
227-
{% endraw %}

docs_headless/src/content/docs/fields/ReferenceFieldBase.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
---
2-
layout: default
3-
title: "The ReferenceFieldBase Component"
4-
storybook_path: ra-core-controller-field-referencefieldbase--basic
2+
title: "<ReferenceFieldBase>"
53
---
64

7-
# `<ReferenceFieldBase>`
8-
95
`<ReferenceFieldBase>` is useful for displaying many-to-one and one-to-one relationships, e.g. the details of a user when rendering a post authored by that user.
10-
`<ReferenceFieldBase>` is a headless component, handling only the logic. This allows to use any UI library for the render. For a version based on MUI see [`<ReferenceField>`](/ReferenceField.html)
6+
`<ReferenceFieldBase>` is a headless component, handling only the logic. This allows to use any UI library for the render. For a version based on MUI see [`<ReferenceField>`](../components/ReferenceField.md)
117

128
## Usage
139

@@ -27,17 +23,18 @@ For instance, let's consider a model where a `post` has one author from the `use
2723
In that case, use `<ReferenceFieldBase>` to display the post's author as follows:
2824

2925
```jsx
30-
import { Show, SimpleShowLayout, ReferenceField, TextField, RecordRepresentation } from 'react-admin';
26+
import { ShowBase, ReferenceFieldBase } from 'ra-core';
27+
import { TextField } from './TextField';
3128

3229
export const PostShow = () => (
33-
<Show>
34-
<SimpleShowLayout>
30+
<ShowBase>
31+
<div>
3532
<TextField source="title" />
3633
<ReferenceFieldBase source="user_id" reference="users" >
3734
<UserView />
3835
</ReferenceFieldBase>
39-
</SimpleShowLayout>
40-
</Show>
36+
</div>
37+
</ShowBase>
4138
);
4239

4340
export const UserView = () => {
@@ -55,7 +52,7 @@ export const UserView = () => {
5552
};
5653
```
5754

58-
`<ReferenceFieldBase>` fetches the data, puts it in a [`RecordContext`](./useRecordContext.md), and its up to its children to handle the rendering by accessing the `ReferencingContext` using the `useReferenceFieldContext` hook.
55+
`<ReferenceFieldBase>` fetches the data, puts it in a [`RecordContext`](../common/useRecordContext.md), and its up to its children to handle the rendering by accessing the `ReferencingContext` using the `useReferenceFieldContext` hook.
5956

6057
It uses `dataProvider.getMany()` instead of `dataProvider.getOne()` [for performance reasons](#performance). When using several `<ReferenceFieldBase>` in the same page (e.g. in a `<DataTable>`), this allows to call the `dataProvider` once instead of once per row.
6158

@@ -78,7 +75,7 @@ You can pass any component of your own as child, to render the related records a
7875
You can access the list context using the `useReferenceFieldContext` hook.
7976

8077
```tsx
81-
import { ReferenceFieldBase } from 'react-admin';
78+
import { ReferenceFieldBase } from 'ra-core';
8279

8380
export const UserView = () => {
8481
const { error, isPending, referenceRecord } = useReferenceFieldContext();
@@ -146,9 +143,8 @@ You can customize this error message by passing a React element or a string to t
146143

147144
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](./useGetOne.md#aggregating-getone-calls) that fetches the referenced record.
148145

149-
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
146+
For instance, to pass [a custom `meta`](../data/Actions.md#meta-parameter):
150147

151-
{% raw %}
152148
```jsx
153149
<ReferenceFieldBase
154150
source="user_id"
@@ -159,7 +155,6 @@ For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
159155
...
160156
</ReferenceFieldBase>
161157
```
162-
{% endraw %}
163158

164159
## `reference`
165160

@@ -215,14 +210,12 @@ By default, when used in a `<Datagrid>`, and when the user clicks on the column
215210

216211
## Performance
217212

218-
<iframe src="https://www.youtube-nocookie.com/embed/egBhWqF3sWc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen style="aspect-ratio: 16 / 9;width:100%;margin-bottom:1em;"></iframe>
219-
220-
When used in a `<DataTable>`, `<ReferenceFieldBase>` fetches the referenced record only once for the entire table.
213+
When used in a list, `<ReferenceFieldBase>` fetches the referenced record only once for the entire table.
221214

222215
For instance, with this code:
223216

224217
```jsx
225-
import { ListBase, ListIterator, ReferenceFieldBase } from 'react-admin';
218+
import { ListBase, ListIterator, ReferenceFieldBase } from 'ra-core';
226219

227220
export const PostList = () => (
228221
<ListBase>
@@ -265,7 +258,6 @@ When you know that a page will contain a `<ReferenceFieldBase>`, you can configu
265258

266259
For example, the following code prefetches the authors referenced by the posts:
267260

268-
{% raw %}
269261
```jsx
270262
const PostList = () => (
271263
<ListBase queryOptions={{ meta: { prefetch: ['author'] } }}>
@@ -282,15 +274,14 @@ const PostList = () => (
282274
</ListBase>
283275
);
284276
```
285-
{% endraw %}
286277

287-
**Note**: For prefetching to function correctly, your data provider must support [Prefetching Relationships](./DataProviders.md#prefetching-relationships). Refer to your data provider's documentation to verify if this feature is supported.
278+
**Note**: For prefetching to function correctly, your data provider must support [Prefetching Relationships](../data/DataProviders.md#prefetching-relationships). Refer to your data provider's documentation to verify if this feature is supported.
288279

289280
**Note**: Prefetching is a frontend performance feature, designed to avoid flickers and repaints. It doesn't always prevent `<ReferenceFieldBase>` to fetch the data. For instance, when coming to a show view from a list view, the main record is already in the cache, so the page renders immediately, and both the page controller and the `<ReferenceFieldBase>` controller fetch the data in parallel. The prefetched data from the page controller arrives after the first render of the `<ReferenceFieldBase>`, so the data provider fetches the related data anyway. But from a user perspective, the page displays immediately, including the `<ReferenceFieldBase>`. If you want to avoid the `<ReferenceFieldBase>` to fetch the data, you can use the React Query Client's `staleTime` option.
290281

291282
## Access Control
292283

293-
If your authProvider implements [the `canAccess` method](./AuthProviderWriting.md#canaccess), React-Admin will verify whether users have access to the Show and Edit views.
284+
If your authProvider implements [the `canAccess` method](../auth/AuthProviderWriting.md#canaccess), React-Admin will verify whether users have access to the Show and Edit views.
294285

295286
For instance, given the following `ReferenceFieldBase`:
296287

docs_headless/src/content/docs/fields/ReferenceManyCount.md

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)