From 46b46d5648e8f406d8cbb2e32eeefbe62e2ea5c1 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Mon, 22 Apr 2024 17:45:13 +0200 Subject: [PATCH 01/22] remove disableNotification from useCheckAuth --- .../ra-core/src/auth/useCheckAuth.spec.tsx | 26 ------------------- packages/ra-core/src/auth/useCheckAuth.ts | 16 +++--------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/packages/ra-core/src/auth/useCheckAuth.spec.tsx b/packages/ra-core/src/auth/useCheckAuth.spec.tsx index 8f21feb25b5..07dc8dfd93d 100644 --- a/packages/ra-core/src/auth/useCheckAuth.spec.tsx +++ b/packages/ra-core/src/auth/useCheckAuth.spec.tsx @@ -132,32 +132,6 @@ describe('useCheckAuth', () => { }); }); - it('should logout without showing a notification when disableNotification is true', async () => { - let location: Location; - render( - { - location = l; - }} - > - - - - - - - ); - await waitFor(() => { - expect(notify).toHaveBeenCalledTimes(0); - expect(screen.queryByText('authenticated')).toBeNull(); - expect(location.pathname).toBe('/login'); - }); - }); - it('should logout without showing a notification when authProvider returns error with message false', async () => { let location: Location; render( diff --git a/packages/ra-core/src/auth/useCheckAuth.ts b/packages/ra-core/src/auth/useCheckAuth.ts index 2db6a4526a1..31ad6229ab9 100644 --- a/packages/ra-core/src/auth/useCheckAuth.ts +++ b/packages/ra-core/src/auth/useCheckAuth.ts @@ -52,12 +52,7 @@ export const useCheckAuth = (): CheckAuth => { ); const checkAuth = useCallback( - ( - params: any = {}, - logoutOnFailure = true, - redirectTo = loginUrl, - disableNotification = false - ) => + (params: any = {}, logoutOnFailure = true, redirectTo = loginUrl) => authProvider.checkAuth(params).catch(error => { if (logoutOnFailure) { logout( @@ -66,9 +61,7 @@ export const useCheckAuth = (): CheckAuth => { ? error.redirectTo : redirectTo ); - const shouldSkipNotify = - disableNotification || - (error && error.message === false); + const shouldSkipNotify = error && error.message === false; !shouldSkipNotify && notify( getErrorMessage(error, 'ra.auth.auth_check_error'), @@ -92,16 +85,13 @@ const checkAuthWithoutAuthProvider = () => Promise.resolve(); * @param {Object} params The parameters to pass to the authProvider * @param {boolean} logoutOnFailure Whether the user should be logged out if the authProvider fails to authenticate them. True by default. * @param {string} redirectTo The login form url. Defaults to '/login' - * @param {boolean} disableNotification Avoid showing a notification after the user is logged out. false by default. * * @return {Promise} Resolved to the authProvider response if the user passes the check, or rejected with an error otherwise */ export type CheckAuth = ( params?: any, logoutOnFailure?: boolean, - redirectTo?: string, - /** @deprecated to disable the notification, authProvider.checkAuth() should return an object with an error property set to true */ - disableNotification?: boolean + redirectTo?: string ) => Promise; const getErrorMessage = (error, defaultMessage) => From 53afd3ca08734426ef0a2482495383876ad5ce17 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Tue, 23 Apr 2024 14:59:32 +0200 Subject: [PATCH 02/22] add an upgrade point for disableNotification param --- docs/Upgrade.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 76cbb63b99d..e500ed314bd 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -924,6 +924,17 @@ The `` component no longer accepts a `touched` prop. This prop If you were using this prop, you can safely remove it. +## `disableNotification` Param of `useCheckAuth` Was Removed + +The `useCheckAuth` hook no longer accepts the deprecated `disableNotification` param. To disabe the notification at the `checkAuth` call, `authProvider.checkAuth()` should return a rejected promise with a `falsy` message: + +```ts +const authProvider: AuthProvider = { + //... + checkAuth: () => Promise.reject({ message: false }), +} +``` + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. From 5e7b2f940d65b3a12347eb49b7e1b5879d719b09 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Tue, 23 Apr 2024 15:23:24 +0200 Subject: [PATCH 03/22] remove useless disableNotification in useCheckAuth spec --- packages/ra-core/src/auth/useCheckAuth.spec.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/ra-core/src/auth/useCheckAuth.spec.tsx b/packages/ra-core/src/auth/useCheckAuth.spec.tsx index 07dc8dfd93d..85d62a5fc8c 100644 --- a/packages/ra-core/src/auth/useCheckAuth.spec.tsx +++ b/packages/ra-core/src/auth/useCheckAuth.spec.tsx @@ -21,20 +21,18 @@ const TestComponent = ({ params, logoutOnFailure, redirectTo, - disableNotification, }: { params?: any; logoutOnFailure?: boolean; redirectTo?: string; - disableNotification?: boolean; }) => { const [authenticated, setAuthenticated] = useState(true); const checkAuth = useCheckAuth(); useEffect(() => { - checkAuth(params, logoutOnFailure, redirectTo, disableNotification) + checkAuth(params, logoutOnFailure, redirectTo) .then(() => setAuthenticated(true)) .catch(() => setAuthenticated(false)); - }, [params, logoutOnFailure, redirectTo, disableNotification, checkAuth]); + }, [params, logoutOnFailure, redirectTo, checkAuth]); return
{authenticated ? 'authenticated' : 'not authenticated'}
; }; From 6d8dcbb5eb93818db40f2f6f1fd2058bff486b12 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Tue, 23 Apr 2024 16:48:52 +0200 Subject: [PATCH 04/22] remove disableNotification from useLogoutIfAccessDenied --- docs/Upgrade.md | 18 ++++++ .../src/auth/useLogoutIfAccessDenied.spec.tsx | 59 +++++++------------ .../src/auth/useLogoutIfAccessDenied.ts | 11 +--- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index e500ed314bd..0c972b31c3b 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -935,6 +935,24 @@ const authProvider: AuthProvider = { } ``` +## `disableNotification` Param of `useLogoutIfAccessDenied` Was Removed + +The `useLogoutIfAccessDenied` hook no longer accepts the deprecated `disableNotification` param. To disabe the notification at the `checkError` call, `authProvider.checkError()` should return a rejected promise with a `falsy` message: + +```ts +const authProvider: AuthProvider = { + //... + checkError: () => Promise.reject({ message: false }), +} +``` + +Or the `useLogoutIfAccessDenied` hook could be called with an error param as follows: + +```ts +const logoutIfAccessDenied = useLogoutIfAccessDenied(); +logoutIfAccessDenied(new Error('Denied')); +``` + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-core/src/auth/useLogoutIfAccessDenied.spec.tsx b/packages/ra-core/src/auth/useLogoutIfAccessDenied.spec.tsx index dcd79382766..f4365066849 100644 --- a/packages/ra-core/src/auth/useLogoutIfAccessDenied.spec.tsx +++ b/packages/ra-core/src/auth/useLogoutIfAccessDenied.spec.tsx @@ -39,18 +39,12 @@ const authProvider: AuthProvider = { getPermissions: () => Promise.reject('bad method'), }; -const TestComponent = ({ - error, - disableNotification, -}: { - error?: any; - disableNotification?: boolean; -}) => { +const TestComponent = ({ error }: { error?: any }) => { const [loggedOut, setLoggedOut] = useSafeSetState(false); const logoutIfAccessDenied = useLogoutIfAccessDenied(); useEffect(() => { - logoutIfAccessDenied(error, disableNotification).then(setLoggedOut); - }, [error, disableNotification, logoutIfAccessDenied, setLoggedOut]); + logoutIfAccessDenied(error).then(setLoggedOut); + }, [error, logoutIfAccessDenied, setLoggedOut]); return
{loggedOut ? '' : 'logged in'}
; }; @@ -169,28 +163,6 @@ describe('useLogoutIfAccessDenied', () => { expect(screen.queryByText('logged in')).toBeNull(); }); - it('should logout without showing a notification if disableAuthentication is true', async () => { - render( - - } - />, - { - wrapper: TestWrapper, - } - ); - await waitFor(() => { - expect(authProvider.logout).toHaveBeenCalledTimes(1); - expect(notify).toHaveBeenCalledTimes(0); - expect(screen.queryByText('logged in')).toBeNull(); - }); - }); - it('should logout without showing a notification if authProvider returns error with message false', async () => { render( @@ -203,14 +175,7 @@ describe('useLogoutIfAccessDenied', () => { }} > - - - - } - /> + } /> @@ -222,6 +187,22 @@ describe('useLogoutIfAccessDenied', () => { }); }); + it('should logout without showing a notification if it has been called with error param', async () => { + render( + } + />, + { + wrapper: TestWrapper, + } + ); + await waitFor(() => { + expect(authProvider.logout).toHaveBeenCalledTimes(0); + expect(notify).toHaveBeenCalledTimes(0); + }); + }); + it('should notify if passed an error with a message that makes the authProvider throw', async () => { render( { const notify = useNotify(); const navigate = useNavigate(); const logoutIfAccessDenied = useCallback( - (error?: any, disableNotification?: boolean) => + (error?: any) => authProvider .checkError(error) .then(() => false) .catch(async e => { const logoutUser = e?.logoutUser ?? true; - //manual debounce if (timer) { // side effects already triggered in this tick, exit @@ -68,7 +67,6 @@ const useLogoutIfAccessDenied = (): LogoutIfAccessDenied => { : undefined; const shouldNotify = !( - disableNotification || (e && e.message === false) || (error && error.message === false) || redirectTo?.startsWith('http') @@ -127,15 +125,10 @@ const logoutIfAccessDeniedWithoutProvider = () => Promise.resolve(false); * If the authProvider rejects the call, logs the user out and shows a logged out notification. * * @param {Error} error An Error object (usually returned by the dataProvider) - * @param {boolean} disableNotification Avoid showing a notification after the user is logged out. false by default. * * @return {Promise} Resolved to true if there was a logout, false otherwise */ -type LogoutIfAccessDenied = ( - error?: any, - /** @deprecated to disable the notification, authProvider.checkAuth() should return an object with an error property set to true */ - disableNotification?: boolean -) => Promise; +type LogoutIfAccessDenied = (error?: any) => Promise; const getErrorMessage = (error, defaultMessage) => typeof error === 'string' From 9d750763066525df35ff5a9e500442c8c66a6c85 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Tue, 23 Apr 2024 17:34:21 +0200 Subject: [PATCH 05/22] Apply suggestions from code review Co-authored-by: Francois Zaninotto --- docs/Upgrade.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 0c972b31c3b..b9e91b92de9 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -924,9 +924,9 @@ The `` component no longer accepts a `touched` prop. This prop If you were using this prop, you can safely remove it. -## `disableNotification` Param of `useCheckAuth` Was Removed +## `useCheckAuth` No Longer Accepts A `disableNotification` Param -The `useCheckAuth` hook no longer accepts the deprecated `disableNotification` param. To disabe the notification at the `checkAuth` call, `authProvider.checkAuth()` should return a rejected promise with a `falsy` message: +The `useCheckAuth` hook no longer accepts the deprecated `disableNotification` param. To disable the "Authentication required" notification when calling `checkAuth`, `authProvider.checkAuth()` should return a rejected promise with the value `{ message: false }`: ```ts const authProvider: AuthProvider = { @@ -935,9 +935,9 @@ const authProvider: AuthProvider = { } ``` -## `disableNotification` Param of `useLogoutIfAccessDenied` Was Removed +## `useLogoutIfAccessDenied` No Longer Accepts A `disableNotification` Param -The `useLogoutIfAccessDenied` hook no longer accepts the deprecated `disableNotification` param. To disabe the notification at the `checkError` call, `authProvider.checkError()` should return a rejected promise with a `falsy` message: +The `useLogoutIfAccessDenied` hook no longer accepts the deprecated `disableNotification` param. To disable the "Authentication required" notification when `checkError` is called, `authProvider.checkError()` should return a rejected promise with the value `{ message: false }`: ```ts const authProvider: AuthProvider = { From c680d513eea88fa33e0c27ecca0c04ead6979ddb Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Tue, 23 Apr 2024 17:58:42 +0200 Subject: [PATCH 06/22] resource param from useDeleteWithUndoController and useDeleteWithConfirmController are no longer deprecated --- .../src/controller/button/useDeleteWithConfirmController.tsx | 1 - .../src/controller/button/useDeleteWithUndoController.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/ra-core/src/controller/button/useDeleteWithConfirmController.tsx b/packages/ra-core/src/controller/button/useDeleteWithConfirmController.tsx index 422d57bf2b5..9b11d69a101 100644 --- a/packages/ra-core/src/controller/button/useDeleteWithConfirmController.tsx +++ b/packages/ra-core/src/controller/button/useDeleteWithConfirmController.tsx @@ -178,7 +178,6 @@ export interface UseDeleteWithConfirmControllerParams< mutationMode?: MutationMode; record?: RecordType; redirect?: RedirectionSideEffect; - // @deprecated. This hook get the resource from the context resource?: string; onClick?: ReactEventHandler; mutationOptions?: UseMutationOptions< diff --git a/packages/ra-core/src/controller/button/useDeleteWithUndoController.tsx b/packages/ra-core/src/controller/button/useDeleteWithUndoController.tsx index 547307dd0a4..954471abc1a 100644 --- a/packages/ra-core/src/controller/button/useDeleteWithUndoController.tsx +++ b/packages/ra-core/src/controller/button/useDeleteWithUndoController.tsx @@ -134,7 +134,6 @@ export interface UseDeleteWithUndoControllerParams< > { record?: RecordType; redirect?: RedirectionSideEffect; - // @deprecated. This hook get the resource from the context resource?: string; onClick?: ReactEventHandler; mutationOptions?: UseMutationOptions< From 381f9396412ebf08c9dc9fdd9e90ce3b87e952e1 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Wed, 24 Apr 2024 15:31:55 +0200 Subject: [PATCH 07/22] remove `data` from `CreateControllerResult` --- packages/ra-core/src/controller/create/useCreateController.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/ra-core/src/controller/create/useCreateController.ts b/packages/ra-core/src/controller/create/useCreateController.ts index 982eb253145..fd4fccc0081 100644 --- a/packages/ra-core/src/controller/create/useCreateController.ts +++ b/packages/ra-core/src/controller/create/useCreateController.ts @@ -213,9 +213,6 @@ export interface CreateControllerProps< export interface CreateControllerResult< RecordType extends Omit = any > extends SaveContextValue { - // Necessary for actions (EditActions) which expect a data prop containing the record - // @deprecated - to be removed in 4.0d - data?: RecordType; defaultTitle?: string; isFetching: boolean; isPending: boolean; From 9c38cc8698365f788114cacebd723346c6b37ee9 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Wed, 24 Apr 2024 15:37:13 +0200 Subject: [PATCH 08/22] remove `defaultReferenceSource` and `referenceSource` from `useReferenceInputController` --- .../src/controller/input/useReferenceInputController.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/ra-core/src/controller/input/useReferenceInputController.ts b/packages/ra-core/src/controller/input/useReferenceInputController.ts index 7f1fec4c2aa..6c55df9874c 100644 --- a/packages/ra-core/src/controller/input/useReferenceInputController.ts +++ b/packages/ra-core/src/controller/input/useReferenceInputController.ts @@ -7,9 +7,6 @@ import { ChoicesContextValue } from '../../form'; import { useReferenceParams } from './useReferenceParams'; import { UseQueryOptions } from '@tanstack/react-query'; -const defaultReferenceSource = (resource: string, source: string) => - `${resource}@${source}`; - /** * A hook for choosing a reference record. Useful for foreign keys. * @@ -218,8 +215,6 @@ export interface UseReferenceInputControllerParams< perPage?: number; record?: RaRecord; reference: string; - // @deprecated ignored - referenceSource?: typeof defaultReferenceSource; resource?: string; sort?: SortPayload; source: string; From 2288159da170ed6f2683f466739f7cdb98d4c33a Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Thu, 25 Apr 2024 17:45:00 +0200 Subject: [PATCH 09/22] remove onError type --- docs/Upgrade.md | 3 +++ packages/ra-core/src/types.ts | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index b9e91b92de9..5cf0fbbec89 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -952,6 +952,9 @@ Or the `useLogoutIfAccessDenied` hook could be called with an error param as fol const logoutIfAccessDenied = useLogoutIfAccessDenied(); logoutIfAccessDenied(new Error('Denied')); ``` +## `onError` Type From `ra-core` Was Removed + +The `onError` type from `ra-core` was removed. Use `OnError` instead. ## Upgrading to v4 diff --git a/packages/ra-core/src/types.ts b/packages/ra-core/src/types.ts index 5884f5643d8..0bf2ee45aae 100644 --- a/packages/ra-core/src/types.ts +++ b/packages/ra-core/src/types.ts @@ -257,8 +257,6 @@ export type OnSuccess = ( ) => void; export type OnError = (error?: any, variables?: any, context?: any) => void; -// @deprecated - use OnError instead -export type onError = OnError; export type TransformData = ( data: any, @@ -271,7 +269,7 @@ export interface UseDataProviderOptions { meta?: object; mutationMode?: MutationMode; onSuccess?: OnSuccess; - onError?: onError; + onError?: OnError; enabled?: boolean; } From 35522e1c89ae9109147c0203e35f57e16a9b1fcb Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 10:54:53 +0200 Subject: [PATCH 10/22] useLocale is no longer deprecated --- packages/ra-core/src/i18n/useLocale.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ra-core/src/i18n/useLocale.tsx b/packages/ra-core/src/i18n/useLocale.tsx index 83f06b55a6b..0113092df5b 100644 --- a/packages/ra-core/src/i18n/useLocale.tsx +++ b/packages/ra-core/src/i18n/useLocale.tsx @@ -15,8 +15,6 @@ import { useLocaleState } from './useLocaleState'; * const locale = useLocale(); * return {availableLanguages[locale]}; * } - * - * @deprecated use useLocaleState instead */ export const useLocale = () => { const [locale] = useLocaleState(); From 40c0babd2137247b3c08b6daf4fcf99c1a6ba86b Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 10:56:23 +0200 Subject: [PATCH 11/22] useSetLocale is no longer deprecated --- packages/ra-core/src/i18n/useSetLocale.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ra-core/src/i18n/useSetLocale.tsx b/packages/ra-core/src/i18n/useSetLocale.tsx index 80da12f08ee..6c4bcc7296e 100644 --- a/packages/ra-core/src/i18n/useSetLocale.tsx +++ b/packages/ra-core/src/i18n/useSetLocale.tsx @@ -23,8 +23,6 @@ import { useLocaleState } from './useLocaleState'; * } * ); * } - * - * @deprecated use useLocaleState instead */ export const useSetLocale = () => { const [, setLocale] = useLocaleState(); From e0f6fce79675302145862f82d98eb9d9ffa97b0b Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 11:00:50 +0200 Subject: [PATCH 12/22] remove deprecated `linkToRecord` helper --- docs/Upgrade.md | 4 ++++ packages/ra-core/src/routing/index.ts | 1 - .../ra-core/src/routing/linkToRecord.spec.ts | 23 ------------------- packages/ra-core/src/routing/linkToRecord.ts | 12 ---------- 4 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 packages/ra-core/src/routing/linkToRecord.spec.ts delete mode 100644 packages/ra-core/src/routing/linkToRecord.ts diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 5cf0fbbec89..6ab796976f2 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -956,6 +956,10 @@ logoutIfAccessDenied(new Error('Denied')); The `onError` type from `ra-core` was removed. Use `OnError` instead. +## `linkToRecord` Helper Was Removed + +The `linkToRecord` helper was removed. Use [`useCreatePath`](https://marmelab.com/react-admin/Routing.html#linking-to-a-page) instead. + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-core/src/routing/index.ts b/packages/ra-core/src/routing/index.ts index 17603276874..8250df51b14 100644 --- a/packages/ra-core/src/routing/index.ts +++ b/packages/ra-core/src/routing/index.ts @@ -1,6 +1,5 @@ export * from './AdminRouter'; export * from './BasenameContextProvider'; -export * from './linkToRecord'; export * from './resolveRedirectTo'; export * from './RestoreScrollPosition'; export * from './useBasename'; diff --git a/packages/ra-core/src/routing/linkToRecord.spec.ts b/packages/ra-core/src/routing/linkToRecord.spec.ts deleted file mode 100644 index 08a955260b7..00000000000 --- a/packages/ra-core/src/routing/linkToRecord.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import expect from 'expect'; -import { linkToRecord } from './linkToRecord'; - -describe('Linking to a record', () => { - it('should generate valid edition links by default', () => { - expect(linkToRecord('books', 22)).toEqual('books/22'); - expect(linkToRecord('books', '/books/13')).toEqual( - 'books/%2Fbooks%2F13' - ); - expect(linkToRecord('blogs', 'https://dunglas.fr')).toEqual( - 'blogs/https%3A%2F%2Fdunglas.fr' - ); - }); - it('should generate valid show links if requested', () => { - expect(linkToRecord('books', 22, 'show')).toEqual('books/22/show'); - expect(linkToRecord('books', '/books/13', 'show')).toEqual( - 'books/%2Fbooks%2F13/show' - ); - expect(linkToRecord('blogs', 'https://dunglas.fr', 'show')).toEqual( - 'blogs/https%3A%2F%2Fdunglas.fr/show' - ); - }); -}); diff --git a/packages/ra-core/src/routing/linkToRecord.ts b/packages/ra-core/src/routing/linkToRecord.ts deleted file mode 100644 index 25a5488385d..00000000000 --- a/packages/ra-core/src/routing/linkToRecord.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @deprecated use useCreatePath instead - */ -export const linkToRecord = (resource, id, linkType = 'edit') => { - const link = `${resource}/${encodeURIComponent(id)}`; - - if (linkType === 'show') { - return `${link}/show`; - } - - return link; -}; From 3b19836759f3adbf223f97eec50f307256649446 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 11:07:41 +0200 Subject: [PATCH 13/22] remove deprecated `resolveRedirectTo` helper --- docs/Upgrade.md | 5 +++ packages/ra-core/src/routing/index.ts | 1 - .../src/routing/resolveRedirectTo.spec.ts | 25 ----------- .../ra-core/src/routing/resolveRedirectTo.ts | 42 ------------------- 4 files changed, 5 insertions(+), 68 deletions(-) delete mode 100644 packages/ra-core/src/routing/resolveRedirectTo.spec.ts delete mode 100644 packages/ra-core/src/routing/resolveRedirectTo.ts diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 6ab796976f2..93bc52f824c 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -960,6 +960,11 @@ The `onError` type from `ra-core` was removed. Use `OnError` instead. The `linkToRecord` helper was removed. Use [`useCreatePath`](https://marmelab.com/react-admin/Routing.html#linking-to-a-page) instead. +## `resolveRedirectTo` Helper Was Removed + +The `resolveRedirectTo` helper was removed. Use [`useCreatePath`](https://marmelab.com/react-admin/Routing.html#linking-to-a-page) instead. + + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-core/src/routing/index.ts b/packages/ra-core/src/routing/index.ts index 8250df51b14..7854460a987 100644 --- a/packages/ra-core/src/routing/index.ts +++ b/packages/ra-core/src/routing/index.ts @@ -1,6 +1,5 @@ export * from './AdminRouter'; export * from './BasenameContextProvider'; -export * from './resolveRedirectTo'; export * from './RestoreScrollPosition'; export * from './useBasename'; export * from './useCreatePath'; diff --git a/packages/ra-core/src/routing/resolveRedirectTo.spec.ts b/packages/ra-core/src/routing/resolveRedirectTo.spec.ts deleted file mode 100644 index e386e8703d6..00000000000 --- a/packages/ra-core/src/routing/resolveRedirectTo.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import expect from 'expect'; -import { resolveRedirectTo } from './resolveRedirectTo'; - -describe('resolveRedirectTo', () => { - it('should accept a view name', () => { - expect(resolveRedirectTo('list', 'books', 1)).toEqual('/books'); - expect(resolveRedirectTo('create', 'books', 1)).toEqual( - '/books/create' - ); - expect(resolveRedirectTo('edit', 'books', 1)).toEqual('/books/1'); - expect(resolveRedirectTo('show', 'books', 1)).toEqual('/books/1/show'); - }); - - it('should accept a custom route name', () => { - expect(resolveRedirectTo('home', 'books', 1)).toEqual('home'); - }); - - it('should accept a function as parameter', () => { - const redirect = (resource, id, data) => - `/related/${data.related_id}/show`; - expect( - resolveRedirectTo(redirect, 'books', 1, { related_id: 3 }) - ).toEqual('/related/3/show'); - }); -}); diff --git a/packages/ra-core/src/routing/resolveRedirectTo.ts b/packages/ra-core/src/routing/resolveRedirectTo.ts deleted file mode 100644 index 84dfd8d404d..00000000000 --- a/packages/ra-core/src/routing/resolveRedirectTo.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { To } from 'react-router-dom'; - -/** - * @deprecated use useCreatePath instead - */ -export const resolveRedirectTo = ( - redirectTo, - resource: string, - id?, - data?, - basename: string = '' -): To => { - if (typeof redirectTo === 'function') { - const target: To = redirectTo(resource, id, data); - return typeof target === 'string' - ? removeDoubleSlashes(`${basename}/${target}`) - : { - pathname: removeDoubleSlashes( - `${basename}/${target.pathname}` - ), - ...target, - }; - } - switch (redirectTo) { - case 'list': - return removeDoubleSlashes(`${basename}/${resource}`); - case 'create': - return removeDoubleSlashes(`${basename}/${resource}/create`); - case 'edit': - return removeDoubleSlashes( - `${basename}/${resource}/${encodeURIComponent(id)}` - ); - case 'show': - return removeDoubleSlashes( - `${basename}/${resource}/${encodeURIComponent(id)}/show` - ); - default: - return redirectTo; - } -}; - -const removeDoubleSlashes = (path: string) => path.replace('//', '/'); From ba0dbfdf4bb79b8211e0cfbc8c7272253335cddb Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 11:22:27 +0200 Subject: [PATCH 14/22] remove deprecated `formClassName` of `FieldProps` and `CommonInputProps` types --- docs/Upgrade.md | 7 +++++++ .../ra-ui-materialui/src/field/sanitizeFieldRestProps.ts | 1 - packages/ra-ui-materialui/src/field/types.ts | 9 --------- packages/ra-ui-materialui/src/input/CommonInputProps.ts | 4 ---- packages/ra-ui-materialui/src/input/SelectArrayInput.tsx | 1 - .../ra-ui-materialui/src/input/sanitizeInputRestProps.ts | 1 - 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 93bc52f824c..19b585670e8 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -964,6 +964,13 @@ The `linkToRecord` helper was removed. Use [`useCreatePath`](https://marmelab.co The `resolveRedirectTo` helper was removed. Use [`useCreatePath`](https://marmelab.com/react-admin/Routing.html#linking-to-a-page) instead. +## `formClassName` Prop Of `FieldProps` Type Was Removed + +The deprecated `formClassName` prop of `FieldProps` type has been removed as it is no longer used. + +## `formClassName` Prop Of `CommonInputProps` Type Was Removed + +The deprecated `formClassName` prop of `CommonInputProps` type has been removed as it is no longer used. ## Upgrading to v4 diff --git a/packages/ra-ui-materialui/src/field/sanitizeFieldRestProps.ts b/packages/ra-ui-materialui/src/field/sanitizeFieldRestProps.ts index cc66f58174a..4b981fc6c11 100644 --- a/packages/ra-ui-materialui/src/field/sanitizeFieldRestProps.ts +++ b/packages/ra-ui-materialui/src/field/sanitizeFieldRestProps.ts @@ -2,7 +2,6 @@ export const sanitizeFieldRestProps: (props: any) => any = ({ cellClassName, className, emptyText, - formClassName, fullWidth, headerClassName, label, diff --git a/packages/ra-ui-materialui/src/field/types.ts b/packages/ra-ui-materialui/src/field/types.ts index 847e34a0f5c..0b4bca9154b 100644 --- a/packages/ra-ui-materialui/src/field/types.ts +++ b/packages/ra-ui-materialui/src/field/types.ts @@ -112,11 +112,6 @@ export interface FieldProps< */ headerClassName?: string; - /* - * @deprecated this property is not used anymore - */ - formClassName?: string; - /** * The text alignment for the cell content, when used inside . * @@ -185,10 +180,6 @@ export interface PublicFieldProps< className?: string; cellClassName?: string; headerClassName?: string; - /* - * @deprecated this property is not used anymore - */ - formClassName?: string; textAlign?: TextAlign; emptyText?: string; fullWidth?: boolean; diff --git a/packages/ra-ui-materialui/src/input/CommonInputProps.ts b/packages/ra-ui-materialui/src/input/CommonInputProps.ts index 86a79712451..4cab53bc3c4 100644 --- a/packages/ra-ui-materialui/src/input/CommonInputProps.ts +++ b/packages/ra-ui-materialui/src/input/CommonInputProps.ts @@ -2,10 +2,6 @@ import { InputProps } from 'ra-core'; export type CommonInputProps = InputProps & { cellClassName?: string; - /* - * @deprecated this property is not used anymore - */ - formClassName?: string; fullWidth?: boolean; headerCellClassName?: string; margin?: 'none' | 'dense' | 'normal'; diff --git a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx index 422d12b8e7c..6da9086c4c8 100644 --- a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx @@ -403,7 +403,6 @@ const sanitizeRestProps = ({ enableGetChoices, filter, filterToQuery, - formClassName, initializeForm, initialValue, input, diff --git a/packages/ra-ui-materialui/src/input/sanitizeInputRestProps.ts b/packages/ra-ui-materialui/src/input/sanitizeInputRestProps.ts index 604ea26cec7..774adbbc820 100644 --- a/packages/ra-ui-materialui/src/input/sanitizeInputRestProps.ts +++ b/packages/ra-ui-materialui/src/input/sanitizeInputRestProps.ts @@ -9,7 +9,6 @@ export const sanitizeInputRestProps = ({ error, format, formatOnBlur, - formClassName, initialValue, initializeForm, input, From a5cdafad6cc39418b618965538a4464b592db243 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 11:27:14 +0200 Subject: [PATCH 15/22] remove deprecated `PublicFieldProps` interface --- docs/Upgrade.md | 4 ++++ packages/ra-ui-materialui/src/field/index.ts | 4 ++-- packages/ra-ui-materialui/src/field/types.ts | 24 -------------------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 19b585670e8..66fc4640ef4 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -972,6 +972,10 @@ The deprecated `formClassName` prop of `FieldProps` type has been removed as it The deprecated `formClassName` prop of `CommonInputProps` type has been removed as it is no longer used. +## `PublicFieldProps` Interface Was Removed + +`PublicFieldProps` interface has been removed. Use `FieldProps` instead. + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-ui-materialui/src/field/index.ts b/packages/ra-ui-materialui/src/field/index.ts index aef0eef461a..9e07f4d1a86 100644 --- a/packages/ra-ui-materialui/src/field/index.ts +++ b/packages/ra-ui-materialui/src/field/index.ts @@ -1,4 +1,4 @@ -import { FieldProps, InjectedFieldProps, PublicFieldProps } from './types'; +import { FieldProps, InjectedFieldProps } from './types'; export * from './ArrayField'; export * from './BooleanField'; @@ -24,4 +24,4 @@ export * from './TranslatableFieldsTabContent'; export * from './UrlField'; export * from './WrapperField'; -export type { FieldProps, InjectedFieldProps, PublicFieldProps }; +export type { FieldProps, InjectedFieldProps }; diff --git a/packages/ra-ui-materialui/src/field/types.ts b/packages/ra-ui-materialui/src/field/types.ts index 0b4bca9154b..193a198a345 100644 --- a/packages/ra-ui-materialui/src/field/types.ts +++ b/packages/ra-ui-materialui/src/field/types.ts @@ -163,30 +163,6 @@ export interface FieldProps< resource?: string; } -/** - * @deprecated use FieldProps instead - */ -export interface PublicFieldProps< - RecordType extends Record = Record, - SortByType = unknown -> { - sortBy?: unknown extends SortByType - ? Call - : SortByType; - sortByOrder?: SortOrder; - source?: Call; - label?: string | ReactElement | boolean; - sortable?: boolean; - className?: string; - cellClassName?: string; - headerClassName?: string; - textAlign?: TextAlign; - emptyText?: string; - fullWidth?: boolean; - record?: RecordType; - resource?: string; -} - /** * @deprecated use FieldProps instead */ From 7761b2aba3207d82a03ab907286000d97e318538 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 11:28:33 +0200 Subject: [PATCH 16/22] remove deprecated `InjectedFieldProps` interface --- docs/Upgrade.md | 4 ++++ packages/ra-ui-materialui/src/field/index.ts | 4 ++-- packages/ra-ui-materialui/src/field/types.ts | 8 -------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 66fc4640ef4..6e1a2e22df3 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -976,6 +976,10 @@ The deprecated `formClassName` prop of `CommonInputProps` type has been removed `PublicFieldProps` interface has been removed. Use `FieldProps` instead. +## `InjectedFieldProps` Interface Was Removed + +`InjectedFieldProps` interface has been removed. Use `FieldProps` instead. + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-ui-materialui/src/field/index.ts b/packages/ra-ui-materialui/src/field/index.ts index 9e07f4d1a86..b46f2bc4670 100644 --- a/packages/ra-ui-materialui/src/field/index.ts +++ b/packages/ra-ui-materialui/src/field/index.ts @@ -1,4 +1,4 @@ -import { FieldProps, InjectedFieldProps } from './types'; +import { FieldProps } from './types'; export * from './ArrayField'; export * from './BooleanField'; @@ -24,4 +24,4 @@ export * from './TranslatableFieldsTabContent'; export * from './UrlField'; export * from './WrapperField'; -export type { FieldProps, InjectedFieldProps }; +export type { FieldProps }; diff --git a/packages/ra-ui-materialui/src/field/types.ts b/packages/ra-ui-materialui/src/field/types.ts index 193a198a345..5e061835a3d 100644 --- a/packages/ra-ui-materialui/src/field/types.ts +++ b/packages/ra-ui-materialui/src/field/types.ts @@ -163,14 +163,6 @@ export interface FieldProps< resource?: string; } -/** - * @deprecated use FieldProps instead - */ -export interface InjectedFieldProps { - record?: RecordType; - resource?: string; -} - export const fieldPropTypes = { sortBy: PropTypes.string, sortByOrder: PropTypes.oneOf(['ASC', 'DESC']), From 8649d33640b01b67318d597975038453dd6f571d Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 14:42:05 +0200 Subject: [PATCH 17/22] remove depreacted `rowStyle` prop from `` --- docs/SimpleList.md | 21 ------------------- docs/Upgrade.md | 4 ++++ .../src/list/SimpleList/SimpleList.tsx | 13 +----------- 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/docs/SimpleList.md b/docs/SimpleList.md index 2bf275370cf..fabf1f5fe11 100644 --- a/docs/SimpleList.md +++ b/docs/SimpleList.md @@ -49,7 +49,6 @@ export const PostList = () => ( | `leftIcon` | Optional | function | | A function returning an `` component to display before the primary text. | | `rightAvatar` | Optional | function | | A function returning an `` component to display after the primary text. | | `rightIcon` | Optional | function | | A function returning an `` component to display after the primary text. | -| `rowStyle` | Optional | function | | A function returning a style object to apply to each row. | | `rowSx` | Optional | function | | A function returning a sx object to apply to each row. | | `empty` | Optional | ReactElement | | A ReactElement to display instead of the list when the data is empty. | @@ -190,26 +189,6 @@ This prop should be a function returning an `` component. When present, This prop should be a function returning an `` component. When present, the `` renders a `` after the ``. -## `rowStyle` - -*Deprecated - use [`rowSx`](#rowsx) instead.* - -This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a style object. The style object is applied to the `` styles prop. - -```jsx -import { List, SimpleList } from 'react-admin'; - -const postRowStyle = (record, index) => ({ - backgroundColor: record.nb_views >= 500 ? '#efe' : 'white', -}); - -export const PostList = () => ( - - record.title} rowStyle={postRowStyle} /> - -); -``` - ## `rowSx` This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a Material UI [`sx`](https://mui.com/system/getting-started/the-sx-prop/). The style object is applied to the `` `sx` prop. diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 6e1a2e22df3..2386e70f3d4 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -980,6 +980,10 @@ The deprecated `formClassName` prop of `CommonInputProps` type has been removed `InjectedFieldProps` interface has been removed. Use `FieldProps` instead. +## `` Is No Longer Supported + +The deprecated `rowStyle` prop from `` is no longer supported. Use [`rowSx`](./SimpleList.md#rowsx) instead. + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx index 822a4bcac7e..dc34cfd79f6 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx @@ -47,7 +47,6 @@ import { ListNoResults } from '../ListNoResults'; * - rightAvatar: same * - rightIcon: same * - linkType: 'edit' or 'show', or a function returning 'edit' or 'show' based on the record - * - rowStyle: function returning a style object based on (record, index) * - rowSx: function returning a sx object based on (record, index) * * @example // Display all posts as a List @@ -83,7 +82,6 @@ export const SimpleList = ( secondaryText, tertiaryText, rowSx, - rowStyle, ...rest } = props; const { data, isPending, total } = useListContextWithProps( @@ -137,11 +135,6 @@ export const SimpleList = ( resource={resource} id={record.id} record={record} - style={ - rowStyle - ? rowStyle(record, rowIndex) - : undefined - } sx={rowSx?.(record, rowIndex)} > {leftIcon && ( @@ -261,7 +254,6 @@ SimpleList.propTypes = { PropTypes.element, PropTypes.string, ]), - rowStyle: PropTypes.func, rowSx: PropTypes.func, }; @@ -284,10 +276,7 @@ export interface SimpleListProps secondaryText?: FunctionToElement | ReactElement | string; tertiaryText?: FunctionToElement | ReactElement | string; rowSx?: (record: RecordType, index: number) => SxProps; - /** - * @deprecated Use rowSx instead - */ - rowStyle?: (record: RecordType, index: number) => any; + // can be injected when using the component without context resource?: string; data?: RecordType[]; From bc484a45d5d1fe411f4429cda554367e4c0433b0 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 14:42:26 +0200 Subject: [PATCH 18/22] fix doc link --- docs/Upgrade.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 2386e70f3d4..a2b9831f863 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -962,7 +962,7 @@ The `linkToRecord` helper was removed. Use [`useCreatePath`](https://marmelab.co ## `resolveRedirectTo` Helper Was Removed -The `resolveRedirectTo` helper was removed. Use [`useCreatePath`](https://marmelab.com/react-admin/Routing.html#linking-to-a-page) instead. +The `resolveRedirectTo` helper was removed. Use [`useCreatePath`](./Routing.html#linking-to-a-page) instead. ## `formClassName` Prop Of `FieldProps` Type Was Removed From 9376346e341df6984ab6af659e35bd8adbfc5d2b Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 15:35:43 +0200 Subject: [PATCH 19/22] remove depreacted `theme` prop from `` --- docs/Upgrade.md | 27 +++++++++++++++++++ .../src/detail/EditGuesser.spec.tsx | 2 +- .../src/detail/ShowGuesser.spec.tsx | 2 +- .../src/list/ListGuesser.spec.tsx | 2 +- .../src/theme/ThemeProvider.spec.tsx | 10 ------- .../src/theme/ThemeProvider.tsx | 16 +++-------- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/docs/Upgrade.md b/docs/Upgrade.md index a2b9831f863..6a98116856b 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -984,6 +984,33 @@ The deprecated `formClassName` prop of `CommonInputProps` type has been removed The deprecated `rowStyle` prop from `` is no longer supported. Use [`rowSx`](./SimpleList.md#rowsx) instead. +## `` Is No Longer Supported + +The deprecated `` prop was removed. Use the `ThemesContext.Provider` instead: + +```diff +-import { ThemeProvider } from 'react-admin'; ++import { ThemeProvider, ThemesContext } from 'react-admin'; + + export const ThemeWrapper = ({ children }) => { + return ( +- +- {children} +- ++ {children} ++ + ); + }; +``` + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx b/packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx index 82d392d70fa..f8251191f4e 100644 --- a/packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx +++ b/packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx @@ -25,7 +25,7 @@ describe('', () => { getMany: () => Promise.resolve({ data: [] }), }; render( - + diff --git a/packages/ra-ui-materialui/src/detail/ShowGuesser.spec.tsx b/packages/ra-ui-materialui/src/detail/ShowGuesser.spec.tsx index e853a13fa5e..7d5e3c569de 100644 --- a/packages/ra-ui-materialui/src/detail/ShowGuesser.spec.tsx +++ b/packages/ra-ui-materialui/src/detail/ShowGuesser.spec.tsx @@ -24,7 +24,7 @@ describe('', () => { }), }; render( - + diff --git a/packages/ra-ui-materialui/src/list/ListGuesser.spec.tsx b/packages/ra-ui-materialui/src/list/ListGuesser.spec.tsx index cfe30aa083a..242d752d531 100644 --- a/packages/ra-ui-materialui/src/list/ListGuesser.spec.tsx +++ b/packages/ra-ui-materialui/src/list/ListGuesser.spec.tsx @@ -28,7 +28,7 @@ describe('', () => { getMany: () => Promise.resolve({ data: [], total: 0 }), }); render( - + diff --git a/packages/ra-ui-materialui/src/theme/ThemeProvider.spec.tsx b/packages/ra-ui-materialui/src/theme/ThemeProvider.spec.tsx index 1488d592da4..d925a0fe8de 100644 --- a/packages/ra-ui-materialui/src/theme/ThemeProvider.spec.tsx +++ b/packages/ra-ui-materialui/src/theme/ThemeProvider.spec.tsx @@ -82,14 +82,4 @@ describe('ThemeProvider', () => { const button = screen.getByText('Test'); expect(getComputedStyle(button).color).toBe(DARK_MODE_TEXT_COLOR); }); - - it('should fallback to using theme prop when used outside of a ThemesContext (for backwards compatibility)', () => { - render( - - - - ); - const button = screen.getByText('Test'); - expect(getComputedStyle(button).color).toBe(DARK_MODE_TEXT_COLOR); - }); }); diff --git a/packages/ra-ui-materialui/src/theme/ThemeProvider.tsx b/packages/ra-ui-materialui/src/theme/ThemeProvider.tsx index 64d6f3a652d..9cd03ebe055 100644 --- a/packages/ra-ui-materialui/src/theme/ThemeProvider.tsx +++ b/packages/ra-ui-materialui/src/theme/ThemeProvider.tsx @@ -6,7 +6,6 @@ import { } from '@mui/material/styles'; import { useMediaQuery } from '@mui/material'; -import { RaThemeOptions } from './types'; import { useTheme } from './useTheme'; import { useThemesContext } from './useThemesContext'; import { AdminChildren } from 'ra-core'; @@ -30,10 +29,7 @@ import { AdminChildren } from 'ra-core'; * * ); */ -export const ThemeProvider = ({ - children, - theme: themeOverride, -}: ThemeProviderProps) => { +export const ThemeProvider = ({ children }: ThemeProviderProps) => { const { lightTheme, darkTheme, defaultTheme } = useThemesContext(); const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)', { @@ -45,14 +41,12 @@ export const ThemeProvider = ({ const themeValue = useMemo(() => { try { - return createTheme( - mode === 'dark' ? darkTheme : lightTheme || themeOverride - ); + return createTheme(mode === 'dark' ? darkTheme : lightTheme); } catch (e) { console.warn('Failed to reuse custom theme from store', e); return createTheme(); } - }, [mode, themeOverride, lightTheme, darkTheme]); + }, [mode, lightTheme, darkTheme]); return ( @@ -64,8 +58,4 @@ export const ThemeProvider = ({ export interface ThemeProviderProps { children: AdminChildren; - /** - * @deprecated Use the `ThemesProvider` component instead. - */ - theme?: RaThemeOptions; } From 72ce3ce74701253db6f28bfd9b5862900d4ff32f Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Fri, 26 Apr 2024 15:41:17 +0200 Subject: [PATCH 20/22] remove depreacted `` component --- docs/ListTutorial.md | 1 - docs/Upgrade.md | 4 ++++ .../src/list/pagination/PaginationLimit.tsx | 19 ------------------- .../src/list/pagination/index.ts | 1 - 4 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 packages/ra-ui-materialui/src/list/pagination/PaginationLimit.tsx diff --git a/docs/ListTutorial.md b/docs/ListTutorial.md index fba5aeb21b2..c7cf72e631a 100644 --- a/docs/ListTutorial.md +++ b/docs/ListTutorial.md @@ -825,7 +825,6 @@ The [``](./Pagination.md) component gets the following constants fro * `hasPreviousPage`: True if the page number is greater than 1. * `hasNextPage`: True if the page number is lower than the total number of pages. * `actions`: A component that displays the pagination buttons (default: ``) -* `limit`: An element that is displayed if there is no data to show (default: ``) If you want to replace the default pagination by a "< previous - next >" pagination, create a pagination component like the following: diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 6a98116856b..7af934786d6 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -1011,6 +1011,10 @@ The deprecated `` prop was removed. Use the `ThemesContext. }; ``` +## `` Component Was Removed + +The deprecated `` component was removed. + ## Upgrading to v4 If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5. diff --git a/packages/ra-ui-materialui/src/list/pagination/PaginationLimit.tsx b/packages/ra-ui-materialui/src/list/pagination/PaginationLimit.tsx deleted file mode 100644 index cc8b9cf9fa3..00000000000 --- a/packages/ra-ui-materialui/src/list/pagination/PaginationLimit.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import * as React from 'react'; -import { memo } from 'react'; -import CardContent from '@mui/material/CardContent'; -import Typography from '@mui/material/Typography'; -import { useTranslate } from 'ra-core'; - -/** - * @deprecated Empty state should be handled by the component displaying data (Datagrid, SimpleList). - */ -export const PaginationLimit = memo(() => { - const translate = useTranslate(); - return ( - - - {translate('ra.navigation.no_results')} - - - ); -}); diff --git a/packages/ra-ui-materialui/src/list/pagination/index.ts b/packages/ra-ui-materialui/src/list/pagination/index.ts index 6680e52590a..fe096e58938 100644 --- a/packages/ra-ui-materialui/src/list/pagination/index.ts +++ b/packages/ra-ui-materialui/src/list/pagination/index.ts @@ -1,4 +1,3 @@ export * from './InfinitePagination'; export * from './Pagination'; export * from './PaginationActions'; -export * from './PaginationLimit'; From c5c9c0b86984b068d800690d7d1911209b8f86d6 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Mon, 29 Apr 2024 11:28:12 +0200 Subject: [PATCH 21/22] Revert "remove depreacted `rowStyle` prop from ``" This reverts commit 8649d33640b01b67318d597975038453dd6f571d. --- docs/SimpleList.md | 21 +++++++++++++++++++ docs/Upgrade.md | 4 ---- .../src/list/SimpleList/SimpleList.tsx | 13 +++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/docs/SimpleList.md b/docs/SimpleList.md index fabf1f5fe11..2bf275370cf 100644 --- a/docs/SimpleList.md +++ b/docs/SimpleList.md @@ -49,6 +49,7 @@ export const PostList = () => ( | `leftIcon` | Optional | function | | A function returning an `` component to display before the primary text. | | `rightAvatar` | Optional | function | | A function returning an `` component to display after the primary text. | | `rightIcon` | Optional | function | | A function returning an `` component to display after the primary text. | +| `rowStyle` | Optional | function | | A function returning a style object to apply to each row. | | `rowSx` | Optional | function | | A function returning a sx object to apply to each row. | | `empty` | Optional | ReactElement | | A ReactElement to display instead of the list when the data is empty. | @@ -189,6 +190,26 @@ This prop should be a function returning an `` component. When present, This prop should be a function returning an `` component. When present, the `` renders a `` after the ``. +## `rowStyle` + +*Deprecated - use [`rowSx`](#rowsx) instead.* + +This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a style object. The style object is applied to the `` styles prop. + +```jsx +import { List, SimpleList } from 'react-admin'; + +const postRowStyle = (record, index) => ({ + backgroundColor: record.nb_views >= 500 ? '#efe' : 'white', +}); + +export const PostList = () => ( + + record.title} rowStyle={postRowStyle} /> + +); +``` + ## `rowSx` This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a Material UI [`sx`](https://mui.com/system/getting-started/the-sx-prop/). The style object is applied to the `` `sx` prop. diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 7af934786d6..44b135c0eee 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -980,10 +980,6 @@ The deprecated `formClassName` prop of `CommonInputProps` type has been removed `InjectedFieldProps` interface has been removed. Use `FieldProps` instead. -## `` Is No Longer Supported - -The deprecated `rowStyle` prop from `` is no longer supported. Use [`rowSx`](./SimpleList.md#rowsx) instead. - ## `` Is No Longer Supported The deprecated `` prop was removed. Use the `ThemesContext.Provider` instead: diff --git a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx index dc34cfd79f6..822a4bcac7e 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx @@ -47,6 +47,7 @@ import { ListNoResults } from '../ListNoResults'; * - rightAvatar: same * - rightIcon: same * - linkType: 'edit' or 'show', or a function returning 'edit' or 'show' based on the record + * - rowStyle: function returning a style object based on (record, index) * - rowSx: function returning a sx object based on (record, index) * * @example // Display all posts as a List @@ -82,6 +83,7 @@ export const SimpleList = ( secondaryText, tertiaryText, rowSx, + rowStyle, ...rest } = props; const { data, isPending, total } = useListContextWithProps( @@ -135,6 +137,11 @@ export const SimpleList = ( resource={resource} id={record.id} record={record} + style={ + rowStyle + ? rowStyle(record, rowIndex) + : undefined + } sx={rowSx?.(record, rowIndex)} > {leftIcon && ( @@ -254,6 +261,7 @@ SimpleList.propTypes = { PropTypes.element, PropTypes.string, ]), + rowStyle: PropTypes.func, rowSx: PropTypes.func, }; @@ -276,7 +284,10 @@ export interface SimpleListProps secondaryText?: FunctionToElement | ReactElement | string; tertiaryText?: FunctionToElement | ReactElement | string; rowSx?: (record: RecordType, index: number) => SxProps; - + /** + * @deprecated Use rowSx instead + */ + rowStyle?: (record: RecordType, index: number) => any; // can be injected when using the component without context resource?: string; data?: RecordType[]; From 57cd6e13e4265ea2e6158117e2378a5693e1b689 Mon Sep 17 00:00:00 2001 From: adrien guernier Date: Mon, 29 Apr 2024 11:29:19 +0200 Subject: [PATCH 22/22] `` is no longer deprecated --- packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx index 822a4bcac7e..53d49e721f0 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx @@ -284,9 +284,6 @@ export interface SimpleListProps secondaryText?: FunctionToElement | ReactElement | string; tertiaryText?: FunctionToElement | ReactElement | string; rowSx?: (record: RecordType, index: number) => SxProps; - /** - * @deprecated Use rowSx instead - */ rowStyle?: (record: RecordType, index: number) => any; // can be injected when using the component without context resource?: string;