Skip to content

Commit 5e5e270

Browse files
committed
Merge branch 'master' into demo/msw
2 parents a81377b + 09d3bb4 commit 5e5e270

File tree

188 files changed

+7630
-936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+7630
-936
lines changed

.lintstagedrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"*.{js,jsx,ts,tsx}": [
3-
"eslint --fix",
4-
"git add",
3+
"eslint --fix"
54
],
65
"*.{json,css,md}": [
7-
"prettier",
8-
"git add"
6+
"prettier"
97
]
108
}

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## 5.10.0
4+
5+
* Add filter input to `<ColumnsButton>` when there are many columns ([#10848](https://github.com/marmelab/react-admin/pull/10848)) ([slax57](https://github.com/slax57))
6+
* Update `react-query` dependency to require at least v5.83 ([#10838](https://github.com/marmelab/react-admin/pull/10838)) ([djhi](https://github.com/djhi)). You might have duplicate versions if you already had it in your dependencies. Should you have an error mentioning the `QueryContext`, make sure you only have one version in your package manager lock file.
7+
* Add render prop page and reference MUI components ([#10837](https://github.com/marmelab/react-admin/pull/10837)) ([ThieryMichel](https://github.com/ThieryMichel))
8+
* Introduce `<ReferenceArrayInputBase>` ([#10833](https://github.com/marmelab/react-admin/pull/10833)) ([djhi](https://github.com/djhi))
9+
* Add render prop to page and reference base components ([#10832](https://github.com/marmelab/react-admin/pull/10832)) ([ThieryMichel](https://github.com/ThieryMichel))
10+
* Add disable support for `<RadioButtonGroupInput>` and `<CheckboxGroupInput>` choices ([#10821](https://github.com/marmelab/react-admin/pull/10821)) ([WiXSL](https://github.com/WiXSL))
11+
* Add support for `empty` in Reference fields ([#10817](https://github.com/marmelab/react-admin/pull/10817)) ([fzaninotto](https://github.com/fzaninotto))
12+
* Add `<ReferenceManyCountBase>` ([#10808](https://github.com/marmelab/react-admin/pull/10808)) ([fzaninotto](https://github.com/fzaninotto))
13+
* Add support for keyboard shortcuts to `<MenuItemLink>` ([#10790](https://github.com/marmelab/react-admin/pull/10790)) ([djhi](https://github.com/djhi))
14+
* Fix `useEditController` does not pass all variables to useUpdate ([#10839](https://github.com/marmelab/react-admin/pull/10839)) by ([djhi](https://github.com/djhi))
15+
* Fix typo in `<Create>` documentation ([#10840](https://github.com/marmelab/react-admin/pull/10840)) by ([rkfg](https://github.com/rkfg))
16+
* [Doc] Backport RBAC's doc ([#10846](https://github.com/marmelab/react-admin/pull/10846)) by ([erwanMarmelab](https://github.com/erwanMarmelab))
17+
* [Doc] Backport DatagridAg's doc update ([#10845](https://github.com/marmelab/react-admin/pull/10845)) by ([erwanMarmelab](https://github.com/erwanMarmelab))
18+
* [Doc] Backport Tree's doc ([#10847](https://github.com/marmelab/react-admin/pull/10847)) by ([erwanMarmelab](https://github.com/erwanMarmelab))
19+
* [chore] Fix release script milestone description ([#10849](https://github.com/marmelab/react-admin/pull/10849)) by ([slax57](https://github.com/slax57))
20+
321
## 5.9.2
422

523
* Fix `fullWidth` is not propagated anymore ([#10827](https://github.com/marmelab/react-admin/pull/10827)) ([djhi](https://github.com/djhi))

docs/CheckboxGroupInput.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The form value for the source must be an array of the selected values, e.g.
6666
| `optionValue` | Optional | `string` | `id` | Field name of record containing the value to use as input value |
6767
| `row` | Optional | `boolean` | `true` | Display group of elements in a compact row. |
6868
| `translateChoice` | Optional | `boolean` | `true` | Whether the choices should be translated |
69+
| `disableValue` | Optional | `string` | `disabled` | The custom field name used in `choices` to disable some choices |
6970

7071
`<CheckboxGroupInput>` also accepts the [common input props](./Inputs.md#common-input-props).
7172

@@ -93,6 +94,17 @@ You can also use an array of objects with different properties for the label and
9394
]} optionValue="_id" optionText="label" />
9495
```
9596

97+
You can render some options as disabled by setting the `disabled` field in some choices:
98+
99+
```jsx
100+
const choices = [
101+
{ id: 'tech', name: 'Tech' },
102+
{ id: 'lifestyle', name: 'Lifestyle' },
103+
{ id: 'people', name: 'People', disabled: true },
104+
];
105+
<RadioButtonGroupInput source="category" choices={choices} />
106+
```
107+
96108
The choices are translated by default, so you can use translation identifiers as choices:
97109

98110
```jsx
@@ -256,6 +268,30 @@ However, in some cases (e.g. inside a `<ReferenceArrayInput>`), you may not want
256268
<CheckboxGroupInput source="roles" choices={choices} translateChoice={false}/>
257269
```
258270

271+
## `disableValue`
272+
273+
By default, `<CheckboxGroupInput>` renders the choices with the field `disabled: true` as disabled.
274+
275+
```jsx
276+
const choices = [
277+
{ id: 'tech', name: 'Tech' },
278+
{ id: 'lifestyle', name: 'Lifestyle' },
279+
{ id: 'people', name: 'People', disabled: true },
280+
];
281+
<CheckboxGroupInput source="category" choices={choices} />
282+
```
283+
284+
If you want to use another field to denote disabled options, set the `disableValue` prop.
285+
286+
```jsx
287+
const choices = [
288+
{ id: 'tech', name: 'Tech' },
289+
{ id: 'lifestyle', name: 'Lifestyle' },
290+
{ id: 'people', name: 'People', not_available: true },
291+
];
292+
<CheckboxGroupInput source="category" choices={choices} disableValue="not_available" />
293+
```
294+
259295
## Fetching Choices
260296

261297
If you want to populate the `choices` attribute with a list of related records, you should decorate `<CheckboxGroupInput>` with [`<ReferenceArrayInput>`](./ReferenceArrayInput.md), and leave the `choices` empty:

docs/Create.md

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,25 @@ export default App;
5555

5656
You can customize the `<Create>` component using the following props:
5757

58-
* [`actions`](#actions): override the actions toolbar with a custom component
59-
* [`aside`](#aside): component to render aside to the main content
60-
* `children`: the components that renders the form
61-
* `className`: passed to the root component
62-
* [`component`](#component): override the root component
63-
* [`disableAuthentication`](#disableauthentication): disable the authentication check
64-
* [`mutationMode`](#mutationmode): switch to optimistic or undoable mutations (pessimistic by default)
65-
* [`mutationOptions`](#mutationoptions): options for the `dataProvider.create()` call
66-
* [`record`](#record): initialize the form with a record
67-
* [`redirect`](#redirect): change the redirect location after successful creation
68-
* [`resource`](#resource): override the name of the resource to create
69-
* [`sx`](#sx-css-api): Override the styles
70-
* [`title`](#title): override the page title
71-
* [`transform`](#transform): transform the form data before calling `dataProvider.create()`
58+
| Prop | Required | Type | Default | Description |
59+
|---------------------|----------|---------------------|----------------|--------------------------------------------------------------------------------------------------|
60+
| `children` | Optional&nbsp;* | `ReactNode` | - | The components that render the form |
61+
| `render` | Optional&nbsp;* | `function` | - | Alternative to children. Function that renders the form, receives the create context as argument |
62+
| `actions` | Optional | `ReactNode` | Default toolbar| Override the actions toolbar with a custom component |
63+
| `aside` | Optional | `ReactNode` | - | Component to render aside to the main content |
64+
| `className` | Optional | `string` | - | Passed to the root component |
65+
| `component` | Optional | `string`/`Component`| `Card` | Override the root component |
66+
| `disableAuthentication` | Optional | `boolean` | `false` | Disable the authentication check |
67+
| `mutationMode` | Optional | `string` | `pessimistic` | Switch to optimistic or undoable mutations |
68+
| `mutationOptions` | Optional | `object` | - | Options for the `dataProvider.create()` call |
69+
| `record` | Optional | `object` | `{}` | Initialize the form with a record |
70+
| `redirect` | Optional | `string`/`function` | `'edit'` | Change the redirect location after successful creation |
71+
| `resource` | Optional | `string` | From URL | Override the name of the resource to create |
72+
| `sx` | Optional | `object` | - | Override the styles |
73+
| `title` | Optional | `string`/`ReactNode`| Translation | Override the page title |
74+
| `transform` | Optional | `function` | - | Transform the form data before calling `dataProvider.create()` |
75+
76+
`*` You must provide either `children` or `render`.
7277

7378
## `actions`
7479

@@ -120,6 +125,28 @@ const PostCreate = () => (
120125

121126
{% endraw %}
122127

128+
## `children`
129+
130+
The `<Create>` component will render its children inside a [`CreateContext`](./useCreateContext.md#return-value). Children can be any React node, but are usually a form component like [`<SimpleForm>`](./SimpleForm.md), [`<TabbedForm>`](./TabbedForm.md), or the headless [`<Form>`](./Form.md) component.
131+
132+
```tsx
133+
import { Create, SimpleForm, TextInput, DateInput, required } from 'react-admin';
134+
import RichTextInput from 'ra-input-rich-text';
135+
136+
export const PostCreate = () => (
137+
<Create>
138+
<SimpleForm>
139+
<TextInput source="title" validate={[required()]} />
140+
<TextInput source="teaser" multiline={true} label="Short description" />
141+
<RichTextInput source="body" />
142+
<DateInput label="Publication date" source="published_at" defaultValue={new Date()} />
143+
</SimpleForm>
144+
</Create>
145+
);
146+
```
147+
148+
**Tip**: Alternatively to `children`, you can pass a [`render`](#render) prop to `<Create>`.
149+
123150
## `component`
124151

125152
By default, the `<Create>` view render the main form inside a Material UI `<Card>` element. The actual layout of the form depends on the `Form` component you're using ([`<SimpleForm>`](./SimpleForm.md), [`<TabbedForm>`](./TabbedForm.md), or a custom form component).
@@ -160,9 +187,9 @@ const PostCreate = () => (
160187

161188
The `<Create>` view exposes a Save button, which perform a "mutation" (i.e. it creates the data). React-admin offers three modes for mutations. The mode determines when the side effects (redirection, notifications, etc.) are executed:
162189

163-
- `pessimistic` (default): The mutation is passed to the dataProvider first. When the dataProvider returns successfully, the mutation is applied locally, and the side effects are executed.
164-
- `optimistic`: The mutation is applied locally and the side effects are executed immediately. Then the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
165-
- `undoable`: The mutation is applied locally and the side effects are executed immediately. Then a notification is shown with an undo button. If the user clicks on undo, the mutation is never sent to the dataProvider, and the page is refreshed. Otherwise, after a 5 seconds delay, the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
190+
* `pessimistic` (default): The mutation is passed to the dataProvider first. When the dataProvider returns successfully, the mutation is applied locally, and the side effects are executed.
191+
* `optimistic`: The mutation is applied locally and the side effects are executed immediately. Then the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
192+
* `undoable`: The mutation is applied locally and the side effects are executed immediately. Then a notification is shown with an undo button. If the user clicks on undo, the mutation is never sent to the dataProvider, and the page is refreshed. Otherwise, after a 5 seconds delay, the mutation is passed to the dataProvider. If the dataProvider returns successfully, nothing happens (as the mutation was already applied locally). If the dataProvider returns in error, the page is refreshed and an error notification is shown.
166193

167194
By default, pages using `<Create>` use the `pessimistic` mutation mode as the new record identifier is often generated on the backend. However, should you decide to generate this identifier client side, you can change the `mutationMode` to either `optimistic` or `undoable`:
168195

@@ -315,6 +342,37 @@ Note that the `redirect` prop is ignored if you set [the `mutationOptions` prop]
315342

316343
If you want to allow the user to enter several records one after the other, setting `redirect` to `false` won't make it, as the form isn't emptied by default. You'll have to empty the form using the `mutationOptions`, and this option disables the `redirect` prop. Check [the Save And Add Another section](#save-and-add-another) for more details.
317344

345+
## `render`
346+
347+
Alternatively to `children`, you can pass a `render` prop to `<Create>`. It will receive the [`CreateContext`](./useCreateContext.md#return-value) as its argument, and should return a React node.
348+
349+
This allows to inline the render logic for the create page.
350+
351+
{% raw %}
352+
353+
```tsx
354+
const PostCreate = () => ()
355+
<Create render={({ save, saving }) => (
356+
<div>
357+
<h1>Create new Post</h1>
358+
<form onSubmit={save}>
359+
<input type="text" name="title" placeholder="Title" required />
360+
<textarea name="teaser" placeholder="Short description" rows={3} />
361+
<textarea name="body" placeholder="Body" rows={5} />
362+
<input type="date" name="published_at" defaultValue={new Date().toISOString().split('T')[0]} />
363+
<button type="submit" disabled={saving}>
364+
{saving ? 'Saving...' : 'Save'}
365+
</button>
366+
</form>
367+
</div>
368+
)} />
369+
);
370+
```
371+
372+
{% endraw %}
373+
374+
**Tip**: When receiving a `render` prop, the `<Create>` component will ignore the `children` prop.
375+
318376
## `resource`
319377

320378
Components based on `<Create>` are often used as `<Resource create>` props, and therefore rendered when the URL matches `/[resource]/create`. The `<Create>` component generates a call to `dataProvider.create()` using the resource name from the URL by default.

docs/CreateBase.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const BookCreate = () => (
4646
You can customize the `<CreateBase>` component using the following props, documented in the `<Create>` component:
4747

4848
* `children`: the components that renders the form
49+
* `render`: alternative to children, a function that takes the `CreateController` context and renders the form
4950
* [`disableAuthentication`](./Create.md#disableauthentication): disable the authentication check
5051
* [`mutationMode`](./Create.md#mutationmode): Switch to optimistic or undoable mutations (pessimistic by default)
5152
* [`mutationOptions`](./Create.md#mutationoptions): options for the `dataProvider.create()` call

0 commit comments

Comments
 (0)