From edcf64c034603ccc0381a39040c96a3106695cb6 Mon Sep 17 00:00:00 2001 From: Max Frederiksen <maxfrederiksen@Maxs-MacBook-Air.local> Date: Mon, 30 Dec 2024 11:15:15 +0100 Subject: [PATCH] Add typing /components/host --- src/components/host/HostStatus/HostStatus.tsx | 16 +++++++++--- .../host/HostStatus/HostStatusData.ts | 11 ++++++-- src/components/host/HostTable.tsx | 25 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/components/host/HostStatus/HostStatus.tsx b/src/components/host/HostStatus/HostStatus.tsx index 990ce26e..92f859c7 100644 --- a/src/components/host/HostStatus/HostStatus.tsx +++ b/src/components/host/HostStatus/HostStatus.tsx @@ -6,14 +6,24 @@ import { useLazyFindHostAlertsQuery } from "../../../store/deployApi"; -export const HostStatus = ({ hostId, hideAlerts }) => { +interface HostStatusProps { + hostId?: string; + hideAlerts: boolean; +} + +export const HostStatus = ({ hostId, hideAlerts }: HostStatusProps) => { const [callFindHostAlerts, { data: hostAlert }] = useLazyFindHostAlertsQuery(); - const { data: hostStateStatus } = useFindHostStatusQuery({ hostId }); + const { data: hostStateStatus } = useFindHostStatusQuery( + { + hostId: hostId ?? "" + }, + { skip: !hostId } + ); useEffect(() => { - if (!hideAlerts) { + if (!hideAlerts && hostId) { callFindHostAlerts({ hostId }); } }, [callFindHostAlerts, hideAlerts, hostId]); diff --git a/src/components/host/HostStatus/HostStatusData.ts b/src/components/host/HostStatus/HostStatusData.ts index ce72ed31..9d7104ab 100644 --- a/src/components/host/HostStatus/HostStatusData.ts +++ b/src/components/host/HostStatus/HostStatusData.ts @@ -1,3 +1,7 @@ +import { + HostAlertResponse, + HostStatusResponse +} from "../../../store/deployApi"; import { SEVERITY, STATUS } from "../../common/Status"; export const HOST_STATUS = { @@ -5,8 +9,11 @@ export const HOST_STATUS = { unreachable: "UNREACHABLE" }; -export const getHostStatus = (state, alert) => { - let { status } = state; +export const getHostStatus = ( + state: HostStatusResponse, + alert: HostAlertResponse | undefined +) => { + const { status } = state; const alertSeverity = alert?.alertSeverity?.toLowerCase(); if ( diff --git a/src/components/host/HostTable.tsx b/src/components/host/HostTable.tsx index 74c89031..b63c2f59 100644 --- a/src/components/host/HostTable.tsx +++ b/src/components/host/HostTable.tsx @@ -1,5 +1,7 @@ import { Table, InternalLink, EllipsisText } from "@ess-ics/ce-ui-common"; import { HostStatus } from "./HostStatus"; +import { HostInfoWithId } from "../../store/deployApi"; +import { OnPageParams, Pagination } from "../../types/common"; const columns = [ { @@ -15,10 +17,15 @@ const columns = [ { field: "scope", headerName: "Network scope" } ]; -function CreateRow(host) { +function CreateRow(host: HostInfoWithId) { return { id: host.hostId, - status: <HostStatus hostId={host.hostId} />, + status: ( + <HostStatus + hostId={host?.hostId} + hideAlerts={false} + /> + ), hostName: ( <InternalLink to={`/hosts/${host.hostId}`} @@ -35,7 +42,19 @@ function CreateRow(host) { }; } -export function HostTable({ hosts, pagination, onPage, loading }) { +interface HostTableProps { + hosts: HostInfoWithId[] | undefined; + pagination?: Pagination; + onPage?: (page: OnPageParams) => void; + loading: boolean; +} + +export function HostTable({ + hosts, + pagination, + onPage, + loading +}: HostTableProps) { return ( <Table columns={columns} -- GitLab