Skip to content
Snippets Groups Projects
Commit 0959dbff authored by Alexander Madsen's avatar Alexander Madsen
Browse files

CE-2075: Convert useHostIOCList

parent 6a0f1f86
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!349CE-2075: Convert useHostIOCList
......@@ -380,13 +380,6 @@ export function useCSEntrySearch() {
return useAsync({ fcn: method, call: false, init: emptyHostListResponse });
}
const emptyHostIocListResponse = {
totalCount: 0,
pageNumber: 0,
limit: 0,
deployedList: []
};
export function unpackRecord(record) {
return { ...record };
}
......@@ -429,28 +422,6 @@ export function useRecord(name, onError) {
return useAsync({ fcn: boundMethod, onError: onError });
}
export function unpackHostIOCList(iocs) {
const deployedArr = iocs.deployedIocs.map((ioc) => unpackIocInfo(ioc));
let unpackedHostIocList = {
totalCount: iocs.totalCount,
pageNumber: iocs.pageNumber,
limit: iocs.limit,
deployedList: deployedArr
};
return unpackedHostIocList;
}
export function useHostIOCList() {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(params) => api.apis.Hosts.findAssociatedIocsByHostId(params),
unpackHostIOCList
);
return useAsync({ fcn: method, call: false, init: emptyHostIocListResponse });
}
export function unpackLogin(loginResponse) {
return { ...loginResponse };
}
......
......@@ -10,13 +10,13 @@ import {
Stack
} from "@mui/material";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { useHostIOCList } from "../../api/SwaggerApi";
import { HostBadge } from "../../components/host/HostBadge";
import {
KeyValueTable,
SimpleAccordion,
GlobalAppBarContext,
RootPaper
RootPaper,
useAPIMethod
} from "@ess-ics/ce-ui-common";
import { LokiPanel } from "../../components/common/Loki/LokiPanel";
import { useNavigate, Link as ReactRouterLink } from "react-router-dom";
......@@ -31,6 +31,7 @@ import {
serialize,
deserialize
} from "../../components/common/URLState/URLState";
import { apiContext } from "../../api/DeployApi";
import { usePagination } from "../../hooks/pagination";
import IOCTable from "../../components/IOC/IOCTable";
......@@ -42,7 +43,17 @@ export function HostDetailsView({ id, host }) {
}
}, [host, setTitle]);
const [iocs, getIocs /* reset*/, , loading] = useHostIOCList();
const client = useContext(apiContext);
const {
value: iocs,
wrapper: getIocs,
loading,
dataReady
} = useAPIMethod({
fcn: client.apis.Hosts.findAssociatedIocsByHostId,
call: false
});
const [urlState, setUrlState] = useUrlState(
{
......@@ -84,8 +95,8 @@ export function HostDetailsView({ id, host }) {
// update pagination whenever search result total pages change
useEffect(() => {
setPagination({ totalCount: iocs.totalCount ?? 0 });
}, [setPagination, iocs.totalCount]);
setPagination({ totalCount: iocs?.totalCount ?? 0 });
}, [setPagination, iocs?.totalCount]);
// whenever url state changes, update pagination
useEffect(() => {
......@@ -193,8 +204,8 @@ export function HostDetailsView({ id, host }) {
}
>
<IOCTable
iocs={iocs?.deployedList}
loading={loading}
iocs={iocs?.deployedIocs}
loading={loading || !dataReady}
rowType="host"
pagination={pagination}
onPage={onPage}
......
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