import { useCallback } from 'react' ; import { useService } from '@cloudbeaver/core-di' ; import { NavigationTreeService } from '../NavigationTree/NavigationTreeService' ; import { ROOT_NODE_PATH } from './NodesManager/NavNodeInfoResource' ; import { NavTreeResource } from './NodesManager/NavTreeResource' ; interface Hook { children : string [ ] | undefined ; exception : Error | null ; isLoaded : ( ) => boolean ; isLoading : ( ) => boolean ; isOutdated : ( ) => boolean ; } export function useChildren ( navNodeId = ROOT_NODE_PATH ) { const navTreeService = useService ( NavigationTreeService ) ; const navTreeResource = useService ( NavTreeResource ) ; const children = navTreeService . getChildren ( navNodeId ) ; const exception = navTreeResource . getException ( navNodeId ) ; const deps = [ navNodeId ] ; const isLoading = useCallback ( ( ) => navTreeResource . isDataLoading ( navNodeId ) , deps ) ; const isLoaded = useCallback ( ( ) => navTreeResource . isLoaded ( navNodeId ) , deps ) ; const isOutdated = useCallback ( ( ) => navTreeResource . isOutdated ( navNodeId ) , deps ) ; return { children , exception , isLoaded , isLoading , isOutdated , } ; }