/
CompactShowLayout.jsx
60 lines (56 loc) · 1.54 KB
/
CompactShowLayout.jsx
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
50
51
52
53
54
55
56
57
58
59
60
import React, { Children } from 'react'
import PropTypes from 'prop-types'
import { CardContentInner } from 'react-admin'
import RaField from './RaField'
import { cloneRecursively, getComponentsNames, isLayoutComponent } from '../core'
const sanitizeRestProps = ({
children,
className,
record,
resource,
basePath,
version,
initialValues,
translate,
...rest
}) => rest
const CompactShowLayout = ({
layoutComponents,
basePath,
className,
children,
record,
resource,
version,
...rest
}) => {
const layoutComponentsNamesArr = getComponentsNames(layoutComponents)
return (
<CardContentInner className={className} key={version} {...sanitizeRestProps(rest)}>
{Children.map(children, (child) =>
cloneRecursively(
child,
(x) => isLayoutComponent(x, layoutComponentsNamesArr),
(x) => (
<RaField
field={x}
basePath={basePath}
record={record}
resource={resource}
/>
)
)
)}
</CardContentInner>
)
}
CompactShowLayout.propTypes = {
basePath: PropTypes.string,
record: PropTypes.object,
resource: PropTypes.string,
version: PropTypes.number,
children: PropTypes.node,
className: PropTypes.string,
layoutComponents: PropTypes.array,
}
export default CompactShowLayout