Skip to content

Commit 02a957a

Browse files
committed
Add documentation
1 parent 32af617 commit 02a957a

File tree

9 files changed

+277
-26
lines changed

9 files changed

+277
-26
lines changed

docs/DataTable.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ Each `<DataTable.Col>` defines one column of the table: its `source` (used for s
5353
| `empty` | Optional | Element | `<Empty>` | The component to render when the list is empty. |
5454
| `expand` | Optional | Element | | The component rendering the expand panel for each row. |
5555
| `expandSingle` | Optional | Boolean | `false` | Whether to allow only one expanded row at a time. |
56-
| `head` | Optional | Element | `<DataTable Header>` | The component rendering the table header. |
56+
| `head` | Optional | Element | `<DataTable Header>` | The component rendering the table header. |
5757
| `hiddenColumns` | Optional | Array | `[]` | The list of columns to hide by default. |
5858
| `foot` | Optional | Element | | The component rendering the table footer. |
5959
| `hover` | Optional | Boolean | `true` | Whether to highlight the row under the mouse. |
6060
| `isRowExpandable` | Optional | Function | `() => true` | A function that returns whether a row is expandable. |
6161
| `isRowSelectable` | Optional | Function | `() => true` | A function that returns whether a row is selectable. |
62+
| `offline` | Optional | Element | `<Offline>` | The content rendered to render when data could not be fetched because of connectivity issues. |
6263
| `rowClick` | Optional | mixed | | The action to trigger when the user clicks on a row. |
6364
| `rowSx` | Optional | Function | | A function that returns the `sx` prop to apply to a row. |
6465
| `size` | Optional | `'small'` or `'medium'` | `'small'` | The size of the table. |
@@ -754,6 +755,38 @@ export const PostList = () => (
754755
```
755756
{% endraw %}
756757

758+
## `offline`
759+
760+
It's possible that a `<DataTable>` will have no records to display because of connectivity issues. In that case, `<DataTable>` will display a message indicating data couldn't be fetched.
761+
762+
You can customize this message via react-admin's [translation system](./Translation.md), by setting a custom translation for the `ra.notification.offline` key.
763+
764+
```tsx
765+
const messages = {
766+
ra: {
767+
notification: {
768+
offline: "No network. Data couldn't be fetched.",
769+
}
770+
}
771+
}
772+
```
773+
774+
If you need to go beyond text, pass a custom element as the `<DataTable offline>` prop:
775+
776+
```tsx
777+
const Offline = () => (
778+
<p>No network. Data couldn't be fetched.</p>
779+
);
780+
781+
const BookList = () => (
782+
<List>
783+
<DataTable offline={<Offline />}>
784+
...
785+
</DataTable>
786+
</List>
787+
);
788+
```
789+
757790
## `rowClick`
758791

759792
By default, `<DataTable>` uses the current [resource definition](https://marmelab.com/react-admin/Resource.html) to determine what to do when the user clicks on a row. If the resource has a `show` page, a row click redirects to the Show view. If the resource has an `edit` page, a row click redirects to the Edit view. Otherwise, the row is not clickable.

docs/Datagrid.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Both are [Enterprise Edition](https://react-admin-ee.marmelab.com) components.
5757
| `hover` | Optional | Boolean | `true` | Whether to highlight the row under the mouse. |
5858
| `isRowExpandable` | Optional | Function | `() => true` | A function that returns whether a row is expandable. |
5959
| `isRowSelectable` | Optional | Function | `() => true` | A function that returns whether a row is selectable. |
60+
| `offline` | Optional | Element | `<Offline>` | The content rendered to render when data could not be fetched because of connectivity issues. |
6061
| `optimized` | Optional | Boolean | `false` | Whether to optimize the rendering of the table. |
6162
| `rowClick` | Optional | mixed | | The action to trigger when the user clicks on a row. |
6263
| `rowStyle` | Optional | Function | | A function that returns the style to apply to a row. |
@@ -640,6 +641,26 @@ export const PostList = () => (
640641
```
641642
{% endraw %}
642643

644+
## `offline`
645+
646+
It's possible that a Datagrid will have no records to display because of connectivity issues. In that case, the Datagrid will display a message indicating data couldn't be fetched. This message is translatable and its key is `ra.notification.offline`.
647+
648+
You can customize the content to display by passing a component to the `offline` prop:
649+
650+
```tsx
651+
const CustomOffline = () => <div>No network. Data couldn't be fetched.</div>;
652+
653+
const PostList = () => (
654+
<List>
655+
<Datagrid offline={<CustomOffline />}>
656+
<TextField source="id" />
657+
<TextField source="title" />
658+
<TextField source="views" />
659+
</Datagrid>
660+
</List>
661+
);
662+
```
663+
643664
## `optimized`
644665

645666
When displaying large pages of data, you might experience some performance issues.

docs/Edit.md

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,25 @@ export default App;
6060

6161
You can customize the `<Edit>` component using the following props:
6262

63-
* [`actions`](#actions): override the actions toolbar with a custom component
64-
* [`aside`](#aside): component to render aside to the main content
65-
* `children`: the components that renders the form
66-
* `className`: passed to the root component
67-
* [`component`](#component): override the root component
68-
* [`disableAuthentication`](#disableauthentication): disable the authentication check
69-
* [`emptyWhileLoading`](#emptywhileloading): Set to `true` to return `null` while the edit is loading.
70-
* [`id`](#id): the id of the record to edit
71-
* [`mutationMode`](#mutationmode): switch to optimistic or pessimistic mutations (undoable by default)
72-
* [`mutationOptions`](#mutationoptions): options for the `dataProvider.update()` call
73-
* [`queryOptions`](#queryoptions): options for the `dataProvider.getOne()` call
74-
* [`redirect`](#redirect): change the redirect location after successful creation
75-
* [`resource`](#resource): override the name of the resource to create
76-
* [`sx`](#sx-css-api): Override the styles
77-
* [`title`](#title): override the page title
78-
* [`transform`](#transform): transform the form data before calling `dataProvider.update()`
63+
| Prop | Required | Type | Default | Description |
64+
| ----------------------- | -------- | ------------------------------------- | --------------------- | ------------------------------------------------------------- |
65+
| `actions` | | `ReactNode` | | override the actions toolbar with a custom component |
66+
| `aside` | | `ReactNode` | | component to render aside to the main content |
67+
| `children` | | `ReactNode` | | The components that renders the form |
68+
| `className` | | `string` | | passed to the root component |
69+
| `component` | | `Component` | | override the root component |
70+
| `disableAuthentication` | | `boolean` | | disable the authentication check |
71+
| `emptyWhileLoading` | | `boolean` | | Set to `true` to return `null` while the edit is loading. |
72+
| `id` | | `string | number` | | the id of the record to edit |
73+
| `mutationMode` | | `pessimistic | optimistic | undoable` | | switch to optimistic or pessimistic mutations (undoable by default) |
74+
| `mutationOptions` | | `object` | | options for the `dataProvider.update()` call |
75+
| `offline` | | `ReactNode` | | The content rendered to render when data could not be fetched because of connectivity issues |
76+
| `queryOptions` | | `object` | | options for the `dataProvider.getOne()` call |
77+
| `redirect` | | `string | Function | false` | | change the redirect location after successful creation |
78+
| `resource` | | `string` | | override the name of the resource to create |
79+
| `sx` | | `object` | | Override the styles |
80+
| `title` | | `ReactNode` | | override the page title |
81+
| `transform` | | `Function` | | transform the form data before calling `dataProvider.update()` |
7982

8083
## `actions`
8184

@@ -488,6 +491,36 @@ The default `onError` function is:
488491

489492
**Tip**: If you want to have different failure side effects based on the button clicked by the user, you can set the `mutationOptions` prop on the `<SaveButton>` component, too.
490493

494+
## `offline`
495+
496+
It's possible that a `<Edit>` will have no record to display because of connectivity issues. In that case, `<Edit>` will display a message indicating data couldn't be fetched.
497+
498+
You can customize this message via react-admin's [translation system](./Translation.md), by setting a custom translation for the `ra.notification.offline` key.
499+
500+
```tsx
501+
const messages = {
502+
ra: {
503+
notification: {
504+
offline: "No network. Data couldn't be fetched.",
505+
}
506+
}
507+
}
508+
```
509+
510+
If you need to go beyond text, pass a custom element as the `<Edit offline>` prop:
511+
512+
```tsx
513+
const Offline = () => (
514+
<p>No network. Data couldn't be fetched.</p>
515+
);
516+
517+
const BookEdit = () => (
518+
<Edit offline={<Offline />}>
519+
...
520+
</Edit>
521+
);
522+
```
523+
491524
## `queryOptions`
492525

493526
`<Edit>` calls `dataProvider.getOne()` on mount via react-query's `useQuery` hook. You can customize the options you pass to this hook by setting the `queryOptions` prop.
@@ -498,7 +531,7 @@ This can be useful e.g. to pass [a custom `meta`](./Actions.md#meta-parameter) t
498531
```jsx
499532
import { Edit, SimpleForm } from 'react-admin';
500533

501-
export const PostShow = () => (
534+
export const PostEdit = () => (
502535
<Edit queryOptions={{ meta: { foo: 'bar' } }}>
503536
<SimpleForm>
504537
...

docs/ReferenceArrayInput.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ See the [`children`](#children) section for more details.
104104
| `enableGet Choices` | Optional | `({q: string}) => boolean` | `() => true` | Function taking the `filterValues` and returning a boolean to enable the `getList` call. |
105105
| `filter` | Optional | `Object` | `{}` | Permanent filters to use for getting the suggestion list |
106106
| `label` | Optional | `string` | - | Useful only when `ReferenceArrayInput` is in a Filter array, the label is used as the Filter label. |
107+
| `offline ` | Optional | `ReactNode` | - | The content rendered to render when data could not be fetched because of connectivity issues |
107108
| `page` | Optional | `number` | 1 | The current page number |
108109
| `perPage` | Optional | `number` | 25 | Number of suggestions to show |
109110
| `queryOptions` | Optional | [`UseQueryOptions`](https://tanstack.com/query/v5/docs/react/reference/useQuery) | `{}` | `react-query` client options |
@@ -216,6 +217,31 @@ const filters = [
216217
];
217218
```
218219

220+
## `offline`
221+
222+
`<ReferenceArrayInput>` can display a custom message when data cannot be fetched because of connectivity issues.
223+
You can customize this message via react-admin's [translation system](./Translation.md), by setting a custom translation for the `ra.notification.offline` key.
224+
225+
```tsx
226+
const messages = {
227+
ra: {
228+
notification: {
229+
offline: "No network. Data couldn't be fetched.",
230+
}
231+
}
232+
}
233+
```
234+
235+
If you need to go beyond text, pass a custom element as the `<ReferenceArrayInput offline>` prop:
236+
237+
```jsx
238+
const Offline = () => (
239+
<p>No network. Data couldn't be fetched.</p>
240+
);
241+
242+
<ReferenceArrayInput source="tags_ids" reference="tags" offline={<Offline />} />
243+
```
244+
219245
## `parse`
220246
221247
By default, children of `<ReferenceArrayInput>` transform the empty form value (an empty string) into `null` before passing it to the `dataProvider`.

docs/ReferenceField.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ It uses `dataProvider.getMany()` instead of `dataProvider.getOne()` [for perform
7777
| `emptyText` | Optional | `string` | '' | Defines a text to be shown when the field has no value or when the reference is missing |
7878
| `label` | Optional | `string | Function` | `resources. [resource]. fields.[source]` | Label to use for the field when rendered in layout components |
7979
| `link` | Optional | `string | Function` | `edit` | Target of the link wrapping the rendered child. Set to `false` to disable the link. |
80+
| `offline ` | Optional | `ReactNode` | - | The content rendered to render when data could not be fetched because of connectivity issues |
8081
| `queryOptions` | Optional | [`UseQuery Options`](https://tanstack.com/query/v5/docs/react/reference/useQuery) | `{}` | `react-query` client options |
8182
| `sortBy` | Optional | `string | Function` | `source` | Name of the field to use for sorting when used in a Datagrid |
8283

@@ -142,6 +143,31 @@ You can also use a custom `link` function to get a custom path for the children.
142143
/>
143144
```
144145

146+
## `offline`
147+
148+
`<ReferenceField>` can display a custom message when data cannot be fetched because of connectivity issues.
149+
You can customize this message via react-admin's [translation system](./Translation.md), by setting a custom translation for the `ra.notification.offline` key.
150+
151+
```tsx
152+
const messages = {
153+
ra: {
154+
notification: {
155+
offline: "No network. Data couldn't be fetched.",
156+
}
157+
}
158+
}
159+
```
160+
161+
If you need to go beyond text, pass a custom element as the `<ReferenceField offline>` prop:
162+
163+
```jsx
164+
const Offline = () => (
165+
<p>No network. Data couldn't be fetched.</p>
166+
);
167+
168+
<ReferenceField source="user_id" reference="users" offline={<Offline />} />
169+
```
170+
145171
## `queryOptions`
146172
147173
Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` query](./useGetOne.md#aggregating-getone-calls) that fetches the referenced record.

docs/ReferenceInput.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ See the [`children`](#children) section for more details.
107107
| `enableGet Choices` | Optional | `({q: string}) => boolean` | `() => true` | Function taking the `filterValues` and returning a boolean to enable the `getList` call. |
108108
| `filter` | Optional | `Object` | `{}` | Permanent filters to use for getting the suggestion list |
109109
| `label` | Optional | `string` | - | Useful only when `ReferenceInput` is in a Filter array, the label is used as the Filter label. |
110+
| `offline ` | Optional | `ReactNode` | - | The content rendered to render when data could not be fetched because of connectivity issues |
110111
| `page` | Optional | `number` | 1 | The current page number |
111112
| `perPage` | Optional | `number` | 25 | Number of suggestions to show |
112113
| `queryOptions` | Optional | [`UseQueryOptions`](https://tanstack.com/query/v5/docs/react/reference/useQuery) | `{}` | `react-query` client options |
@@ -190,6 +191,31 @@ const filters = [
190191
];
191192
```
192193

194+
## `offline`
195+
196+
`<ReferenceInput>` can display a custom message when data cannot be fetched because of connectivity issues.
197+
You can customize this message via react-admin's [translation system](./Translation.md), by setting a custom translation for the `ra.notification.offline` key.
198+
199+
```tsx
200+
const messages = {
201+
ra: {
202+
notification: {
203+
offline: "No network. Data couldn't be fetched.",
204+
}
205+
}
206+
}
207+
```
208+
209+
If you need to go beyond text, pass a custom element as the `<ReferenceInput offline>` prop:
210+
211+
```jsx
212+
const Offline = () => (
213+
<p>No network. Data couldn't be fetched.</p>
214+
);
215+
216+
<ReferenceInput source="company_id" reference="companies" offline={<Offline />} />
217+
```
218+
193219
## `parse`
194220
195221
By default, children of `<ReferenceInput>` transform the empty form value (an empty string) into `null` before passing it to the `dataProvider`.

0 commit comments

Comments
 (0)