asb_cloud_front/src/pages/Wells.jsx

65 lines
1.5 KiB
React
Raw Normal View History

import { useState, useEffect } from 'react'
2021-04-08 12:29:19 +05:00
import { WellService } from '../services/api'
2021-06-01 15:28:05 +05:00
import LoaderPortal from '../components/LoaderPortal'
import { Table } from 'antd' // TreeSelect
2021-04-02 17:22:34 +05:00
import { useHistory } from 'react-router-dom'
2021-05-31 15:21:37 +05:00
import notify from '../components/notify'
2021-04-02 17:22:34 +05:00
const columns = [
{
title: 'Месторождение',
dataIndex: 'deposit',
key: 'deposit',
},
{
title: 'Куст',
dataIndex: 'cluster',
key: 'cluster',
},
{
title: 'Скважина',
dataIndex: 'caption',
key: 'caption',
},
{
title: 'Данные',
dataIndex: 'lastData',
key: 'lastData',
},
];
export default function Wells(props){
const [wells, setWells] = useState([])
const [loader, setLoader] = useState(false)
const history = useHistory()
const updateWellsList = async () => {
2021-04-02 17:22:34 +05:00
setLoader(true)
try{
let newWells = (await WellService.getWells()).map(w =>{return {key:w.id, ...w}})
2021-06-01 14:26:15 +05:00
console.log(newWells)
2021-04-09 17:59:35 +05:00
setWells( newWells )
2021-04-02 17:22:34 +05:00
}
catch(e){
2021-05-31 15:21:37 +05:00
notify('Не удалось загрузить список скважин', 'error')
2021-06-01 14:26:15 +05:00
console.error(`${e}`);
2021-04-02 17:22:34 +05:00
}
setLoader(false)
2021-04-02 17:22:34 +05:00
}
2021-06-01 14:26:15 +05:00
useEffect(()=>updateWellsList(), [])
2021-04-02 17:22:34 +05:00
return(<>
<h2>Скважины</h2>
2021-06-01 15:28:05 +05:00
<LoaderPortal show={loader}>
<Table
2021-04-02 17:22:34 +05:00
dataSource={wells}
columns={columns}
2021-04-16 15:49:35 +05:00
onRow={(record) => {
2021-04-02 17:22:34 +05:00
return {
onClick: event => {history.push(`/well/${record.id}/`)},
2021-04-02 17:22:34 +05:00
};
}}/>
2021-06-01 15:28:05 +05:00
</LoaderPortal>
2021-04-02 17:22:34 +05:00
</>)
}