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

Support data providers in custom components #3357

Open
Janpot opened this issue Apr 4, 2024 · 0 comments
Open

Support data providers in custom components #3357

Janpot opened this issue Apr 4, 2024 · 0 comments
Labels
feature: Custom components Everything related to the code editor experience, codesandbox like waiting for 👍 Waiting for upvotes

Comments

@Janpot
Copy link
Member

Janpot commented Apr 4, 2024

Summary

Custom component authors should get access to data provider data to build their own data rich components. They should also be able to call the CRUD methods on these data providers. Concretely, Toolpad should offer an API that allows:

  • custom component authors to mark a property of their component as having the type "data provider". This should enable the same user interface on the property that exists for the data grid.

  • call a one of a specific set of hooks with the value of this property that allows interaction with the user provided data provider.
    tentative API shape:

    type DataProvider = Opaque // opaque value, obtained from the custom component property.
    
    interface GetManyOptions {
      filterModel: { /* ... */ },
      pagination: { /* ... */ }
    }
    
    interface GetManyHook {
      data: any[],
      error: Error | null,
      loading: boolean
    }
    
    interface DeleteOneHook {
      execute: (id: Id) => Promise<void>
      error: Error | null
      loading: boolean
    }
    
    interface createOneHook {
      execute: (values: R) => Promise<R>
      error: Error | null
      loading: boolean
    }
    
    interface UpdateOneHook {
      execute: (id: Id, values: Partial<R>) => Promise<R>
      error: Error | null
      loading: boolean
    }
    
    function useDataProviderGetMany(dataProvider: DataProvider, options: GetManyOptions): GetManyHook;
    
    function useDataProviderDeleteOne(dataProvider: DataProvider): DeleteOneHook;
    
    function useDataProviderCreateOne(dataProvider: DataProvider): createOneHook;
    
    function useDataProviderUpdateOne(dataProvider: DataProvider): UpdateOneHook;

    Alternatively, Toolpad could take the property name as a string in its first argument to the hooks.

Examples

No response

Motivation

#351 (comment)

Search keywords: data provider custom components

@Janpot Janpot added waiting for 👍 Waiting for upvotes feature: Custom components Everything related to the code editor experience, codesandbox like labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: Custom components Everything related to the code editor experience, codesandbox like waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

1 participant