Skip to content

Commit 2027186

Browse files
fzaninottoslax57djhidunglas
authored
Add support for react-admin v5 (#572)
* [WIP] Add support for react-admin v5 * Fix more TS errors * Fix build * Fix linter warnings * Fix one test * fix jest config for react-query * InputGuesser: fix array label and test * Add folder hierarchy * Fix tests * Add sort and filter to the test entity * Modernize override code * Fix console error * Fix override code * Add stroy testing view customization * Bump version * Apply suggestions from code review Co-authored-by: Gildas Garcia <[email protected]> * Update .dockerignore Co-authored-by: Kévin Dunglas <[email protected]> * Apply suggestion from code review --------- Co-authored-by: Jean-Baptiste Kaiser <[email protected]> Co-authored-by: Gildas Garcia <[email protected]> Co-authored-by: Kévin Dunglas <[email protected]>
1 parent 56efa7c commit 2027186

Some content is hidden

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

54 files changed

+675
-771
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

CHANGELOG.md

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

3+
## 4.0.0
4+
5+
* Compatibility with react-admin v5
6+
37
## 3.4.5
48

59
* Fix validation errors shown as "Server communication error" when creating an entity

UPGRADE.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
# Upgrade to 3.0
1+
# Upgrade to 4.0
22

3-
First of all, read the [UPGRADE guide from react-admin](https://marmelab.com/react-admin/doc/4.0/Upgrade.html).
3+
API Platform Admin 4.0 has the same API as API Platform admin 3.4, but now requires react-admin v5.
44

5-
Since API Platform Admin is built on top of react-admin, almost everything in the react-admin upgrade guide applies to API Platform Admin as well.
5+
If your application only uses components from the '@api-platform/admin' package, it should work out of the box with API Platform Admin 4.0.
66

7-
This UPGRADE guide will only cover the specific changes for API Platform Admin.
8-
9-
## Authentication Support
10-
11-
Since the way to define custom routes has completely changed in react-admin, the way to add authentication support in API Platform Admin has also been modified.
12-
13-
In short, you need to use the `<CustomRoutes>` component inside the `<HydraAdmin>` or `<AdminGuesser>` component, with a redirect condition on its child.
14-
The condition is taken from a state variable, and the state updater function is given to the data provider and will be used when there is an unauthorized error.
15-
16-
To see the full updated example, please [go to the related documentation page](https://api-platform.com/docs/main/admin/authentication-support/).
17-
18-
## Mercure Support
19-
20-
Since react-admin does not use Redux anymore, it's also the case for Mercure in API Platform Admin.
21-
22-
Instead it uses react-query cache to update the received changes in real time.
23-
24-
You will not see the Redux data action when a resource is updated by Mercure anymore.
7+
If you have done some customization based on the 'react-admin' package, you will probably have to make some changes. Read the [UPGRADE guide from react-admin](https://marmelab.com/react-admin/doc/5.0/Upgrade.html) for further details.

api/src/Entity/Greeting.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
use ApiPlatform\Metadata\ApiResource;
66
use Doctrine\ORM\Mapping as ORM;
77
use Symfony\Component\Validator\Constraints as Assert;
8+
use ApiPlatform\Metadata\ApiFilter;
9+
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
10+
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
11+
812

9-
/**
10-
* This is a dummy entity. Remove it!
11-
*/
1213
#[ApiResource(mercure: true)]
1314
#[ORM\Entity]
15+
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial'])]
16+
#[ApiFilter(OrderFilter::class, properties: ['name'], arguments: ['orderParameterName' => 'order'])]
1417
class Greeting
1518
{
1619
/**

jest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const config: JestConfigWithTsJest = {
99
moduleNameMapper: {
1010
'^(\\.{1,2}/.*/llhttp\\.wasm\\.js)$': '$1',
1111
'^(\\.{1,2}/.*)\\.js$': '$1',
12+
'^@tanstack/react-query$':
13+
'<rootDir>/node_modules/@tanstack/react-query/build/modern/index.cjs',
1214
},
1315
transform: {
1416
'^.+\\.tsx?$': [

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
"sideEffects": false,
2020
"dependencies": {
2121
"@api-platform/api-doc-parser": "^0.16.2",
22-
"history": "^5.0.0",
2322
"jsonld": "^8.1.0",
2423
"lodash.isplainobject": "^4.0.6",
25-
"prop-types": "^15.6.2",
26-
"react-admin": "^4.4.0",
27-
"react-error-boundary": "^4.0.13"
24+
"react-admin": "^5.0.3"
2825
},
2926
"devDependencies": {
3027
"@babel/preset-env": "^7.23.3",

src/AdminGuesser.tsx

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

src/AdminGuesser.test.tsx renamed to src/core/AdminGuesser.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import React from 'react';
22
import { AdminUI, AuthContext } from 'react-admin';
33
import type { AdminProps, AuthProvider } from 'react-admin';
44
import ReactTestRenderer from 'react-test-renderer/shallow';
5-
import AdminGuesser, { AdminResourcesGuesser } from './AdminGuesser.js';
5+
import AdminGuesser from './AdminGuesser.js';
6+
import { AdminResourcesGuesser } from './AdminResourcesGuesser.js';
67
import ResourceGuesser from './ResourceGuesser.js';
7-
import schemaAnalyzer from './hydra/schemaAnalyzer.js';
8-
import resources from './__fixtures__/resources.js';
9-
import { API_DATA } from './__fixtures__/parsedData.js';
8+
import schemaAnalyzer from '../hydra/schemaAnalyzer.js';
9+
import resources from '../__fixtures__/resources.js';
10+
import { API_DATA } from '../__fixtures__/parsedData.js';
1011
import type {
1112
ApiPlatformAdminDataProvider,
1213
ApiPlatformAdminRecord,
13-
} from './types.js';
14+
} from '../types.js';
1415

1516
const dataProvider: ApiPlatformAdminDataProvider = {
1617
getList: () => Promise.resolve({ data: [], total: 0 }),

0 commit comments

Comments
 (0)