Skip to content

Commit f5e0f15

Browse files
authoredNov 19, 2020
Merge pull request #5560 from thcolin/fix/login-page-theme
Fix Loading route missing theme with LoadingPage
2 parents 24ba591 + f1f6c9e commit f5e0f15

File tree

7 files changed

+50
-8
lines changed

7 files changed

+50
-8
lines changed
 

‎packages/ra-core/src/core/CoreAdminRouter.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
CustomRoutes,
1818
CatchAllComponent,
1919
LayoutComponent,
20+
LoadingComponent,
2021
CoreLayoutProps,
2122
ResourceProps,
2223
RenderResourcesFunction,
@@ -28,7 +29,7 @@ export interface AdminRouterProps extends CoreLayoutProps {
2829
catchAll: CatchAllComponent;
2930
children?: AdminChildren;
3031
customRoutes?: CustomRoutes;
31-
loading: ComponentType;
32+
loading: LoadingComponent;
3233
ready?: ComponentType;
3334
}
3435

@@ -101,7 +102,7 @@ const CoreAdminRouter: FunctionComponent<AdminRouterProps> = props => {
101102
children,
102103
customRoutes,
103104
dashboard,
104-
loading,
105+
loading: LoadingPage,
105106
logout,
106107
menu,
107108
ready,
@@ -121,7 +122,13 @@ const CoreAdminRouter: FunctionComponent<AdminRouterProps> = props => {
121122
(!computedChildren || computedChildren.length === 0)
122123
) {
123124
if (oneSecondHasPassed) {
124-
return <Route path="/" key="loading" component={loading} />;
125+
return (
126+
<Route
127+
path="/"
128+
key="loading"
129+
render={() => <LoadingPage theme={theme} />}
130+
/>
131+
);
125132
} else {
126133
return null;
127134
}

‎packages/ra-core/src/core/CoreAdminUI.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CatchAllComponent,
1414
CustomRoutes,
1515
DashboardComponent,
16+
LoadingComponent,
1617
} from '../types';
1718

1819
export type ChildrenFunction = () => ComponentType[];
@@ -27,7 +28,7 @@ export interface AdminUIProps {
2728
customRoutes?: CustomRoutes;
2829
dashboard?: DashboardComponent;
2930
layout?: LayoutComponent;
30-
loading?: ComponentType;
31+
loading?: LoadingComponent;
3132
loginPage?: LoginComponent | boolean;
3233
logout?: ComponentType;
3334
menu?: ComponentType;

‎packages/ra-core/src/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ export interface CoreLayoutProps {
409409
}
410410

411411
export type LayoutComponent = ComponentType<CoreLayoutProps>;
412+
export type LoadingComponent = ComponentType<{
413+
theme?: ThemeOptions;
414+
loadingPrimary?: string;
415+
loadingSecondary?: string;
416+
}>;
412417

413418
export interface ResourceComponentInjectedProps {
414419
basePath?: string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { ThemeProvider } from '@material-ui/styles';
4+
import { createMuiTheme } from '@material-ui/core/styles';
5+
import Loading from './Loading';
6+
7+
const LoadingPage = ({ theme, ...props }) => (
8+
<ThemeProvider theme={theme}>
9+
<Loading {...props} />
10+
</ThemeProvider>
11+
);
12+
13+
LoadingPage.propTypes = {
14+
theme: PropTypes.object,
15+
classes: PropTypes.object,
16+
className: PropTypes.string,
17+
loadingPrimary: PropTypes.string,
18+
loadingSecondary: PropTypes.string,
19+
};
20+
21+
LoadingPage.defaultProps = {
22+
theme: createMuiTheme({}),
23+
loadingPrimary: 'ra.page.loading',
24+
loadingSecondary: 'ra.message.loading',
25+
};
26+
27+
export default LoadingPage;

‎packages/ra-ui-materialui/src/layout/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Error, { ErrorProps } from './Error';
88
import HideOnScroll, { HideOnScrollProps } from './HideOnScroll';
99
import Layout, { LayoutProps } from './Layout';
1010
import Loading from './Loading';
11+
import LoadingPage from './LoadingPage';
1112
import LinearProgress from './LinearProgress';
1213
import LoadingIndicator from './LoadingIndicator';
1314
import Menu, { MenuProps } from './Menu';
@@ -32,6 +33,7 @@ export {
3233
HideOnScroll,
3334
Layout,
3435
Loading,
36+
LoadingPage,
3537
LinearProgress,
3638
LoadingIndicator,
3739
Menu,
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react';
22
import { FC } from 'react';
33
import { CoreAdminRouter, AdminRouterProps } from 'ra-core';
4-
import { Loading } from 'ra-ui-materialui';
4+
import { LoadingPage } from 'ra-ui-materialui';
55

66
const AdminRouter: FC<AdminRouterProps> = props => (
77
<CoreAdminRouter {...props} />
88
);
99

1010
AdminRouter.defaultProps = {
11-
loading: Loading,
11+
loading: LoadingPage,
1212
};
1313

1414
export default AdminRouter;

‎packages/react-admin/src/AdminUI.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FC } from 'react';
33
import { CoreAdminUI, AdminUIProps } from 'ra-core';
44
import {
55
Layout as DefaultLayout,
6-
Loading,
6+
LoadingPage,
77
Login,
88
Logout,
99
NotFound,
@@ -14,7 +14,7 @@ const AdminUI: FC<AdminUIProps> = props => <CoreAdminUI {...props} />;
1414
AdminUI.defaultProps = {
1515
layout: DefaultLayout,
1616
catchAll: NotFound,
17-
loading: Loading,
17+
loading: LoadingPage,
1818
loginPage: Login,
1919
logout: Logout,
2020
};

0 commit comments

Comments
 (0)
Please sign in to comment.