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 () => {