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

Rename appLayout prop to layout in <Admin> component #3055

Merged
merged 4 commits into from
May 19, 2019
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
8 changes: 4 additions & 4 deletions docs/Admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Here are all the props accepted by the component:
- [`catchAll`](#catchall)
- [`menu`](#menu)
- [`theme`](#theme)
- [`appLayout`](#applayout)
- [`layout`](#layout)
- [`customReducers`](#customreducers)
- [`customSagas`](#customsagas)
- [`customRoutes`](#customroutes)
Expand Down Expand Up @@ -153,7 +153,7 @@ const App = () => (

## `menu`

**Tip**: This prop is deprecated. To override the menu component, use a [custom layout](#applayout) instead.
**Tip**: This prop is deprecated. To override the menu component, use a [custom layout](#layout) instead.

React-admin uses the list of `<Resource>` components passed as children of `<Admin>` to build a menu to each resource with a `list` component.

Expand Down Expand Up @@ -243,7 +243,7 @@ const App = () => (

For more details on predefined themes and custom themes, refer to the [Material UI Customization documentation](https://material-ui.com/customization/themes/).

## `appLayout`
## `layout`

If you want to deeply customize the app header, the menu, or the notifications, the best way is to provide a custom layout component. It must contain a `{children}` placeholder, where react-admin will render the resources. If you use material UI fields and inputs, it should contain a `<ThemeProvider>` element. And finally, if you want to show the spinner in the app header when the app fetches data in the background, the Layout should connect to the redux store.

Expand All @@ -254,7 +254,7 @@ Use the [default layout](https://github.com/marmelab/react-admin/blob/master/pac
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down
20 changes: 10 additions & 10 deletions docs/Theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ const App = () => (

## Using a Custom Layout

Instead of the default layout, you can use your own component as the admin layout. Just use the `appLayout` prop of the `<Admin>` component:
Instead of the default layout, you can use your own component as the admin layout. Just use the `layout` prop of the `<Admin>` component:

```jsx
// in src/App.js
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down Expand Up @@ -606,14 +606,14 @@ const MyLayout = (props) => <Layout {...props} appBar={MyAppBar} />;
export default MyLayout;
```

Then, use this layout in the `<Admin>` with the `appLayout` prop:
Then, use this layout in the `<Admin>` with the `layout` prop:

```jsx
// in src/App.js
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down Expand Up @@ -710,14 +710,14 @@ const MyLayout = (props) => <Layout {...props} menu={MyMenu} />;
export default MyLayout;
```

Then, use this layout in the `<Admin>` `appLayout` prop:
Then, use this layout in the `<Admin>` `layout` prop:

```jsx
// in src/App.js
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down Expand Up @@ -808,14 +808,14 @@ const MyLayout = (props) => <Layout {...props} notification={MyNotification} />;
export default MyLayout;
```

Then, use this layout in the `<Admin>` `applayout` prop:
Then, use this layout in the `<Admin>` `layout` prop:

```jsx
// in src/App.js
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down Expand Up @@ -875,14 +875,14 @@ const MyLayout = (props) => <Layout {...props} error={MyError} />;
export default MyLayout;
```

Then, use this layout in the `<Admin>` `applayout` prop:
Then, use this layout in the `<Admin>` `layout` prop:

```jsx
// in src/App.js
import MyLayout from './MyLayout';

const App = () => (
<Admin appLayout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin layout={MyLayout} dataProvider={simpleRestProvider('http://path.to.my.api')}>
// ...
</Admin>
);
Expand Down
4 changes: 2 additions & 2 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
</a>
<ul class="articles" {% if page.path !='Admin.md' %}style="display:none" {% endif %}>
<li class="chapter">
<a href="#applayout">
<code>appLayout</code>
<a href="#layout">
<code>layout</code>
</a>
</li>
<li class="chapter">
Expand Down
14 changes: 11 additions & 3 deletions packages/ra-core/src/CoreAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export type ChildrenFunction = () => ComponentType[];
const DefaultLayout: SFC<LayoutProps> = ({ children }) => <>{children}</>;

export interface AdminProps {
appLayout: LayoutComponent;
layout: LayoutComponent;
appLayout?: LayoutComponent;
authProvider?: AuthProvider;
children?: AdminChildren;
catchAll: CatchAllComponent;
Expand Down Expand Up @@ -61,7 +62,8 @@ class CoreAdminBase extends Component<AdminProps> {

static defaultProps: Partial<AdminProps> = {
catchAll: () => null,
appLayout: DefaultLayout,
layout: DefaultLayout,
appLayout: undefined,
loading: () => null,
loginPage: false,
};
Expand Down Expand Up @@ -90,6 +92,7 @@ React-admin requires a valid dataProvider function to work.`);

renderCore() {
const {
layout,
appLayout,
authProvider,
children,
Expand All @@ -106,6 +109,11 @@ React-admin requires a valid dataProvider function to work.`);

const logout = authProvider ? createElement(logoutButton) : null;

if (appLayout) {
console.warn(
'You are using deprecated prop "appLayout", it was replaced by "layout", see https://github.com/marmelab/react-admin/issues/2918'
);
}
if (loginPage === true && process.env.NODE_ENV !== 'production') {
console.warn(
'You passed true to the loginPage prop. You must either pass false to disable it or a component class to customize it'
Expand Down Expand Up @@ -133,7 +141,7 @@ React-admin requires a valid dataProvider function to work.`);
path="/"
render={props => (
<CoreAdminRouter
appLayout={appLayout}
layout={appLayout || layout}
catchAll={catchAll}
customRoutes={customRoutes}
dashboard={dashboard}
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-core/src/CoreAdminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const welcomeStyles: CSSProperties = {
};

export interface AdminRouterProps extends LayoutProps {
appLayout: LayoutComponent;
layout: LayoutComponent;
catchAll: CatchAllComponent;
children?: AdminChildren;
customRoutes?: CustomRoutes;
Expand Down Expand Up @@ -139,7 +139,7 @@ export class CoreAdminRouter extends Component<

render() {
const {
appLayout,
layout,
catchAll,
children,
customRoutes,
Expand Down Expand Up @@ -208,7 +208,7 @@ export class CoreAdminRouter extends Component<
path="/"
render={() =>
createElement(
appLayout,
layout,
{
dashboard,
logout,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-admin/src/Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
const Admin = CoreAdmin;

Admin.defaultProps = {
appLayout: DefaultLayout,
layout: DefaultLayout,
catchAll: NotFound,
loading: Loading,
loginPage: Login,
Expand Down