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 Loading route missing theme with LoadingPage #5560

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions packages/ra-core/src/core/CoreAdminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CustomRoutes,
CatchAllComponent,
LayoutComponent,
LoadingComponent,
CoreLayoutProps,
ResourceProps,
RenderResourcesFunction,
Expand All @@ -28,7 +29,7 @@ export interface AdminRouterProps extends CoreLayoutProps {
catchAll: CatchAllComponent;
children?: AdminChildren;
customRoutes?: CustomRoutes;
loading: ComponentType;
loading: LoadingComponent;
ready?: ComponentType;
}

Expand Down Expand Up @@ -101,7 +102,7 @@ const CoreAdminRouter: FunctionComponent<AdminRouterProps> = props => {
children,
customRoutes,
dashboard,
loading,
loading: LoadingPage,
logout,
menu,
ready,
Expand All @@ -121,7 +122,13 @@ const CoreAdminRouter: FunctionComponent<AdminRouterProps> = props => {
(!computedChildren || computedChildren.length === 0)
) {
if (oneSecondHasPassed) {
return <Route path="/" key="loading" component={loading} />;
return (
<Route
path="/"
key="loading"
render={() => <LoadingPage theme={theme} />}
/>
);
} else {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-core/src/core/CoreAdminUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CatchAllComponent,
CustomRoutes,
DashboardComponent,
LoadingComponent,
} from '../types';

export type ChildrenFunction = () => ComponentType[];
Expand All @@ -27,7 +28,7 @@ export interface AdminUIProps {
customRoutes?: CustomRoutes;
dashboard?: DashboardComponent;
layout?: LayoutComponent;
loading?: ComponentType;
loading?: LoadingComponent;
loginPage?: LoginComponent | boolean;
logout?: ComponentType;
menu?: ComponentType;
Expand Down
5 changes: 5 additions & 0 deletions packages/ra-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ export interface CoreLayoutProps {
}

export type LayoutComponent = ComponentType<CoreLayoutProps>;
export type LoadingComponent = ComponentType<{
theme?: ThemeOptions;
loadingPrimary?: string;
loadingSecondary?: string;
}>;

export interface ResourceComponentInjectedProps {
basePath?: string;
Expand Down
27 changes: 27 additions & 0 deletions packages/ra-ui-materialui/src/layout/LoadingPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { ThemeProvider } from '@material-ui/styles';
import { createMuiTheme } from '@material-ui/core/styles';
import Loading from './Loading';

const LoadingPage = ({ theme, ...props }) => (
<ThemeProvider theme={theme}>
<Loading {...props} />
</ThemeProvider>
);

LoadingPage.propTypes = {
theme: PropTypes.object,
classes: PropTypes.object,
className: PropTypes.string,
loadingPrimary: PropTypes.string,
loadingSecondary: PropTypes.string,
};

LoadingPage.defaultProps = {
theme: createMuiTheme({}),
loadingPrimary: 'ra.page.loading',
loadingSecondary: 'ra.message.loading',
};

export default LoadingPage;
2 changes: 2 additions & 0 deletions packages/ra-ui-materialui/src/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Error, { ErrorProps } from './Error';
import HideOnScroll, { HideOnScrollProps } from './HideOnScroll';
import Layout, { LayoutProps } from './Layout';
import Loading from './Loading';
import LoadingPage from './LoadingPage';
import LinearProgress from './LinearProgress';
import LoadingIndicator from './LoadingIndicator';
import Menu, { MenuProps } from './Menu';
Expand All @@ -32,6 +33,7 @@ export {
HideOnScroll,
Layout,
Loading,
LoadingPage,
LinearProgress,
LoadingIndicator,
Menu,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-admin/src/AdminRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import { FC } from 'react';
import { CoreAdminRouter, AdminRouterProps } from 'ra-core';
import { Loading } from 'ra-ui-materialui';
import { LoadingPage } from 'ra-ui-materialui';

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

AdminRouter.defaultProps = {
loading: Loading,
loading: LoadingPage,
};

export default AdminRouter;
4 changes: 2 additions & 2 deletions packages/react-admin/src/AdminUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC } from 'react';
import { CoreAdminUI, AdminUIProps } from 'ra-core';
import {
Layout as DefaultLayout,
Loading,
LoadingPage,
Login,
Logout,
NotFound,
Expand All @@ -14,7 +14,7 @@ const AdminUI: FC<AdminUIProps> = props => <CoreAdminUI {...props} />;
AdminUI.defaultProps = {
layout: DefaultLayout,
catchAll: NotFound,
loading: Loading,
loading: LoadingPage,
loginPage: Login,
logout: Logout,
};
Expand Down