Исправлено наложение активных телеметрий

This commit is contained in:
goodmice 2022-11-07 07:12:44 +05:00
parent d7669a2317
commit a04090db57
No known key found for this signature in database
GPG Key ID: 63EA771203189CF1

View File

@ -140,6 +140,7 @@ export const normalizeData = (data) => data?.map(item => ({
const dateSorter = makeDateSorter('date') const dateSorter = makeDateSorter('date')
const TelemetryView = memo(() => { const TelemetryView = memo(() => {
const [currentWellId, setCurrentWellId] = useState(null)
const [dataSaub, setDataSaub] = useState([]) const [dataSaub, setDataSaub] = useState([])
const [dataSpin, setDataSpin] = useState([]) const [dataSpin, setDataSpin] = useState([])
const [chartInterval, setChartInterval] = useState(defaultPeriod) const [chartInterval, setChartInterval] = useState(defaultPeriod)
@ -155,15 +156,15 @@ const TelemetryView = memo(() => {
const saubSubject$ = useMemo(() => new BehaviorSubject(), []) const saubSubject$ = useMemo(() => new BehaviorSubject(), [])
const spinSubject$ = useMemo(() => new BehaviorSubject(), []) const spinSubject$ = useMemo(() => new BehaviorSubject(), [])
const handleDataSaub = useCallback((data) => { const handleDataSaub = useCallback((data, replace = false) => {
if (data) { setDataSaub((prev) => {
if (!data)
return replace ? [] : prev
const dataSaub = normalizeData(data) const dataSaub = normalizeData(data)
setDataSaub((prev) => { const out = replace ? [...dataSaub] : [...prev, ...dataSaub]
const out = [...prev, ...dataSaub] out.sort(dateSorter)
out.sort(dateSorter) return out
return out })
})
}
}, []) }, [])
const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), []) const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), [])
@ -185,24 +186,22 @@ const TelemetryView = memo(() => {
}, [spinSubject$]) }, [spinSubject$])
useEffect(() => { useEffect(() => {
const cancel = invokeWebApiWrapperAsync( if (currentWellId == well.id) return
async (signal) => { setCurrentWellId(well.id)
if (signal.aborted) return false invokeWebApiWrapperAsync(
async () => {
const flowChart = await DrillFlowChartService.getByIdWell(well.id) const flowChart = await DrillFlowChartService.getByIdWell(well.id)
const dataSaub = await TelemetryDataSaubService.getData(well.id, null, chartInterval) const dataSaub = await TelemetryDataSaubService.getData(well.id, null, chartInterval)
const dataSpin = await TelemetryDataSpinService.getData(well.id, null, chartInterval) const dataSpin = await TelemetryDataSpinService.getData(well.id, null, chartInterval)
if (signal.aborted) return false
setFlowChartData(flowChart ?? []) setFlowChartData(flowChart ?? [])
handleDataSaub(dataSaub) handleDataSaub(dataSaub, true)
handleDataSpin(dataSpin) setDataSpin(Array.isArray(dataSpin) ? dataSpin : [])
}, },
setIsDataLoading, setIsDataLoading,
`Не удалось получить данные`, `Не удалось получить данные`,
{ actionName: 'Получение данных по скважине', well } { actionName: 'Получение данных по скважине', well }
) )
}, [well, chartInterval, currentWellId, handleDataSaub])
return () => cancel()
}, [well, chartInterval, handleDataSpin, handleDataSaub])
useEffect(() => { useEffect(() => {
const unsubscribe = Subscribe( const unsubscribe = Subscribe(