diff --git a/src/app/Topology/Shared/Entity/utils.tsx b/src/app/Topology/Shared/Entity/utils.tsx index 361d8d404..d4185c3ff 100644 --- a/src/app/Topology/Shared/Entity/utils.tsx +++ b/src/app/Topology/Shared/Entity/utils.tsx @@ -71,6 +71,7 @@ import { concatMap, defaultIfEmpty, forkJoin, + interval, map, merge, Observable, @@ -387,7 +388,7 @@ export const useResources = ( targetNode: TargetNode, resourceType: TargetOwnedResourceType | TargetRelatedResourceType ): { resources: R[]; error?: Error; loading?: boolean } => { - const { api, notificationChannel } = React.useContext(ServiceContext); + const { api, notificationChannel, settings } = React.useContext(ServiceContext); const addSubscription = useSubscriptions(); const [resources, setResources] = React.useState([]); @@ -402,7 +403,7 @@ export const useResources = ( targetSubject .pipe( switchMap((tn) => { - return getTargetOwnedResources(resourceType, tn, api).pipe( + const resourceObs = getTargetOwnedResources(resourceType, tn, api).pipe( map((rs: ResourceTypes[]) => ({ resources: rs, error: undefined, @@ -414,6 +415,13 @@ export const useResources = ( }) ) ); + if (!settings.autoRefreshEnabled()) { + return resourceObs; + } + return merge( + resourceObs, + interval(settings.autoRefreshPeriod() * settings.autoRefreshUnits()).pipe(concatMap(() => resourceObs)) + ); }) ) .subscribe(({ resources, error }) => { @@ -422,7 +430,7 @@ export const useResources = ( setResources(resources); }) ); - }, [addSubscription, setLoading, setError, setResources, api, targetSubject, resourceType]); + }, [addSubscription, setLoading, setError, setResources, api, settings, targetSubject, resourceType]); React.useEffect(() => { const patchEventConfig = [