Merge pull request #7978 from jakemcdermott/fix-7977

Don't display facts until facts are loaded

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-08-24 19:33:26 +00:00 committed by GitHub
commit 1a033653ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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