From 1b17ee2cfd820164effdfbe6f849b4adf4095816 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Mon, 27 Dec 2021 15:58:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=81=D0=BC=D0=B5=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/WellTreeSelector.tsx | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/components/WellTreeSelector.tsx b/src/components/WellTreeSelector.tsx index f322472..c741b21 100644 --- a/src/components/WellTreeSelector.tsx +++ b/src/components/WellTreeSelector.tsx @@ -3,23 +3,20 @@ import { DefaultValueType } from 'rc-tree-select/lib/interface' import { useState, useEffect, ReactNode } from 'react' import { useHistory, useRouteMatch } from 'react-router-dom' -import { DepositService } from '../services/api' +import { isRawDate } from '../utils' +import LoaderPortal from './LoaderPortal' +import { WellIcon, WellIconState } from './icons' +import { invokeWebApiWrapperAsync } from './factory' +import { DepositService, DepositDto } from '../services/api' + import { ReactComponent as DepositIcon } from '../images/DepositIcon.svg' import { ReactComponent as ClusterIcon } from '../images/ClusterIcon.svg' -import { DepositDto } from '../services/api' -import { RawDate } from '../utils' - -import LoaderPortal from './LoaderPortal' -import { invokeWebApiWrapperAsync } from './factory' -import { WellIcon, WellIconState } from './icons' import '../styles/wellTreeSelect.css' export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown' -export const checkIsWellOnline = (lastTelemetryDate?: RawDate): boolean => { - if (!lastTelemetryDate || isNaN(+new Date(lastTelemetryDate))) return false - return Date.now() - +new Date(lastTelemetryDate) < 600_000 -} +export const checkIsWellOnline = (lastTelemetryDate: unknown): boolean => + isRawDate(lastTelemetryDate) && (Date.now() - +new Date(lastTelemetryDate) < 600_000) export type TreeNodeData = { title?: string | null @@ -29,22 +26,24 @@ export type TreeNodeData = { children?: TreeNodeData[] } -const getLabel = (wellsTree: any[], value?: string): string | undefined => { +const getLabel = (wellsTree: TreeNodeData[], value?: string): string | undefined => { if (!value) return value const type = value.replaceAll('/', ' ').trim().split(' ')[0] - let deposit: any, cluster: any, well: any + let deposit: TreeNodeData | undefined + let cluster: TreeNodeData | undefined + let well: TreeNodeData | undefined switch (type) { case 'cluster': deposit = wellsTree.find((deposit) => ( - cluster = deposit.children?.find((cluster: any) => cluster.key === value) + cluster = deposit.children?.find((cluster: TreeNodeData) => cluster.key === value) )) if (deposit && cluster) return `${deposit.title} / ${cluster.title}` break case 'well': deposit = wellsTree.find((deposit) => ( - cluster = deposit.children?.find((cluster: any) => ( - well = cluster.children?.find((well: any) => well.key === value) + cluster = deposit.children?.find((cluster: TreeNodeData) => ( + well = cluster.children?.find((well: TreeNodeData) => well.key === value) )) )) if (deposit && cluster && well) @@ -56,12 +55,13 @@ const getLabel = (wellsTree: any[], value?: string): string | undefined => { } export const WellTreeSelector = () => { - const [wellsTree, setWellsTree] = useState([]) // TODO: Исправить тип (необходимо разобраться с типом значения rc-select) + const [wellsTree, setWellsTree] = useState([]) // TODO: Исправить тип (необходимо разобраться с типом value rc-select) const [showLoader, setShowLoader] = useState(false) const [value, setValue] = useState() const history = useHistory() const routeMatch = useRouteMatch('/:route/:id') + /* eslint-disable react-hooks/exhaustive-deps */ useEffect(() => { invokeWebApiWrapperAsync( async () => {