forked from ddrilling/asb_cloud_front
WellTreeSelector доработан для работы с нецифровыми значениями в местах смены переменных
This commit is contained in:
parent
dc0f80fee5
commit
ebe3a50fbe
@ -12,12 +12,19 @@ import { ReactComponent as ClusterIcon } from '@images/ClusterIcon.svg'
|
||||
|
||||
import '@styles/wellTreeSelect.css'
|
||||
|
||||
/**
|
||||
* Для поиска в URL текущего раздела по шаблону `/{type}/{id}`
|
||||
*
|
||||
* Если найдено совпадение может вернуть 1 или 2 группы соответственно
|
||||
*/
|
||||
const URL_REGEX = /^\/([^\/?#]+)(?:\/([^\/?#]+))?/
|
||||
|
||||
export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown'
|
||||
export const checkIsWellOnline = (lastTelemetryDate: unknown): boolean =>
|
||||
isRawDate(lastTelemetryDate) && (Date.now() - +new Date(lastTelemetryDate) < 600_000)
|
||||
|
||||
const getKeyByUrl = (url?: string): [Key | null, string | null] => {
|
||||
const result = url?.match(/^\/([^\/]+)\/([^\/?]+)/) // pattern "/:type/:id"
|
||||
const result = url?.match(URL_REGEX) // pattern "/:type/:id"
|
||||
if (!result) return [null, null]
|
||||
return [result[0], result[1]]
|
||||
}
|
||||
@ -137,8 +144,8 @@ export const WellTreeSelector = memo<WellTreeSelectorProps>(({ expand, current,
|
||||
}, [wellsTree])
|
||||
|
||||
const onSelect = useCallback((value: Key[]): void => {
|
||||
const newRoot = /\/(\w+)\/\d+/.exec(String(value))
|
||||
const oldRoot = /\/(\w+)(?:\/\d+)?/.exec(location.pathname)
|
||||
const newRoot = URL_REGEX.exec(String(value))
|
||||
const oldRoot = URL_REGEX.exec(location.pathname)
|
||||
if (!newRoot || !oldRoot) return
|
||||
|
||||
let newPath = newRoot[0]
|
||||
|
Loading…
Reference in New Issue
Block a user