Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you disable the React-Admin Undo feature in config?

Tags:

react-admin

The Undo feature is a great, but it can cause inefficiencies during development cycles.

Is there an easy way for us to disable it in our staging environment, or at least lower the timeout?

like image 476
Anthony Main Avatar asked Feb 25 '19 11:02

Anthony Main


4 Answers

The Edit and Create components support the undoable parameter. So you could do like this <Edit {...props} undoable={false} > to disable the undo function for a specific Form

like image 132
user1169629 Avatar answered Nov 20 '22 19:11

user1169629


When I unterstand the documentation and src correctly, you have to override the notification component in order to change the autoHideDuration. This is the time the notification is visible to the user and after the delay, the request is send to the api.

When you set it to 0 the requests should be send nearly immediately.
From the documentation - Theming - Notifications:

You can override the notification component, for instance to change the notification duration. It defaults to 4000, i.e. 4 seconds, and you can override it using the autoHideDuration prop. For instance, to create a custom Notification component with a 5 seconds default:

// in src/MyNotification.js
import { Notification } from 'react-admin';

const MyNotification = props => <Notification {...props}autoHideDuration={5000} />;

export default MyNotification;
like image 1
And-y Avatar answered Nov 20 '22 19:11

And-y


undoable can only be set on Edit component and not on the Create component.

Handle the formProps coming from the Create page by adding a custom variable to check if the props are indeed from the 'Create' page or from the server.

To customize notification for Create or Edit page you can pass the successMessage prop to the components

successMessage="Item created successfully" //or use translate

More about 'successMessage' can be found here - React Documentation

like image 1
Ananth George Avatar answered Nov 20 '22 19:11

Ananth George


With react-admin v.4 the way to disable Undo feature so changes are immediately saved is to add mutationMode="optimistic" to Edit/Create component.

To change the success notification message use mutationOptions={{ onSuccess }} together with notify hook

    import { useNotify, useRefresh, useRedirect, Edit } from 'react-admin';

    const notify = useNotify();
    const refresh = useRefresh();
    const redirect = useRedirect();

    const onSuccess = () => {
        notify(`Changes saved`);
        redirect('/your-collection');
        refresh();
    };

    return (
        <Edit mutationMode="optimistic" mutationOptions={{ onSuccess }}>
        ...
like image 1
Wojciechu Avatar answered Nov 20 '22 21:11

Wojciechu