Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade react-router to 6.22.0, use data router, stabilize useWarnWhenUnsavedChanges and remove <Admin history> prop #9657

Merged
merged 33 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
536096c
[no ci] wip: upgrade react-router and rewrite useWarnWhenUnsavedChanges
slax57 Feb 9, 2024
7ccead7
handle closing tab with beforeunload
slax57 Feb 16, 2024
028765a
update tests
slax57 Feb 16, 2024
6bc0f39
[no ci] use createHashRouter in AdminRouter and remove history prop
slax57 Feb 16, 2024
441a22a
fix use element instead of Component
slax57 Feb 21, 2024
51ec845
[no ci] wip: introduce TestMemoryRouter
slax57 Feb 21, 2024
2268b01
[no ci] fix should allow custom redirect with warnWhenUnsavedChanges …
slax57 Feb 22, 2024
821e6c7
[no ci] migrate 2 more files and add support for navigateCallback
slax57 Feb 23, 2024
3d58967
[no ci] update TabbedShowLayout tests
slax57 Feb 23, 2024
0892754
[no ci] [wip] codemod 1st version!
slax57 Feb 26, 2024
cd69510
[no ci] [wip] preserve initialEntries
slax57 Feb 26, 2024
c3efa4d
[no ci] [wip] add replace-MemoryRouter codemod
slax57 Feb 26, 2024
de05871
[no ci] [wip] run replace-Admin-history on ra-core
slax57 Feb 27, 2024
fa13590
[no ci] [wip] run replace-MemoryRouter on ra-core
slax57 Feb 27, 2024
91b81e6
[no ci] update FakeBrowser jsdoc
slax57 Feb 27, 2024
e20413a
[no ci] clean up last call to history in ra-core
slax57 Feb 27, 2024
133f13f
[no ci] run replace-Admin-history in ra-ui-materialui
slax57 Feb 27, 2024
be7a8c7
[no ci] run replace-MemoryRouter in ra-ui-materialui
slax57 Feb 27, 2024
353968b
fix most tests
slax57 Feb 27, 2024
3c13fc8
fix tests about rendering error
slax57 Feb 27, 2024
aebc600
add codemods to ra-core package
slax57 Feb 27, 2024
b976c1f
fix FakeBrowser BrowserBar location
slax57 Feb 27, 2024
cf45a6e
fix stories
slax57 Feb 27, 2024
b81a73a
remove dep on history
slax57 Feb 27, 2024
eec30bc
cleanup test code
slax57 Feb 27, 2024
2165633
Merge remote-tracking branch 'origin/next' into react-router-6.22.0
slax57 Feb 27, 2024
3a45bab
upgrade guide
slax57 Feb 27, 2024
513c4b1
code review 1
slax57 Feb 27, 2024
a5c6dbc
fix tests after merge
slax57 Feb 27, 2024
43abae5
code review
slax57 Feb 29, 2024
d973d48
code review 2
slax57 Feb 29, 2024
289843a
code review 3
slax57 Feb 29, 2024
2eb491a
fix blocker is not stable
slax57 Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"react-admin": "^4.12.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^3.1.4",
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0"
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.4",
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"react": "^18.0.0",
"react-admin": "^4.12.0",
"react-dom": "^18.2.0",
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0",
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0",
"recharts": "^2.1.15"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"react-admin": "^4.16.2",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0"
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0"
},
"devDependencies": {
"@hookform/devtools": "^4.0.2",
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default {
average_note: 3,
commentable: true,
published_at: new Date('2012-08-05'),
tags: [],
category: 'tech',
notifications: [12, 31, 42],
},
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/src/dataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const delayedDataProvider = new Proxy(sometimesFailsDataProvider, {
setTimeout(
() =>
resolve(sometimesFailsDataProvider[name](resource, params)),
300
2000
)
);
},
Expand Down
97 changes: 50 additions & 47 deletions examples/simple/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint react/jsx-key: off */
import * as React from 'react';
import { Admin, Resource, CustomRoutes } from 'react-admin'; // eslint-disable-line import/no-unresolved
import { Admin, Resource, CustomRoutes } from 'react-admin';
import { createRoot } from 'react-dom/client';
import { Route } from 'react-router-dom';

Expand All @@ -16,55 +15,59 @@ import users from './users';
import tags from './tags';
import { queryClient } from './queryClient';

const App = () => (
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved
<Admin
authProvider={authProvider}
dataProvider={dataProvider}
i18nProvider={i18nProvider}
queryClient={queryClient}
title="Example Admin"
layout={Layout}
>
<CustomRoutes noLayout>
<Route
path="/custom"
element={<CustomRouteNoLayout title="Posts from /custom" />}
/>
</CustomRoutes>
<Resource name="posts" {...posts} />
<Resource name="comments" {...comments} />
<Resource name="tags" {...tags} />
{permissions => (
<>
{permissions ? <Resource name="users" {...users} /> : null}
<CustomRoutes noLayout>
<Route
path="/custom1"
element={
<CustomRouteNoLayout title="Posts from /custom1" />
}
/>
</CustomRoutes>
<CustomRoutes>
<Route
path="/custom2"
element={
<CustomRouteLayout title="Posts from /custom2" />
}
/>
</CustomRoutes>
</>
)}
<CustomRoutes>
<Route
path="/custom3"
element={<CustomRouteLayout title="Posts from /custom3" />}
/>
</CustomRoutes>
</Admin>
);

const container = document.getElementById('root');
const root = createRoot(container);

root.render(
<React.StrictMode>
<Admin
authProvider={authProvider}
dataProvider={dataProvider}
i18nProvider={i18nProvider}
queryClient={queryClient}
title="Example Admin"
layout={Layout}
>
<CustomRoutes noLayout>
<Route
path="/custom"
element={<CustomRouteNoLayout title="Posts from /custom" />}
/>
</CustomRoutes>
<Resource name="posts" {...posts} />
<Resource name="comments" {...comments} />
<Resource name="tags" {...tags} />
{permissions => (
<>
{permissions ? <Resource name="users" {...users} /> : null}
<CustomRoutes noLayout>
<Route
path="/custom1"
element={
<CustomRouteNoLayout title="Posts from /custom1" />
}
/>
</CustomRoutes>
<CustomRoutes>
<Route
path="/custom2"
element={
<CustomRouteLayout title="Posts from /custom2" />
}
/>
</CustomRoutes>
</>
)}
<CustomRoutes>
<Route
path="/custom3"
element={<CustomRouteLayout title="Posts from /custom3" />}
/>
</CustomRoutes>
</Admin>
<App />
</React.StrictMode>
);
12 changes: 11 additions & 1 deletion examples/simple/src/posts/PostEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ const categories = [
const PostEdit = () => {
const { permissions } = usePermissions();
return (
<Edit title={<PostTitle />} actions={<EditActions />}>
<Edit
title={<PostTitle />}
actions={<EditActions />}
mutationMode="pessimistic"
redirect="show"
// mutationOptions={{
// onSuccess: () => {
// console.log('success!');
// },
// }}
>
<TabbedForm
defaultValues={{ average_note: 0 }}
warnWhenUnsavedChanges
Expand Down
8 changes: 4 additions & 4 deletions packages/ra-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"react": "^18.0.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0",
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0",
"react-test-renderer": "^18.2.0",
"recharts": "^2.1.15",
"rimraf": "^3.0.2",
Expand All @@ -54,8 +54,8 @@
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0",
"react-hook-form": "^7.43.9",
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0"
"react-router": "^6.22.0",
"react-router-dom": "^6.22.0"
},
"dependencies": {
"@tanstack/react-query": "^5.8.4",
Expand Down
38 changes: 18 additions & 20 deletions packages/ra-core/src/auth/Authenticated.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import expect from 'expect';
import { render, screen, waitFor } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { Routes, Route, useLocation } from 'react-router-dom';

import { memoryStore } from '../store';
import { CoreAdminContext } from '../core';
import { useNotificationContext } from '../notification';
import { Authenticated } from './Authenticated';
import { TestMemoryRouter } from '../routing';

describe('<Authenticated>', () => {
const Foo = () => <div>Foo</div>;
Expand Down Expand Up @@ -44,7 +44,6 @@ describe('<Authenticated>', () => {
};
const store = memoryStore();
const reset = jest.spyOn(store, 'reset');
const history = createMemoryHistory();

const Login = () => {
const location = useLocation();
Expand All @@ -65,25 +64,24 @@ describe('<Authenticated>', () => {
};

render(
<CoreAdminContext
authProvider={authProvider}
store={store}
history={history}
>
<Notification />
<Routes>
<Route
path="/"
element={
<Authenticated>
<Foo />
</Authenticated>
}
/>
<Route path="/login" element={<Login />} />
</Routes>
</CoreAdminContext>
<TestMemoryRouter>
<CoreAdminContext authProvider={authProvider} store={store}>
<Notification />
<Routes>
<Route
path="/"
element={
<Authenticated>
<Foo />
</Authenticated>
}
/>
<Route path="/login" element={<Login />} />
</Routes>
</CoreAdminContext>
</TestMemoryRouter>
);

await waitFor(() => {
expect(authProvider.checkAuth.mock.calls[0][0]).toEqual({});
expect(authProvider.logout.mock.calls[0][0]).toEqual({});
Expand Down
Loading