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

[RFR] Add Crud hooks #3253

Merged
merged 18 commits into from
May 22, 2019
Merged

[RFR] Add Crud hooks #3253

merged 18 commits into from
May 22, 2019

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented May 20, 2019

Based on the exploration done in #3248

  • Change useQuery signature to accept a query and options
  • Change useMutation signature to accept a query and options
  • Add useQueryWithStore to extend useQuery with a cache
  • Add a reducer and a default selector to enable caching by default on useQueryWithStore (not in useMutation)
  • Update doc for useQuery and useMutation
  • Document caching abilities of useQueryWithStore
  • Add useGetOne hook based on useQueryWithStore
  • Add useGetList hook based on useQueryWithStore
  • Use useGetOne in ShowController and EditController
  • Use useGetList in ListController
    // in EditController
    const { data: record, loading } = useGetOne(resource, id, {
        basePath,
        version, // used to force reload
        onFailure: {
            notification: {
                body: 'ra.notification.item_doesnt_exist',
                level: 'warning',
            },
            redirectTo: 'list',
            refresh: true,
        },
    });

    // in ListController
    const { data, ids, total, loading, loaded } = useGetList(
        resource,
        {
            page: query.page,
            perPage: query.perPage,
        },
        { field: query.sort, order: query.order },
        { ...query.filter, ...filter },
        {
            version,
            onFailure: {
                notification: {
                    body: 'ra.notification.http_error',
                    level: 'warning',
                },
            },
        }
    );

@fzaninotto fzaninotto added this to the 3.0.0 milestone May 20, 2019
Copy link
Collaborator

@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.

I love it! It's so much clearer this way 👍

packages/ra-core/src/fetch/useMutation.ts Outdated Show resolved Hide resolved
@fzaninotto fzaninotto changed the title [WIP] Add Crud hooks [RFR] Add Crud hooks May 22, 2019
@fzaninotto
Copy link
Member Author

Switching to RFR

Copy link
Collaborator

@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!

@djhi djhi merged commit 078d026 into next May 22, 2019
@djhi djhi deleted the crud-hook branch May 22, 2019 09:41
@fzaninotto fzaninotto mentioned this pull request May 24, 2019
2 tasks
@fzaninotto fzaninotto mentioned this pull request Sep 13, 2019
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants