Skip to content

Commit 918416f

Browse files
committed
Have ListGuesser suggest how to handle the relationship between Users and Posts
1 parent 72823e6 commit 918416f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/App.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
// Adding custom styles with material-ui provided JSS
1+
// Have ListGuesser suggest how to handle the relationship between Users and Posts
22
// https://marmelab.com/react-admin/Tutorial.html
33

44
/*
55
6-
Guessed List from last commit (now used in this commit, and imported from ./users.js). Browser shows same list of users:
6+
Guessed List for posts from the posts API endpoint:
7+
8+
Guessed List:
9+
10+
export const PostList = props => (
11+
<List {...props}>
12+
<Datagrid rowClick="edit">
13+
<ReferenceField source="userId" reference="users"><TextField source="id" /></ReferenceField>
14+
<TextField source="id" />
15+
<TextField source="title" />
16+
<TextField source="body" />
17+
</Datagrid>
18+
</List>
19+
);
20+
21+
Guessed List for users from prior commit (now used in this commit, and imported from ./users.js). Browser shows same list of users:
722
823
export const UserList = props => (
924
<List {...props}>
@@ -17,20 +32,21 @@ export const UserList = props => (
1732
<TextField source="website" />
1833
<TextField source="company.name" />
1934
</Datagrid>
20-
</List> );
35+
</List>
2136
);
2237
2338
*/
2439

2540
import React from 'react';
26-
import { Admin, Resource } from 'react-admin';
41+
import { Admin, Resource, ListGuesser } from 'react-admin';
2742
import { UserList } from './users'
2843
import jsonServerProvider from 'ra-data-json-server';
2944

3045
const dataProvider = jsonServerProvider('http://jsonplaceholder.typicode.com');
3146

3247
const App = () => (
3348
<Admin dataProvider={dataProvider} >
49+
<Resource name="posts" list={ListGuesser} />
3450
<Resource name="users" list={UserList} />
3551
</Admin>
3652
)

0 commit comments

Comments
 (0)