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

Optimistic mode #5799

Merged
merged 14 commits into from
Jan 30, 2021
Merged

Optimistic mode #5799

merged 14 commits into from
Jan 30, 2021

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jan 19, 2021

Problem

The undoable mode is optimistic AND undoable. React-admin offers no way to use the dataProvider in an optimistic and non-unduable way.

Solution

Replace the 'undoable' boolean option in useDataProvider by a fetch mode the can be one of 'regular', 'optimistic', and 'undoable'. Implement that fetch mode in useDataProvider.

Closes #5133, supersedes #5258

Example usage

const [updateMany, { loading }] = useUpdateMany(
        resource,
        selectedIds,
        { views: 0 },
        {
            action: CRUD_UPDATE_MANY,
            onSuccess: () => {
                notify('ra.notification.updated', 'info', {
                    smart_count: selectedIds.length,
                }); // note that the notification isn't undoable
                unselectAll(resource);
            },
            onFailure: error =>
                notify(
                    typeof error === 'string'
                        ? error
                        : error.message || 'ra.notification.http_error',
                    'warning'
                ),
            mode: 'optimistic', // <= that's what's new
        }
    );

Tasks

  • Proof of concept
  • Improve naming
  • Add documentation
  • Add unit tests

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good!

examples/simple/src/posts/ResetViewsButton.js Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useDataProvider.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useDataProvider.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useDataProvider.ts Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/detail/EditView.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way better!

@fzaninotto fzaninotto added RFR Ready For Review and removed WIP Work In Progress labels Jan 29, 2021
@fzaninotto
Copy link
Member Author

Switching to RFR

@fzaninotto fzaninotto changed the title [WIP] Optimistic mode Optimistic mode Jan 29, 2021
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome :)

docs/Actions.md Outdated Show resolved Hide resolved
docs/Actions.md Outdated Show resolved Hide resolved
docs/Actions.md Outdated Show resolved Hide resolved
docs/Actions.md Outdated Show resolved Hide resolved
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
@fzaninotto fzaninotto merged commit ff51006 into next Jan 30, 2021
@fzaninotto fzaninotto deleted the optimistic-mode branch January 30, 2021 07:17
@fzaninotto fzaninotto added this to the 3.12 milestone Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants