asb_cloud_front/src/pages/Measure/View.jsx

61 lines
1.5 KiB
React
Raw Normal View History

import React from 'react'
import { Empty, Form } from 'antd'
import { Grid, GridItem } from '../../components/Grid'
2021-10-06 13:57:04 +05:00
import '../../styles/index.css'
const colsCount = 3
2021-10-06 13:57:04 +05:00
const headerCellStyle = {
border:'1px solid lightgrey'
2021-10-06 13:57:04 +05:00
}
2021-09-03 09:26:43 +05:00
const valueCellStyle = {
border:'1px solid lightgrey',
justifyContent:'right',
marginRight:'16px',
fontWeight:'bold',
textAlign:'right',
padding: 0
}
export const View = React.memo(({columns, item}) => {
2021-09-03 09:26:43 +05:00
if (!item || !columns?.length)
return <Empty key='empty' image={Empty.PRESENTED_IMAGE_SIMPLE}/>
2021-09-03 09:26:43 +05:00
return (
<Grid>
{columns.map((column, i) => (
<>
<GridItem
key={column.dataIndex}
row={Math.floor(i / colsCount) + 1}
col={(i % colsCount) * 2 + 1}
style={headerCellStyle}
>
{column.title}
</GridItem>
<GridItem
key={column.title}
row={Math.floor(i / colsCount) + 1}
col={(i % colsCount) * 2 + 2}
style={valueCellStyle}
>
{column.render ? (
<Form.Item
key={column.dataIndex}
name={column.dataIndex}
style={{ margin: 0 }}
//rules={column.formItemRules}
>
{column.render(item[column.dataIndex])}
</Form.Item>
) : (
<p key={column.title} className='m-5px'>{item[column.dataIndex]}</p>
)}
</GridItem>
</>
))}
</Grid>
)
})