Skip to content

Support params in <Resource /> name #4

@kopax

Description

@kopax

Supports of params in <Resource /> name

We keep struggling creating customized list views.

Because <List /> is tightly coupled with the URL, it makes it complicated to use it in customRoutes.

What we want is to fetch and display a list of records with the react-admin UI.

We have tried to use <Resource /> to create more than one list view (It seems from marmelab/react-admin#2903 (comment) that people can build most of the UI with the current react-admin without hassle).

I want a way to pass filter to the list within any <Resource />, for instance:

export default function ProjectServiceNewslettersList(props) {
  return (
    <List
      {...props}
      filter={{ project_id: match.params.id }} // <~~~ This will come from the URL using withRouter
      sort={{ field: 'id', order: 'DESC' }}
      filters={<ProjectServiceNewslettersListFilter />}
    >
      <Datagrid striped hover>
        <TextField source="name" />
        <ShowButton size="sm" />
      </Datagrid>
    </List>
  );
}

Issue Type

Reproduction

I have declared the resource as follow:

  <Resource
    name="projects/:projectId/services/:serviceId/newsletters/groups"
    list={ProjectServiceNewslettersList}
  />

Result

Params are not replaced in CRUD requests.

{"timestamp":"2019-03-18 20:00:48","status":404,"error":"Not Found","message":"No message available","path":"/projects/:projectId/services/:serviceId/newsletters/groups"}

Expected

We expect to query the backend with the replaced params of the url we are on when querying the list.

I assert this is not currently possible because <Resource />.

This would have helped us to set filter on <List /> using params from the URL and create more than one list per entities.

Description

This feature would permit:

<Resource name="users/:userId/choses/:choseId" /> 

without having REST request using the wrong url.

That can be done using a custom <Resource />:

  1. read match.params and interpolate if this is not already done yet.
  2. during resources registration within redux, we need to see how we could store those resources. => *for examples, in pages, when we have param path, we replace : with $, we could pick the same strategy for redux-store.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions