diff --git a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx index 8fa5d6c858..0edd661ba3 100644 --- a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx +++ b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx @@ -10,6 +10,7 @@ import { FetchMock } from 'jest-fetch-mock/types'; describe('ScrapePoolList', () => { const defaultProps = { pathPrefix: '..', + onLoadingChange: jest.fn(), }; beforeEach(() => { diff --git a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx index 65eeb8ceb1..95e1c497f1 100644 --- a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx +++ b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx @@ -111,10 +111,18 @@ ScrapePoolListContent.displayName = 'ScrapePoolListContent'; const ScrapePoolListWithStatusIndicator = withStatusIndicator(ScrapePoolListContent); -const ScrapePoolList: FC = ({ pathPrefix }) => { +const ScrapePoolList: FC void }> = ({ + pathPrefix, + onLoadingChange, +}) => { const { response, error, isLoading } = useFetch(`${pathPrefix}/api/v1/targets?state=active`); const { status: responseStatus } = response; const badResponse = responseStatus !== 'success' && responseStatus !== 'start fetching'; + + useEffect(() => { + onLoadingChange(isLoading); // Inform Targets.tsx about the loading state + }, [isLoading, onLoadingChange]); + return ( = ({ pathPrefix }) => { - const scrapePoolListProps = { pathPrefix }; + const [isLoading, setIsLoading] = useState(false); + + const handleLoadingChange = (loadingState: boolean) => { + setIsLoading(loadingState); + }; return ( <> -

Targets

- + {isLoading ? ( + + Sometimes the targets page doesn't fully load because it takes too long to load targets from leaf nodes. Please + wait some time or try again later. + + ) : ( + <> +

Targets

+ + + )} ); };