import React from 'react'; import { Icon } from 'UI'; import ServiceCategory from 'Components/Header/HealthStatus/ServiceCategory'; import cn from 'classnames'; import { IServiceStats } from './HealthStatus'; import { Divider, Space } from 'antd'; import VersionTag from "Components/Header/VersionTag"; function HealthWidget({ healthResponse, getHealth, isLoading, lastAsked, setShowModal, isError }: { healthResponse: { overallHealth: boolean; healthMap: Record, details: 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) : ('ic-errors' as const); const problematicServices = Object.values(healthResponse?.healthMap || {}).filter( (service: Record) => !service.healthOk ); return (
{title}
Checked {lastAskedDiff}min ago.
getHealth()} >
{isError &&
Error getting service health status
}
Captured
{healthResponse.details?.numberOfSessionsCaptured.toLocaleString()}
Sessions
{healthResponse.details?.numberOfEventCaptured.toLocaleString()}
Events
{!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;