forked from ddrilling/asb_cloud_front
Косметические изменения
This commit is contained in:
parent
8552a40506
commit
1b17ee2cfd
@ -3,23 +3,20 @@ import { DefaultValueType } from 'rc-tree-select/lib/interface'
|
|||||||
import { useState, useEffect, ReactNode } from 'react'
|
import { useState, useEffect, ReactNode } from 'react'
|
||||||
import { useHistory, useRouteMatch } from 'react-router-dom'
|
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 DepositIcon } from '../images/DepositIcon.svg'
|
||||||
import { ReactComponent as ClusterIcon } from '../images/ClusterIcon.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'
|
import '../styles/wellTreeSelect.css'
|
||||||
|
|
||||||
export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown'
|
export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown'
|
||||||
export const checkIsWellOnline = (lastTelemetryDate?: RawDate): boolean => {
|
export const checkIsWellOnline = (lastTelemetryDate: unknown): boolean =>
|
||||||
if (!lastTelemetryDate || isNaN(+new Date(lastTelemetryDate))) return false
|
isRawDate(lastTelemetryDate) && (Date.now() - +new Date(lastTelemetryDate) < 600_000)
|
||||||
return Date.now() - +new Date(lastTelemetryDate) < 600_000
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TreeNodeData = {
|
export type TreeNodeData = {
|
||||||
title?: string | null
|
title?: string | null
|
||||||
@ -29,22 +26,24 @@ export type TreeNodeData = {
|
|||||||
children?: TreeNodeData[]
|
children?: TreeNodeData[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const getLabel = (wellsTree: any[], value?: string): string | undefined => {
|
const getLabel = (wellsTree: TreeNodeData[], value?: string): string | undefined => {
|
||||||
if (!value) return value
|
if (!value) return value
|
||||||
const type = value.replaceAll('/', ' ').trim().split(' ')[0]
|
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) {
|
switch (type) {
|
||||||
case 'cluster':
|
case 'cluster':
|
||||||
deposit = wellsTree.find((deposit) => (
|
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)
|
if (deposit && cluster)
|
||||||
return `${deposit.title} / ${cluster.title}`
|
return `${deposit.title} / ${cluster.title}`
|
||||||
break
|
break
|
||||||
case 'well':
|
case 'well':
|
||||||
deposit = wellsTree.find((deposit) => (
|
deposit = wellsTree.find((deposit) => (
|
||||||
cluster = deposit.children?.find((cluster: any) => (
|
cluster = deposit.children?.find((cluster: TreeNodeData) => (
|
||||||
well = cluster.children?.find((well: any) => well.key === value)
|
well = cluster.children?.find((well: TreeNodeData) => well.key === value)
|
||||||
))
|
))
|
||||||
))
|
))
|
||||||
if (deposit && cluster && well)
|
if (deposit && cluster && well)
|
||||||
@ -56,12 +55,13 @@ const getLabel = (wellsTree: any[], value?: string): string | undefined => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const WellTreeSelector = () => {
|
export const WellTreeSelector = () => {
|
||||||
const [wellsTree, setWellsTree] = useState<any[]>([]) // TODO: Исправить тип (необходимо разобраться с типом значения rc-select)
|
const [wellsTree, setWellsTree] = useState<any[]>([]) // TODO: Исправить тип (необходимо разобраться с типом value rc-select)
|
||||||
const [showLoader, setShowLoader] = useState<boolean>(false)
|
const [showLoader, setShowLoader] = useState<boolean>(false)
|
||||||
const [value, setValue] = useState<string>()
|
const [value, setValue] = useState<string>()
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const routeMatch = useRouteMatch('/:route/:id')
|
const routeMatch = useRouteMatch('/:route/:id')
|
||||||
|
|
||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
invokeWebApiWrapperAsync(
|
invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user