From a000f5df45de09d6b28fa5eed09272e49d6beb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 7 Mar 2024 10:27:18 +0100 Subject: [PATCH] chore: simplify migration (#537) * chore: simplify migration * tests: update snapshots --- src/AdminGuesser.tsx | 76 ++++++++------------ src/__snapshots__/AdminGuesser.test.tsx.snap | 10 +-- src/layout/AppBar.tsx | 8 +-- 3 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/AdminGuesser.tsx b/src/AdminGuesser.tsx index c92ca6c0..5c335fc9 100644 --- a/src/AdminGuesser.tsx +++ b/src/AdminGuesser.tsx @@ -1,15 +1,12 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import PropTypes from 'prop-types'; import { - Admin, + AdminContext, + AdminUI, ComponentPropType, - I18nContextProvider, Loading, - ThemeProvider, - ThemesContext, defaultI18nProvider, } from 'react-admin'; -import { createHashHistory, createMemoryHistory } from 'history'; import { ErrorBoundary } from 'react-error-boundary'; import type { FallbackProps } from 'react-error-boundary'; import type { ComponentType, ErrorInfo } from 'react'; @@ -23,6 +20,7 @@ import { Error as DefaultError, Layout, LoginPage, + darkTheme, lightTheme, } from './layout/index.js'; import getRoutesAndResourcesFromNodes, { @@ -68,7 +66,7 @@ const getOverrideCode = (resources: Resource[]) => { export const AdminResourcesGuesser = ({ // Admin props loadingPage: LoadingPage = Loading, - admin: AdminEl = Admin, + admin: AdminEl = AdminUI, // Props children, includeDeprecated, @@ -116,7 +114,7 @@ const AdminGuesser = ({ includeDeprecated = false, // Admin props dataProvider, - history, + i18nProvider, layout = Layout, loginPage = LoginPage, loading: loadingPage, @@ -129,14 +127,6 @@ const AdminGuesser = ({ const [loading, setLoading] = useState(true); const [, setError] = useState(); const [introspect, setIntrospect] = useState(true); - let adminHistory = history; - - if (!adminHistory) { - adminHistory = - typeof window === 'undefined' - ? createMemoryHistory() - : createHashHistory(); - } useEffect(() => { if (typeof dataProvider.introspect !== 'function') { @@ -175,23 +165,29 @@ const AdminGuesser = ({ ); return ( - - - - {children} - - - + + + + + {children} + + + + ); }; @@ -231,19 +227,9 @@ const AdminGuesserWithError = ({ ); return ( - - - - - - - - - + + + ); }; diff --git a/src/__snapshots__/AdminGuesser.test.tsx.snap b/src/__snapshots__/AdminGuesser.test.tsx.snap index 073fa111..85acc1f7 100644 --- a/src/__snapshots__/AdminGuesser.test.tsx.snap +++ b/src/__snapshots__/AdminGuesser.test.tsx.snap @@ -3,7 +3,7 @@ exports[` renders loading 1`] = ``; exports[` renders with custom resources 1`] = ` - renders with custom resources 1`] = ` - + `; exports[` renders without custom resources 1`] = ` - renders without custom resources 1`] = ` - + `; exports[` renders without data 1`] = ` - { /> - ); };