import { useState , useEffect } from 'react' ; import useAttempt from 'shared/hooks/useAttemptNext' ; import { Kube } from 'teleport/services/kube' ; import TeleportContext from 'teleport/teleportContext' ; import useStickyClusterId from 'teleport/useStickyClusterId' ; export default function useKubes ( ctx ) { const { clusterId , isLeafCluster } = useStickyClusterId ( ) ; const { username , authType } = ctx . storeUser . state ; const canCreate = ctx . storeUser . getTokenAccess ( ) . create ; const { run , attempt } = useAttempt ( 'processing' ) ; const [ kubes , setKubes ] = useState ( [ ] as Kube [ ] ) ; useEffect ( ( ) => { run ( ( ) => ctx . kubeService . fetchKubernetes ( clusterId ) . then ( setKubes ) ) ; } , [ clusterId ] ) ; return { kubes , attempt , username , authType , isLeafCluster , clusterId , canCreate , } ; } export type State = ReturnType < typeof useKubes > ;