import React from 'react' import { Icon } from "UI"; import ServiceCategory from "Components/Header/HealthStatus/ServiceCategory"; import cn from 'classnames' import { IServiceStats } from './HealthStatus' function HealthWidget({ healthResponse, getHealth, isLoading, lastAsked, setShowModal, isError, }: { healthResponse: { overallHealth: boolean; healthMap: Record }; getHealth: Function; isLoading: boolean; lastAsked: string | null; setShowModal: (visible: boolean) => void; isError?: boolean; }) { const [lastAskedDiff, setLastAskedDiff] = React.useState(0); const healthOk = healthResponse?.overallHealth; React.useEffect(() => { const now = new Date(); const lastAskedDate = lastAsked ? new Date(parseInt(lastAsked, 10)) : null; const diff = lastAskedDate ? now.getTime() - lastAskedDate.getTime() : 0; const diffInMinutes = Math.round(diff / 1000 / 60); setLastAskedDiff(diffInMinutes); }, [lastAsked]); const title = !isError && healthOk ? 'All Systems Operational' : 'Service disruption'; const icon = !isError && healthOk ? ('check-circle-fill' as const) : ('exclamation-circle-fill' as const); const problematicServices = Object.values(healthResponse?.healthMap || {}).filter( (service: Record) => !service.healthOk ) return (
{title}
Last checked {lastAskedDiff}min ago.
getHealth()} >
{isError &&
Error getting service health status
}
{!isError && !healthOk ? ( <>
Observed installation Issue with the following
{problematicServices.map((service) => ( setShowModal(true)} healthOk={false} name={service.name} isSelectable noBorder={problematicServices.length === 1} /> ))} ) : null}
); } export default HealthWidget