import { useEffect , useState } from 'react' ; import Ctx from 'teleport/teleportContext' ; import useAttempt from 'shared/hooks/useAttemptNext' ; import * as Features from 'teleport/features' ; export default function useClusters ( ctx ) { const [ clusters , setClusters ] = useState ( [ ] ) ; const { attempt , run } = useAttempt ( ) ; function init ( ) { run ( ( ) => ctx . clusterService . fetchClusters ( ) . then ( setClusters ) ) ; } const [ enabledFeatures ] = useState ( ( ) => buildACL ( ctx ) ) ; useEffect ( ( ) => { init ( ) ; } , [ ] ) ; return { init , initAttempt : attempt , clusters , enabledFeatures , } ; } function buildACL ( ctx ) { const apps = ctx . features . some ( f => f instanceof Features . FeatureApps ) ; const nodes = ctx . features . some ( f => f instanceof Features . FeatureNodes ) ; const audit = ctx . features . some ( f => f instanceof Features . FeatureAudit ) ; const kubes = ctx . features . some ( f => f instanceof Features . FeatureKubes ) ; const databases = ctx . features . some ( f => f instanceof Features . FeatureDatabases ) ; const recordings = ctx . features . some ( f => f instanceof Features . FeatureRecordings ) ; const desktops = ctx . features . some ( f => f instanceof Features . FeatureDesktops ) ; return { nodes , audit , recordings , apps , kubes , databases , desktops , } ; }