From 9c85b1e22922fce37dbd35fa7348ae7a95199ce2 Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 7 Nov 2022 05:38:31 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B9=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Well/Telemetry/TelemetryView/index.jsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pages/Well/Telemetry/TelemetryView/index.jsx b/src/pages/Well/Telemetry/TelemetryView/index.jsx index 35efc86..fd17199 100644 --- a/src/pages/Well/Telemetry/TelemetryView/index.jsx +++ b/src/pages/Well/Telemetry/TelemetryView/index.jsx @@ -140,6 +140,7 @@ export const normalizeData = (data) => data?.map(item => ({ const dateSorter = makeDateSorter('date') const TelemetryView = memo(() => { + const [currentWellId, setCurrentWellId] = useState(null) const [dataSaub, setDataSaub] = useState([]) const [dataSpin, setDataSpin] = useState([]) const [chartInterval, setChartInterval] = useState(defaultPeriod) @@ -155,11 +156,11 @@ const TelemetryView = memo(() => { const saubSubject$ = useMemo(() => new BehaviorSubject(), []) const spinSubject$ = useMemo(() => new BehaviorSubject(), []) - const handleDataSaub = useCallback((data) => { + const handleDataSaub = useCallback((data, replace = false) => { if (data) { const dataSaub = normalizeData(data) setDataSaub((prev) => { - const out = [...prev, ...dataSaub] + const out = replace ? [...dataSaub] : [...prev, ...dataSaub] out.sort(dateSorter) return out }) @@ -185,24 +186,23 @@ const TelemetryView = memo(() => { }, [spinSubject$]) useEffect(() => { - const cancel = invokeWebApiWrapperAsync( - async (signal) => { - if (signal.aborted) return false + if (currentWellId == well.id) return + setCurrentWellId(well.id) + invokeWebApiWrapperAsync( + async () => { const flowChart = await DrillFlowChartService.getByIdWell(well.id) const dataSaub = await TelemetryDataSaubService.getData(well.id, null, chartInterval) const dataSpin = await TelemetryDataSpinService.getData(well.id, null, chartInterval) if (signal.aborted) return false setFlowChartData(flowChart ?? []) - handleDataSaub(dataSaub) - handleDataSpin(dataSpin) + handleDataSaub(dataSaub, true) + setDataSpin(Array.isArray(dataSpin) ? dataSpin : []) }, setIsDataLoading, `Не удалось получить данные`, { actionName: 'Получение данных по скважине', well } ) - - return () => cancel() - }, [well, chartInterval, handleDataSpin, handleDataSaub]) + }, [well, chartInterval, currentWellId, handleDataSaub]) useEffect(() => { const unsubscribe = Subscribe( From f82b80d0d0dbbd93a3c3cfc31356f9cdd12622ea Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 7 Nov 2022 06:33:14 +0500 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=20=D0=BE=D1=87=D0=B8=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Well/Telemetry/TelemetryView/index.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/Well/Telemetry/TelemetryView/index.jsx b/src/pages/Well/Telemetry/TelemetryView/index.jsx index fd17199..4193658 100644 --- a/src/pages/Well/Telemetry/TelemetryView/index.jsx +++ b/src/pages/Well/Telemetry/TelemetryView/index.jsx @@ -157,14 +157,14 @@ const TelemetryView = memo(() => { const spinSubject$ = useMemo(() => new BehaviorSubject(), []) const handleDataSaub = useCallback((data, replace = false) => { - if (data) { + setDataSaub((prev) => { + if (!data) + return replace ? [] : prev const dataSaub = normalizeData(data) - setDataSaub((prev) => { - const out = replace ? [...dataSaub] : [...prev, ...dataSaub] - out.sort(dateSorter) - return out - }) - } + const out = replace ? [...dataSaub] : [...prev, ...dataSaub] + out.sort(dateSorter) + return out + }) }, []) const handleDataSpin = useCallback((data) => data && setDataSpin((prev) => [...prev, ...data]), [])