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

Fix default theme and store #575

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
18 changes: 12 additions & 6 deletions src/core/AdminGuesser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useEffect, useMemo, useState } from 'react';
import { AdminContext, defaultI18nProvider } from 'react-admin';
import {
AdminContext,
defaultI18nProvider,
/* tree-shaking no-side-effects-when-called */ localStorageStore,
} from 'react-admin';

import type { ComponentType } from 'react';
import type { AdminProps } from 'react-admin';
Expand All @@ -12,8 +16,8 @@ import {
Error as DefaultError,
Layout,
LoginPage,
darkTheme,
lightTheme,
darkTheme as defaultDarkTheme,
lightTheme as defaultLightTheme,
} from '../layout/index.js';
import type { ApiPlatformAdminDataProvider, SchemaAnalyzer } from '../types.js';

Expand All @@ -24,6 +28,8 @@ export interface AdminGuesserProps extends AdminProps {
includeDeprecated?: boolean;
}

const defaultStore = localStorageStore();

const AdminGuesser = ({
// Props for SchemaAnalyzerContext
schemaAnalyzer,
Expand All @@ -33,7 +39,7 @@ const AdminGuesser = ({
basename,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error = DefaultError as any,
store,
store = defaultStore,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React-admin defines the default store in react-adminù 's Admincomponent. SinceAdminGuesserrelies on the lower-levelAdminContext`, we have to repeat the same initialization.

dataProvider,
i18nProvider = defaultI18nProvider,
authProvider,
Expand All @@ -42,7 +48,8 @@ const AdminGuesser = ({
layout = Layout,
loginPage = LoginPage,
loading: loadingPage,
theme = lightTheme,
theme = defaultLightTheme,
darkTheme = defaultDarkTheme,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug here - the dark theme couldn't be overridden

// Other props
children,
...rest
Expand Down Expand Up @@ -98,7 +105,6 @@ const AdminGuesser = ({
queryClient={queryClient}
theme={theme}
darkTheme={darkTheme}
lightTheme={lightTheme}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lightTheme isn't documented in react-admin - theme is the prop to use.

https://marmelab.com/react-admin/Admin.html#theme

defaultTheme={defaultTheme}>
<IntrospectionContext.Provider value={introspectionContext}>
<SchemaAnalyzerContext.Provider value={schemaAnalyzer}>
Expand Down
3 changes: 3 additions & 0 deletions src/layout/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const darkTheme: RaThemeOptions = {
},
},
},
MuiFilledInput: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom darkTheme here extends react-admin's defaultTheme, which is in fact the defaultLightTheme and contains light-theme specific changes for inputs that should not apply to dark theme.

styleOverrides: undefined,
},
},
};

Expand Down