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 params in <Resource /> name #4

Open
1 task done
kopax opened this issue Mar 19, 2019 · 0 comments
Open
1 task done

Support params in <Resource /> name #4

kopax opened this issue Mar 19, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@kopax
Copy link
Contributor

kopax commented Mar 19, 2019

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

@kopax kopax added the enhancement New feature or request label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant