Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding error box when target not loaded #7034

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FetchMock } from 'jest-fetch-mock/types';
describe('ScrapePoolList', () => {
const defaultProps = {
pathPrefix: '..',
onLoadingChange: jest.fn(),
};

beforeEach(() => {
Expand Down
10 changes: 9 additions & 1 deletion pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ ScrapePoolListContent.displayName = 'ScrapePoolListContent';

const ScrapePoolListWithStatusIndicator = withStatusIndicator(ScrapePoolListContent);

const ScrapePoolList: FC<PathPrefixProps> = ({ pathPrefix }) => {
const ScrapePoolList: FC<PathPrefixProps & { onLoadingChange: (loadingState: boolean) => void }> = ({
pathPrefix,
onLoadingChange,
}) => {
const { response, error, isLoading } = useFetch<ScrapePoolListProps>(`${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 (
<ScrapePoolListWithStatusIndicator
{...response.data}
Expand Down
22 changes: 18 additions & 4 deletions pkg/ui/react-app/src/pages/targets/Targets.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import { RouteComponentProps } from '@reach/router';
import Filter from './Filter';
import ScrapePoolList from './ScrapePoolList';
import PathPrefixProps from '../../types/PathPrefixProps';
import { useLocalStorage } from '../../hooks/useLocalStorage';
import { UncontrolledAlert } from 'reactstrap';

const Targets: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix }) => {
const scrapePoolListProps = { pathPrefix };
const [isLoading, setIsLoading] = useState(false);

const handleLoadingChange = (loadingState: boolean) => {
setIsLoading(loadingState);
};

return (
<>
<h2>Targets</h2>
<ScrapePoolList {...scrapePoolListProps} />
{isLoading ? (
<UncontrolledAlert color="danger">
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.
</UncontrolledAlert>
) : (
<>
<h2>Targets</h2>
<ScrapePoolList pathPrefix={pathPrefix} onLoadingChange={handleLoadingChange} />
</>
)}
</>
);
};
Expand Down
Loading