Добавлена обработка в случае, когда не выбрано месторождение/куст/скважина

This commit is contained in:
Александр Сироткин 2022-12-06 00:51:41 +05:00
parent 17d7b7c41d
commit 1a737b6afe

View File

@ -23,26 +23,28 @@ export const getWellState = (idState?: number): WellIconState => idState === 1 ?
export const checkIsWellOnline = (lastTelemetryDate: unknown): boolean =>
isRawDate(lastTelemetryDate) && (Date.now() - +new Date(lastTelemetryDate) < 600_000)
const getKeyByUrl = (url?: string): [Key | null, string | null] => {
const getKeyByUrl = (url?: string): [Key | null, string | null, number | null] => {
const result = url?.match(URL_REGEX) // pattern "/:type/:id"
if (!result) return [null, null]
return [result[0], result[1]]
if (!result) return [null, null, null]
return [result[0], result[1], result[2] && result[2] !== 'null' ? Number(result[2]) : null]
}
const getLabel = (wellsTree: TreeDataNode[], value?: string): string | undefined => {
const [url, type] = getKeyByUrl(value)
const [url, type, key] = getKeyByUrl(value)
if (!url) return
let deposit: TreeDataNode | undefined
let cluster: TreeDataNode | undefined
let well: TreeDataNode | undefined
switch (type) {
case 'deposit':
if (key === null) return 'Месторождение не выбрано'
deposit = wellsTree.find((deposit) => deposit.key === url)
if (deposit)
return `${deposit.title}`
return 'Ошибка! Месторождение не найдено!'
case 'cluster':
if (key === null) return 'Куст не выбран'
deposit = wellsTree.find((deposit) => (
cluster = deposit.children?.find((cluster: TreeDataNode) => cluster.key === url)
))
@ -51,6 +53,7 @@ const getLabel = (wellsTree: TreeDataNode[], value?: string): string | undefined
return 'Ошибка! Куст не найден!'
case 'well':
if (key === null) return 'Скважина не выбрана'
deposit = wellsTree.find((deposit) => (
cluster = deposit.children?.find((cluster: TreeDataNode) => (
well = cluster.children?.find((well: TreeDataNode) => well.key === url)