forked from api-platform/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.js
49 lines (44 loc) · 1.15 KB
/
List.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Api from '@api-platform/api-doc-parser/lib/Api';
import Resource from '@api-platform/api-doc-parser/lib/Resource';
import {
Datagrid,
EditButton,
List as BaseList,
ShowButton,
TextField,
} from 'admin-on-rest';
import PropTypes from 'prop-types';
import React from 'react';
const List = props => {
const {hasEdit, hasShow, options: {api, fieldFactory, resource}} = props;
return (
<BaseList {...props}>
<Datagrid>
<TextField source="id" />
{resource.readableFields.map(field =>
fieldFactory(field, {
action: 'list',
api,
resource,
}),
)}
{hasShow && <ShowButton />}
{hasEdit && <EditButton />}
</Datagrid>
</BaseList>
);
};
List.defaultProps = {
perPage: 30, // Default value in API Platform
};
List.propTypes = {
options: PropTypes.shape({
api: PropTypes.instanceOf(Api).isRequired,
fieldFactory: PropTypes.func.isRequired,
resource: PropTypes.instanceOf(Resource).isRequired,
}),
perPage: PropTypes.number,
hasEdit: PropTypes.bool.isRequired,
hasShow: PropTypes.bool.isRequired,
};
export default List;