Don't display facts until facts are loaded

This commit is contained in:
Jake McDermott
2020-08-24 12:55:32 -04:00
parent 6ef27e5458
commit 0af9e01610

View File

@@ -11,32 +11,31 @@ import useRequest from '../../../util/useRequest';
import { HostsAPI } from '../../../api'; import { HostsAPI } from '../../../api';
function InventoryHostFacts({ i18n, host }) { function InventoryHostFacts({ i18n, host }) {
const { result: facts, isLoading, error, request: fetchFacts } = useRequest( const { request, isLoading, error, result } = useRequest(
useCallback(async () => { useCallback(async () => {
const [{ data: factsObj }] = await Promise.all([ const { data } = await HostsAPI.readFacts(host.id);
HostsAPI.readFacts(host.id),
]); return JSON.stringify(data, null, 4);
return JSON.stringify(factsObj, null, 4);
}, [host]), }, [host]),
'{}' null
); );
useEffect(() => { useEffect(() => {
fetchFacts(); request();
}, [fetchFacts]); }, [request]);
if (isLoading) {
return <ContentLoading />;
}
if (error) { if (error) {
return <ContentError error={error} />; return <ContentError error={error} />;
} }
if (isLoading || result === null) {
return <ContentLoading />;
}
return ( return (
<CardBody> <CardBody>
<DetailList gutter="sm"> <DetailList gutter="sm">
<VariablesDetail label={i18n._(t`Facts`)} fullHeight value={facts} /> <VariablesDetail label={i18n._(t`Facts`)} fullHeight value={result} />
</DetailList> </DetailList>
</CardBody> </CardBody>
); );