From e51817f4005580d266222d4e52de3d9de54cf696 Mon Sep 17 00:00:00 2001 From: Imre Toth <imre.toth@ess.eu> Date: Thu, 28 Sep 2023 10:28:25 +0200 Subject: [PATCH] CE-2099: Convert useActiveHistory hook --- src/api/SwaggerApi.js | 14 -------------- .../DeploymentLineChart/DeploymentLineChart.js | 8 ++++++-- src/views/statistics/StatisticsView.js | 16 +++++++++++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index 118f158d..e9f1f938 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -374,20 +374,6 @@ export function useTagsAndCommitIds(onError) { return useAsync({ fcn: method, call: false, onError: onError, init: [] }); } -export function unpackActiveIOCHistory(statistics) { - return { ...statistics }; -} - -export function useActiveIOCHistory() { - const api = useContext(apiContext); - const method = useCallAndUnpack( - api.apis.Statistics.activeIocHistory, - unpackActiveIOCHistory - ); - - return useAsync({ fcn: method, call: false }); -} - export function unpackParam(param) { return { ...param }; } diff --git a/src/components/statistics/DeploymentLineChart/DeploymentLineChart.js b/src/components/statistics/DeploymentLineChart/DeploymentLineChart.js index 912af09d..2b12c503 100644 --- a/src/components/statistics/DeploymentLineChart/DeploymentLineChart.js +++ b/src/components/statistics/DeploymentLineChart/DeploymentLineChart.js @@ -13,8 +13,12 @@ import { Tooltip } from "recharts"; -export default function DeploymentLineChart({ title, chartLabel, hook }) { - const [iocDeployments, getIOCDeployments] = hook(); +export default function DeploymentLineChart({ + title, + chartLabel, + iocDeployments, + getIOCDeployments +}) { const theme = useTheme(); useEffect(() => { diff --git a/src/views/statistics/StatisticsView.js b/src/views/statistics/StatisticsView.js index 00043bb0..22b9ab73 100644 --- a/src/views/statistics/StatisticsView.js +++ b/src/views/statistics/StatisticsView.js @@ -5,14 +5,13 @@ import { GlobalAppBarContext } from "@ess-ics/ce-ui-common"; import { RootContainer } from "../../components/common/Container/RootContainer"; import ActiveIOCChart from "../../components/statistics/ActiveIOCChart"; import DeploymentLineChart from "../../components/statistics/DeploymentLineChart"; -import { - useActiveIOCHistory, - useDeploymenStatistics -} from "../../api/SwaggerApi"; +import { useDeploymenStatistics } from "../../api/SwaggerApi"; import { HostStatistics } from "../../components/statistics/HostStatistics"; import { IOCStatistics } from "../../components/statistics/IOCStatistics"; import OperationChart from "../../components/statistics/OperationChart/OperationChart"; import { applicationTitle } from "../../components/common/Helper"; +import { apiContext } from "../../api/DeployApi"; +import { useAPIMethod } from "@ess-ics/ce-ui-common"; const PREFIX = "StatisticsView"; @@ -29,9 +28,15 @@ const StyledRootContainer = styled(RootContainer)(({ theme }) => ({ export function StatisticsView() { const { setTitle } = useContext(GlobalAppBarContext); useEffect(() => setTitle(applicationTitle("Statistics")), [setTitle]); + const client = useContext(apiContext); const theme = useTheme(); + const { value: iocsOverTime, wrapper: getIocsOverTime } = useAPIMethod({ + fcn: client.apis.Statistics.activeIocHistory, + call: false + }); + return ( <StyledRootContainer> <Grid @@ -79,7 +84,8 @@ export function StatisticsView() { <DeploymentLineChart title="Number of IOCs detected over time" chartLabel="Active IOCs over time" - hook={useActiveIOCHistory} + iocDeployments={iocsOverTime} + getIOCDeployments={getIocsOverTime} /> </Paper> </Grid> -- GitLab