Skip to content

Commit 703d0be

Browse files
authored
Merge pull request #11176 from marmelab/merge-master-5.14.3
[chore] Merge master 5.14.3 -> next
2 parents d2341ef + f4ac29d commit 703d0be

File tree

78 files changed

+2670
-1026
lines changed

Some content is hidden

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

78 files changed

+2670
-1026
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030

3131
# Initializes the CodeQL tools for scanning.
3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@v2
33+
uses: github/codeql-action/init@v3
3434
# Override language selection by uncommenting this and choosing your languages
3535
# with:
3636
# languages: go, javascript, csharp, python, cpp, java
3737

3838
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3939
# If this step fails, then you should remove it and run the build manually (see below)
4040
- name: Autobuild
41-
uses: github/codeql-action/autobuild@v2
41+
uses: github/codeql-action/autobuild@v3
4242

4343
# ℹ️ Command-line programs to run using the OS shell.
4444
# 📚 https://git.io/JvXDl
@@ -52,4 +52,4 @@ jobs:
5252
# make release
5353

5454
- name: Perform CodeQL Analysis
55-
uses: github/codeql-action/analyze@v2
55+
uses: github/codeql-action/analyze@v3

CHANGELOG.md

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

3+
## 5.14.3
4+
5+
* Add default empty component and i18n messages to `ListGuesser` ([#11165](https://github.com/marmelab/react-admin/pull/11165)) ([WiXSL](https://github.com/WiXSL))
6+
* Fix `<Edit>`, `<ReferenceField>` and `<List>` to better support offline mode ([#11161](https://github.com/marmelab/react-admin/pull/11161)) ([fzaninotto](https://github.com/fzaninotto))
7+
* [Doc] Add DataTableInput dedicated page and cross references ([#11162](https://github.com/marmelab/react-admin/pull/11162)) ([WiXSL](https://github.com/WiXSL))
8+
* [TypeScript] Fix withLifecycleCallback return type for augmented data providers ([#11170](https://github.com/marmelab/react-admin/pull/11170)) ([fzaninotto](https://github.com/fzaninotto))
9+
* [TypeScript] Fix ReferenceManyField queryOptions type doesn't support error and success callbacks ([#11166](https://github.com/marmelab/react-admin/pull/11166)) ([fzaninotto](https://github.com/fzaninotto))
10+
* Bump rollup from 2.79.2 to 2.80.0 ([#11175](https://github.com/marmelab/react-admin/pull/11175)) ([dependabot[bot]](https://github.com/apps/dependabot))
11+
* Bump storybook from 8.6.15 to 8.6.17 ([#11174](https://github.com/marmelab/react-admin/pull/11174)) ([dependabot[bot]](https://github.com/apps/dependabot))
12+
* Bump devalue from 5.6.2 to 5.6.3 ([#11168](https://github.com/marmelab/react-admin/pull/11168)) ([dependabot[bot]](https://github.com/apps/dependabot))
13+
* Bump systeminformation from 5.29.1 to 5.31.1 ([#11167](https://github.com/marmelab/react-admin/pull/11167)) ([dependabot[bot]](https://github.com/apps/dependabot))
14+
315
## 5.14.2
416

517
* Fix `<ReferenceFieldBase>` does not work offline ([#11163](https://github.com/marmelab/react-admin/pull/11163)) ([fzaninotto](https://github.com/fzaninotto))

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ run-crm: ## run the crm example
3939
build-crm: ## build the crm example
4040
@yarn build-crm
4141

42+
run-offline: ## run the offline example (dev mode)
43+
@yarn run-offline
44+
45+
build-offline: ## build the offline example
46+
@yarn build-offline
47+
48+
preview-offline: ## preview the offline example
49+
@yarn preview-offline
50+
4251
build-ra-core:
4352
@echo "Transpiling ra-core files...";
4453
@cd ./packages/ra-core && yarn build

docs/AutocompleteInput.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ It renders using [Material UI's `<Autocomplete>`](https://mui.com/material-ui/re
1515
Your browser does not support the video tag.
1616
</video>
1717

18-
This input allows editing record fields that are scalar values, e.g. `123`, `'admin'`, etc.
18+
This input allows editing record fields that are scalar values, e.g. `123`, `'admin'`, etc.
1919

2020
## Usage
2121

@@ -32,8 +32,9 @@ import { AutocompleteInput } from 'react-admin';
3232
```
3333

3434
By default, the possible choices are built from the `choices` prop, using:
35-
- the `id` field as the option value,
36-
- the `name` field as the option text
35+
36+
- the `id` field as the option value,
37+
- the `name` field as the option text
3738

3839
The form value for the source must be the selected value, e.g.
3940

@@ -47,11 +48,13 @@ The form value for the source must be the selected value, e.g.
4748

4849
**Tip**: React-admin includes other components to edit such values:
4950

50-
- [`<SelectInput>`](./SelectInput.md) renders a dropdown
51-
- [`<RadioButtonGroupInput>`](./RadioButtonGroupInput.md) renders a list of radio buttons
51+
- [`<SelectInput>`](./SelectInput.md) renders a dropdown
52+
- [`<RadioButtonGroupInput>`](./RadioButtonGroupInput.md) renders a list of radio buttons
5253

5354
**Tip**: If you need to let users select more than one item in the list, check out the [`<AutocompleteArrayInput>`](./AutocompleteArrayInput.md) component.
5455

56+
**Tip**: If users need to compare multiple fields before choosing (e.g. team, region, SLA, status), use [`<DataTableInput>`](./DataTableInput.md).
57+
5558
## Props
5659

5760
| Prop | Required | Type | Default | Description |
@@ -152,6 +155,7 @@ To allow users to add new options, pass a React element as the `create` prop. `<
152155
</video>
153156

154157
{% raw %}
158+
155159
```jsx
156160
import {
157161
Create,
@@ -218,6 +222,7 @@ const CreateAuthor = () => {
218222
);
219223
};
220224
```
225+
221226
{% endraw %}
222227

223228
**Tip**: In development with `React.StrictMode`, you may run into an issue where the `<AutocompleteInput>` menu reopens after clicking the create item when the [`openOnFocus`](https://mui.com/material-ui/api/autocomplete/#autocomplete-prop-openOnFocus) prop is set to `true` which is the default with React-admin. If that bothers you, set the `openOnFocus` prop to `false`.
@@ -315,7 +320,7 @@ If the input isn't required (using `validate={required()}`), and you need a choi
315320

316321
The `emptyText` prop accepts either a string or a React Element.
317322

318-
And if you want to hide that empty choice, make the input required.
323+
And if you want to hide that empty choice, make the input required.
319324

320325
```jsx
321326
<AutocompleteInput source="author_id" choices={choices} validate={required()} />
@@ -331,15 +336,15 @@ You can override this value with the `emptyValue` prop.
331336
<AutocompleteInput source="author_id" choices={choices} emptyValue={0} />
332337
```
333338

334-
**Tip**: While you can set `emptyValue` to a non-string value (e.g. `0`), you cannot use `null` or `undefined`, as it would turn the `<AutocompleteInput>` into an [uncontrolled component](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). If you need the empty choice to be stored as `null` or `undefined`, use [the `parse` prop](./Inputs.md#parse) to convert the default empty value ('') to `null` or `undefined`, or use [the `sanitizeEmptyValues` prop](./SimpleForm.md#sanitizeemptyvalues) on the Form component.
339+
**Tip**: While you can set `emptyValue` to a non-string value (e.g. `0`), you cannot use `null` or `undefined`, as it would turn the `<AutocompleteInput>` into an [uncontrolled component](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). If you need the empty choice to be stored as `null` or `undefined`, use [the `parse` prop](./Inputs.md#parse) to convert the default empty value ('') to `null` or `undefined`, or use [the `sanitizeEmptyValues` prop](./SimpleForm.md#sanitizeemptyvalues) on the Form component.
335340

336341
## `filterToQuery`
337342

338343
When used inside a [`<ReferenceInput>`](./ReferenceInput.md), whenever users type a string in the autocomplete input, `<AutocompleteInput>` calls `dataProvider.getList()` using the string as filter, to return a filtered list of possible options from the reference resource. This filter is built using the `filterToQuery` prop.
339344

340345
By default, the filter is built using the `q` parameter. This means that if the user types the string 'lorem', the filter will be `{ q: 'lorem' }`.
341346

342-
You can customize the filter by setting the `filterToQuery` prop. It should be a function that returns a filter object.
347+
You can customize the filter by setting the `filterToQuery` prop. It should be a function that returns a filter object.
343348

344349
```jsx
345350
const filterToQuery = searchText => ({ name_ilike: `%${searchText}%` });
@@ -408,6 +413,7 @@ type OnChange = (
408413
In the following example, the `onChange` prop is used to update the `language` field whenever the user selects a new author:
409414

410415
{% raw %}
416+
411417
```tsx
412418
import * as React from 'react';
413419
import {
@@ -454,11 +460,12 @@ const BookCreate = () => (
454460
</Create>
455461
);
456462
```
463+
457464
{% endraw %}
458465

459466
## `onCreate`
460467

461-
Use the `onCreate` prop to allow users to create new options on the fly. This is equivalent to MUI's `<AutoComplete freeSolo>` prop.
468+
Use the `onCreate` prop to allow users to create new options on the fly. This is equivalent to MUI's `<AutoComplete freeSolo>` prop.
462469

463470
<video controls playsinline muted>
464471
<source src="./img/AutocompleteInput-onCreate.mp4" type="video/mp4"/>
@@ -690,9 +697,11 @@ In that case, set the `translateChoice` prop to `false`.
690697
`<AutocompleteInput>` renders a [Material UI `<Autocomplete>` component](https://mui.com/material-ui/react-autocomplete/) and it accepts the `<Autocomplete>` props:
691698

692699
{% raw %}
700+
693701
```jsx
694702
<AutocompleteInput source="category" size="large" />
695703
```
704+
696705
{% endraw %}
697706

698707
## Fetching Choices
@@ -719,11 +728,11 @@ const CountryInput = () => {
719728

720729
The `isPending` prop is used to display a loading indicator while the data is being fetched.
721730

722-
However, most of the time, if you need to populate a `<AutocompleteInput>` with choices fetched from another resource, it's because you are trying to set a foreign key. In that case, you should use [`<ReferenceInput>`](./ReferenceInput.md) to fetch the choices instead (see next section).
731+
However, most of the time, if you need to populate a `<AutocompleteInput>` with choices fetched from another resource, it's because you are trying to set a foreign key. In that case, you should use [`<ReferenceInput>`](./ReferenceInput.md) to fetch the choices instead (see next section).
723732

724733
## Selecting a Foreign Key
725734

726-
If you use `<AutocompleteInput>` to set a foreign key for a many-to-one or a one-to-one relationship, you'll have to [fetch choices](#fetching-choices), as explained in the previous section. You'll also have to fetch the record corresponding to the current value of the foreign key, as it may not be in the list of choices.
735+
If you use `<AutocompleteInput>` to set a foreign key for a many-to-one or a one-to-one relationship, you'll have to [fetch choices](#fetching-choices), as explained in the previous section. You'll also have to fetch the record corresponding to the current value of the foreign key, as it may not be in the list of choices.
727736

728737
For example, if a `contact` has one `company` via the `company_id` foreign key, a contact form can let users select a company as follows:
729738

@@ -781,18 +790,18 @@ const CompanyInput = () => (
781790
**Tip**: If you need validation (e.g. `required()`), put the `validate` prop on the child input (`<AutocompleteInput>`). `<ReferenceInput>` doesn't accept validation props.
782791

783792
`<ReferenceInput>` is a headless component that:
784-
785-
- fetches a list of records with `dataProvider.getList()` and `dataProvider.getOne()`, using the `reference` prop for the resource,
786-
- puts the result of the fetch in the `ChoiceContext` as the `choices` prop, as well as the `isPending` state,
787-
- and renders its child component
793+
794+
- fetches a list of records with `dataProvider.getList()` and `dataProvider.getOne()`, using the `reference` prop for the resource,
795+
- puts the result of the fetch in the `ChoiceContext` as the `choices` prop, as well as the `isPending` state,
796+
- and renders its child component
788797

789798
When rendered as a child of `<ReferenceInput>`, `<AutocompleteInput>` reads that `ChoiceContext` to populate its own `choices` and `isPending` props. It also sends the current input prop to the `useGetList` hook, so that the list of choices is filtered as the user types.
790799

791800
In fact, you can simplify the code even further:
792801

793802
- `<ReferenceInput>` puts all its props inside the `ChoiceContext`, including `source`, so `<AutocompleteInput>` doesn't need to repeat it.
794-
- You can also put the `label` prop on the `<ReferenceInput>` rather than `<AutocompleteInput>` so that it looks just like [`<ReferenceField>`](./ReferenceField.md) (for easier memorization).
795-
- `<AutocompleteInput>` uses the [`recordRepresentation`](./Resource.md#recordrepresentation) to determine how to represent the related choices. In the example above, the `companies` resource uses `name` as its `recordRepresentation`, so `<AutocompleteInput>` will default to `optionText="name"`.
803+
- You can also put the `label` prop on the `<ReferenceInput>` rather than `<AutocompleteInput>` so that it looks just like [`<ReferenceField>`](./ReferenceField.md) (for easier memorization).
804+
- `<AutocompleteInput>` uses the [`recordRepresentation`](./Resource.md#recordrepresentation) to determine how to represent the related choices. In the example above, the `companies` resource uses `name` as its `recordRepresentation`, so `<AutocompleteInput>` will default to `optionText="name"`.
796805
- `<ReferenceInput>`'s default child is `<AutocompleteInput>`, so you can omit it entirely.
797806

798807
The code for the `<CompanyInput>` component can be reduced to:
@@ -893,6 +902,7 @@ The `<AutocompleteInput>` can allow users to create a new choice if either the `
893902
Use the `onCreate` prop when you only require users to provide a simple string and a `prompt` is enough. You can return either the new choice directly or a Promise resolving to the new choice.
894903

895904
{% raw %}
905+
896906
```js
897907
import { AutocompleteInput, Create, SimpleForm, TextInput } from 'react-admin';
898908

@@ -920,11 +930,13 @@ const PostCreate = () => {
920930
);
921931
}
922932
```
933+
923934
{% endraw %}
924935

925936
Use the `create` prop when you want a more polished or complex UI. For example a Material UI `<Dialog>` asking for multiple fields because the choices are from a referenced resource.
926937

927938
{% raw %}
939+
928940
```js
929941
import {
930942
AutocompleteInput,
@@ -991,13 +1003,15 @@ const CreateCategory = () => {
9911003
);
9921004
};
9931005
```
1006+
9941007
{% endraw %}
9951008

9961009
**Tip:** As showcased in this example, react-admin provides a convenient hook for accessing the filter the user has already input in the `<AutocompleteInput>`: `useCreateSuggestionContext`.
9971010

9981011
The `Create %{item}` option will only be displayed once the user has already set a filter (by typing in some input). If you expect your users to create new items often, you can make this more user-friendly by adding a placeholder text like this:
9991012

10001013
{% raw %}
1014+
10011015
```diff
10021016
const PostCreate = () => {
10031017
const categories = [
@@ -1026,4 +1040,5 @@ const PostCreate = () => {
10261040
);
10271041
}
10281042
```
1043+
10291044
{% endraw %}

0 commit comments

Comments
 (0)