Skip to content
Snippets Groups Projects
Commit e4329d6d authored by Johanna Szepanski's avatar Johanna Szepanski
Browse files

changed to rtk and cleaned up details container

parent 5dede217
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!577CE-3395: Fix infinite loop
import { useEffect, useContext, useState, useMemo } from "react";
import { LinearProgress } from "@mui/material";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { IOCDetailsView } from "./IOCDetailsView";
import { NotFoundView } from "../../components/navigation/NotFoundView/NotFoundView";
import { onFetchEntityError } from "../../components/common/Helper";
import { apiContext } from "../../api/DeployApi";
import { useGetIocQuery } from "../../store/enhancedApi";
import { ApiAlertError } from "../../components/common/Alerts/ApiAlertError";
export function IOCDetailsContainer({ id }) {
const [error, setError] = useState(null);
const client = useContext(apiContext);
const IOC_POLL_INTERVAL = 5000;
const params = useMemo(
() => ({
ioc_id: id
}),
[id]
export function IOCDetailsContainer({ id }) {
const { data: ioc, error } = useGetIocQuery(
{ iocId: id },
{ pollingInterval: IOC_POLL_INTERVAL }
);
const {
value: ioc,
wrapper: getIOC,
loading,
error: fetchError,
abort: abortGetIOC
} = useAPIMethod({
fcn: client.apis.IOCs.getIoc,
params
});
useEffect(() => {
if (fetchError) {
onFetchEntityError(fetchError?.message, fetchError?.status, setError);
}
}, [fetchError]);
if (error) {
return (
<NotFoundView
message={error?.message}
status={error?.status}
/>
);
if (error && "status" in error && error.status === 404) {
return <NotFoundView />;
}
if (!ioc && !error) {
return <LinearProgress color="primary" />;
if (error) {
return <ApiAlertError error={error} />;
}
return (
<IOCDetailsView
ioc={ioc}
getIOC={getIOC}
abortGetIOC={abortGetIOC}
loading={loading}
/>
<>
{ioc ? <IOCDetailsView ioc={ioc} /> : <LinearProgress color="primary" />}
</>
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment