Skip to content

Commit

Permalink
Revert changes related to Create, Edit and Show actions views
Browse files Browse the repository at this point in the history
  • Loading branch information
asvarcas committed Jun 7, 2021
1 parent 74a7e0e commit c859fc1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 85 deletions.
35 changes: 3 additions & 32 deletions docs/CreateEdit.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,47 +158,18 @@ const PostTitle = ({ record }) => {
### Actions
You can add extra actions to an `<Edit>` or `<Create>` by using the `actions` prop:
```jsx
import Button from '@material-ui/core/Button';
import { Edit, EditActions } from 'react-admin';

const PostEditActions = (props) => (
<EditActions {...props}>
{/* Add your custom actions */}
<Button
color="primary"
onClick={() => { alert('Your custom action'); }}
>
Custom Action
</Button>
</EditActions>
);

export const PostEdit = (props) => (
<Edit actions={<PostEditActions />} {...props}>
...
</Edit>
);
```
If you want to have control over default actions as well, you can replace the entire `actions` component by your own:
You can replace the list of default actions by your own element using the `actions` prop:
```jsx
import * as React from "react";
import Button from '@material-ui/core/Button';
import { Edit, TopToolbar, ShowButton } from 'react-admin';
import { TopToolbar, ShowButton } from 'react-admin';

const PostEditActions = ({ basePath, data, resource }) => (
<TopToolbar>
<ShowButton basePath={basePath} record={data} />
{/* Add your custom actions */}
<Button
color="primary"
onClick={() => { alert('Your custom action'); }}
>
Custom Action
</Button>
<Button color="primary" onClick={customAction}>Custom Action</Button>
</TopToolbar>
);

Expand Down
28 changes: 2 additions & 26 deletions docs/Show.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,11 @@ export const PostShow = (props) => (

### Actions

You can add extra actions to a `<Show>` by using the `actions` prop:
You can replace the list of default actions by your own component using the `actions` prop:

```jsx
import Button from '@material-ui/core/Button';
import { Show, ShowActions } from 'react-admin';

const PostShowActions = (props) => (
<ShowActions {...props}>
{/* Add your custom actions */}
<Button
color="primary"
onClick={() => { alert('Your custom action'); }}
>
Custom Action
</Button>
</ShowActions>
);

export const PostShow = (props) => (
<Show actions={<PostShowActions />} {...props}>
...
</Show>
);
```
If you want to have control over default actions as well, you can replace the entire `actions` component by your own:

```jsx
import Button from '@material-ui/core/Button';
import { Show, EditButton, TopToolbar } from 'react-admin';
import { EditButton, TopToolbar } from 'react-admin';

const PostShowActions = ({ basePath, data, resource }) => (
<TopToolbar>
Expand Down
10 changes: 1 addition & 9 deletions packages/ra-ui-materialui/src/detail/CreateActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import TopToolbar from '../layout/TopToolbar';
import { ListButton } from '../button';
import { useCreateContext, useResourceDefinition } from 'ra-core';
import { ReactNode } from 'react';

/**
* Action Toolbar for the Create view
Expand All @@ -31,17 +30,12 @@ import { ReactNode } from 'react';
* </Create>
* );
*/
export const CreateActions = ({
children,
className,
...rest
}: CreateActionsProps) => {
export const CreateActions = ({ className, ...rest }: CreateActionsProps) => {
const { basePath } = useCreateContext(rest);
const { hasList } = useResourceDefinition(rest);
return (
<TopToolbar className={className} {...sanitizeRestProps(rest)}>
{hasList && <ListButton basePath={basePath} />}
{children}
</TopToolbar>
);
};
Expand All @@ -55,7 +49,6 @@ const sanitizeRestProps = ({
}) => rest;

export interface CreateActionsProps {
children?: ReactNode;
basePath?: string;
className?: string;
hasCreate?: boolean;
Expand All @@ -67,7 +60,6 @@ export interface CreateActionsProps {

CreateActions.propTypes = {
basePath: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
hasCreate: PropTypes.bool,
hasEdit: PropTypes.bool,
Expand Down
10 changes: 1 addition & 9 deletions packages/ra-ui-materialui/src/detail/EditActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import { Record, useEditContext, useResourceDefinition } from 'ra-core';
import { ShowButton } from '../button';
import TopToolbar from '../layout/TopToolbar';
import { ReactNode } from 'react';

/**
* Action Toolbar for the Edit view
Expand All @@ -31,18 +30,13 @@ import { ReactNode } from 'react';
* </Edit>
* );
*/
export const EditActions = ({
children,
className,
...rest
}: EditActionsProps) => {
export const EditActions = ({ className, ...rest }: EditActionsProps) => {
const { basePath, record } = useEditContext(rest);
const { hasShow } = useResourceDefinition(rest);

return (
<TopToolbar className={className} {...sanitizeRestProps(rest)}>
{hasShow && <ShowButton basePath={basePath} record={record} />}
{children}
</TopToolbar>
);
};
Expand All @@ -58,7 +52,6 @@ const sanitizeRestProps = ({

export interface EditActionsProps {
basePath?: string;
children?: ReactNode;
className?: string;
data?: Record;
hasCreate?: boolean;
Expand All @@ -70,7 +63,6 @@ export interface EditActionsProps {

EditActions.propTypes = {
basePath: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
data: PropTypes.object,
hasCreate: PropTypes.bool,
Expand Down
10 changes: 1 addition & 9 deletions packages/ra-ui-materialui/src/detail/ShowActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Record, useResourceDefinition, useShowContext } from 'ra-core';

import { EditButton } from '../button';
import TopToolbar from '../layout/TopToolbar';
import { ReactNode } from 'react';

const sanitizeRestProps = ({
basePath,
Expand Down Expand Up @@ -40,24 +39,18 @@ const sanitizeRestProps = ({
* </Show>
* );
*/
export const ShowActions = ({
children,
className,
...rest
}: ShowActionsProps) => {
export const ShowActions = ({ className, ...rest }: ShowActionsProps) => {
const { basePath, record } = useShowContext(rest);
const { hasEdit } = useResourceDefinition(rest);
return (
<TopToolbar className={className} {...sanitizeRestProps(rest)}>
{hasEdit && <EditButton basePath={basePath} record={record} />}
{children}
</TopToolbar>
);
};

export interface ShowActionsProps {
basePath?: string;
children?: ReactNode;
className?: string;
data?: Record;
hasCreate?: boolean;
Expand All @@ -69,7 +62,6 @@ export interface ShowActionsProps {

ShowActions.propTypes = {
basePath: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
data: PropTypes.object,
hasCreate: PropTypes.bool,
Expand Down

0 comments on commit c859fc1

Please sign in to comment.