diff --git a/pkg/api/api.go b/pkg/api/api.go index d9dc5f4700..240907e575 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -252,8 +252,9 @@ func Respond(w http.ResponseWriter, data interface{}, warnings []error) { w.WriteHeader(http.StatusOK) resp := &response{ - Status: StatusSuccess, - Data: data, + Status: StatusSuccess, + Warnings: warningsToString(warnings), + Data: data, } for _, warn := range warnings { resp.Warnings = append(resp.Warnings, warn.Error()) @@ -287,3 +288,15 @@ func RespondError(w http.ResponseWriter, apiErr *ApiError, data interface{}) { Data: data, }) } + +func warningsToString(errors []error) []string { + warningStrings := make([]string, len(errors)) + + for i, err := range errors { + if err != nil { + warningStrings[i] = err.Error() + } + } + + return warningStrings +} diff --git a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx index 9378f36d93..e8d015d1f0 100644 --- a/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx +++ b/pkg/ui/react-app/src/pages/targets/ScrapePoolList.tsx @@ -8,7 +8,7 @@ import { useLocalStorage } from '../../hooks/useLocalStorage'; import { ToggleMoreLess } from '../../components/ToggleMoreLess'; import { KVSearch } from '@nexucis/kvsearch'; import styles from './ScrapePoolPanel.module.css'; -import { Col, Collapse, Row } from 'reactstrap'; +import { Col, Collapse, Row, UncontrolledAlert } from 'reactstrap'; import SearchBar from '../../components/SearchBar'; import { ScrapePoolContent } from './ScrapePoolContent'; @@ -111,27 +111,27 @@ ScrapePoolListContent.displayName = 'ScrapePoolListContent'; const ScrapePoolListWithStatusIndicator = withStatusIndicator(ScrapePoolListContent); -const ScrapePoolList: FC void }> = ({ - pathPrefix, - setWarnings, -}) => { +const ScrapePoolList: FC = ({ pathPrefix }) => { const { response, error, isLoading } = useFetch(`${pathPrefix}/api/v1/targets?state=active`); const { status: responseStatus, warnings: responseWarnings } = response; const badResponse = responseStatus !== 'success' && responseStatus !== 'start fetching'; - useEffect(() => { - if (responseWarnings?.length > 0) { - setWarnings(responseWarnings); - } - }, [responseWarnings, setWarnings]); - return ( - + <> +
+ {responseWarnings?.map((warning, index) => ( + + {warning} + + ))} +
+ + ); }; diff --git a/pkg/ui/react-app/src/pages/targets/Targets.tsx b/pkg/ui/react-app/src/pages/targets/Targets.tsx index 38d0b3acfa..33cda0adc2 100644 --- a/pkg/ui/react-app/src/pages/targets/Targets.tsx +++ b/pkg/ui/react-app/src/pages/targets/Targets.tsx @@ -1,28 +1,15 @@ -import React, { FC, useState } from 'react'; +import React, { FC } 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 = ({ pathPrefix }) => { - const [warnings, setWarnings] = useState([]); return ( <> - { - <> -
- {warnings.map((warning, index) => ( - - {warning} - - ))} -
-

Targets

- - - } +

Targets

+ ); };