asb_cloud_front/src/components/AnalysisDepthToInterval.jsx

59 lines
2.0 KiB
React
Raw Normal View History

import { useParams } from "react-router-dom"
import notify from "../components/notify"
import { useState, useEffect } from 'react'
import { AnalyticsService } from '../services/api'
import { ChartDepthToInterval } from './charts/ChartDepthToInterval'
import { Select } from 'antd'
import LoaderPortal from '../components/LoaderPortal'
const { Option } = Select
const timePeriodCollection = [
{ value: '60', label: '1 минута' },
{ value: '300', label: '5 минут' },
{ value: '600', label: '10 минут' },
{ value: '1800', label: '30 минут' },
{ value: '3600', label: '1 час' },
{ value: '21600', label: '6 часов' },
{ value: '43200', label: '12 часов' },
{ value: '86400', label: '24 часа' }
]
const lines = [{ label: 'График скорость проходки-интервал', yAccessorName: "intervalDepthProgress", xAccessorName: "intervalStartDate", color: '#00f' }]
export function AnalysisDepthToInterval() {
let { id } = useParams()
const [depthToIntervalData, setDepthToIntervalData] = useState([])
const [loader, setLoader] = useState(false)
const [chartInterval, setChartInterval] = useState(600)
const children = timePeriodCollection.map((line) => <Option key={line.value}>{line.label}</Option>)
const handleReceiveDepthToIntervalData = (data) => {
setDepthToIntervalData(data)
}
useEffect(() => {
setLoader(true)
AnalyticsService.getWellDepthToInterval(id, chartInterval)
.then(handleReceiveDepthToIntervalData)
.catch(error => {
2021-07-21 15:36:08 +05:00
notify(`Не удалось получить данные для Анализа скорость проходки-интервал "${id}"`,
'warning')
console.log(error)
})
.finally(setLoader(false))
}, [id, chartInterval])
return (
<LoaderPortal show={loader}>
<Select defaultValue="600" onChange={setChartInterval}>
{children}
</Select>
<ChartDepthToInterval
data={depthToIntervalData}
lines={lines}
/>
</LoaderPortal>
)
}