2021-08-28 22:32:13 +05:00
|
|
|
import { useState, useEffect } from 'react'
|
2021-08-30 16:40:56 +05:00
|
|
|
import { Table, Button, Modal } from 'antd'
|
|
|
|
import { HourglassOutlined } from '@ant-design/icons'
|
2021-08-28 22:32:13 +05:00
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
|
|
|
import { MeasureService } from '../../services/api'
|
2021-08-30 16:40:56 +05:00
|
|
|
import { Editor } from './Editor'
|
2021-08-28 22:32:13 +05:00
|
|
|
|
|
|
|
export const MeasureTable = ({idWell, idCategory, title, columns}) => {
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-08-30 16:40:56 +05:00
|
|
|
const [showEditor, setShowEditor] = useState(false)
|
|
|
|
const [lastData, setLastData] = useState({})
|
2021-08-28 22:32:13 +05:00
|
|
|
|
2021-08-30 16:40:56 +05:00
|
|
|
const update = ()=>invokeWebApiWrapperAsync(async()=>{
|
2021-08-28 22:32:13 +05:00
|
|
|
const data = await MeasureService.getLast(idWell, idCategory)
|
|
|
|
setLastData(data)
|
|
|
|
}
|
|
|
|
, setShowLoader
|
|
|
|
, "не удалось загрузить")
|
2021-08-30 16:40:56 +05:00
|
|
|
|
|
|
|
useEffect(update, [idWell, idCategory])
|
|
|
|
|
|
|
|
const timestamp = lastData ? new Date(lastData?.timestamp).toLocaleString() : '-'
|
2021-08-28 22:32:13 +05:00
|
|
|
|
|
|
|
return <LoaderPortal show={showLoader}>
|
|
|
|
<h3>{title}</h3>
|
2021-08-30 16:40:56 +05:00
|
|
|
<span>Дата: {timestamp}</span>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
onClick={() => setShowEditor(true)}
|
|
|
|
icon={<HourglassOutlined/>}>История</Button>
|
2021-08-28 22:32:13 +05:00
|
|
|
<Table
|
2021-08-30 16:40:56 +05:00
|
|
|
style={{marginTop:16}}
|
|
|
|
bordered
|
2021-08-28 22:32:13 +05:00
|
|
|
dataSource = {[lastData?.data]}
|
|
|
|
columns = {columns}
|
2021-08-30 16:40:56 +05:00
|
|
|
scroll={{ x: 400, y: 600 }}/>
|
|
|
|
<Modal
|
|
|
|
title={title}
|
|
|
|
centered
|
|
|
|
visible={showEditor}
|
|
|
|
onOk={() => setShowEditor(false)}
|
|
|
|
onCancel={() => setShowEditor(false)}
|
|
|
|
width="95%"
|
|
|
|
footer={null}
|
|
|
|
>
|
|
|
|
<Editor
|
|
|
|
idWell={idWell}
|
|
|
|
idCategory={idCategory}
|
|
|
|
columns = {columns}
|
|
|
|
onUpdate={update}/>
|
|
|
|
</Modal>
|
2021-08-28 22:32:13 +05:00
|
|
|
</LoaderPortal>
|
|
|
|
}
|