Убран сброс пути при выборе месторождения/куста/скважины

This commit is contained in:
goodmice 2022-10-06 15:14:44 +05:00
parent 836bcd583d
commit 61d71899db
No known key found for this signature in database
GPG Key ID: 63EA771203189CF1

View File

@ -99,6 +99,8 @@ export const WellTreeSelector = memo<WellTreeSelectorProps>(({ show, expand, cur
const navigate = useNavigate() const navigate = useNavigate()
const location = useLocation() const location = useLocation()
console.log(location.pathname)
useEffect(() => { useEffect(() => {
if (current) setSelected([current]) if (current) setSelected([current])
}, [current]) }, [current])
@ -156,7 +158,17 @@ export const WellTreeSelector = memo<WellTreeSelectorProps>(({ show, expand, cur
}, [wellsTree]) }, [wellsTree])
const onSelect = useCallback((value: Key[]): void => { const onSelect = useCallback((value: Key[]): void => {
navigate(String(value), { state: { from: location.pathname }}) const newRoot = /\/(\w+)\/(\d+)/.exec(String(value))
const oldRoot = /\/(\w+)\/(\d+)/.exec(location.pathname)
if (!newRoot || !oldRoot) return
let newPath = newRoot[0]
if (oldRoot[1] === newRoot[1]) { /// Если типы страниц одинаковые (deposit, cluster, well)
const url = location.pathname.substring(oldRoot[0].length)
newPath = newPath + url
}
navigate(newPath, { state: { from: location.pathname }})
}, [navigate, location]) }, [navigate, location])
useEffect(() => onChange(location.pathname), [onChange, location]) useEffect(() => onChange(location.pathname), [onChange, location])