asb_cloud_front/src/components/AnalysisOperationTime.jsx

41 lines
1.5 KiB
React
Raw Normal View History

import moment from 'moment'
import { DatePicker } from 'antd'
2021-07-21 15:36:08 +05:00
import { useState, useEffect } from 'react'
import { useParams } from 'react-router-dom'
import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory'
import { TelemetryAnalyticsService } from '@api'
2021-07-21 15:36:08 +05:00
import { ChartOperationTime } from './charts/ChartOperationTime'
const { RangePicker } = DatePicker
const lines = [{ labelAccessorName: 'processName', pieceAccessorName: 'duration' }]
2021-07-21 15:36:08 +05:00
export const AnalysisOperationTime = () => {
const { id } = useParams()
2021-07-21 15:36:08 +05:00
const [operationTimeData, setOperationTimeData] = useState([])
const [loader, setLoader] = useState(false)
const [range, setRange] = useState([moment().subtract(1,'days'), moment()])
2021-07-21 15:36:08 +05:00
useEffect(() => invokeWebApiWrapperAsync(
async () => {
const begin = range?.length > 1 ? range[0].toISOString() : null
const end = range?.length > 1 ? range[1].toISOString() : null
const summary = await TelemetryAnalyticsService.getOperationsSummary(id, begin, end)
setOperationTimeData(summary)
},
setLoader,
`Не удалось получить данные для Анализа Операция-Время по скважине '${id}' за период с ${begin} по ${end}`
), [id, range])
2021-07-21 15:36:08 +05:00
return (
<LoaderPortal show={loader}>
<RangePicker showTime onChange={(range) => setRange(range)} />
<ChartOperationTime data={operationTimeData} lines={lines} />
</LoaderPortal>
2021-07-21 15:36:08 +05:00
)
}
export default AnalysisOperationTime