import React from 'react'; import { Icon } from 'UI'; import ServiceCategory from 'Components/Header/HealthStatus/ServiceCategory'; import cn from 'classnames'; import { Divider, Space } from 'antd'; import VersionTag from 'Components/Header/VersionTag'; import { IServiceStats } from './HealthStatus'; import { useTranslation } from 'react-i18next'; 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 { t } = useTranslation(); 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 ? t('All Systems Operational') : t('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}
{t('Checked')}  {lastAskedDiff}  {t('min ago.')}
getHealth()} >
{isError && (
{t('Error getting service health status')}
)}
{t('Captured')}
{healthResponse.details?.numberOfSessionsCaptured.toLocaleString()}
{t('Sessions')}
{healthResponse.details?.numberOfEventCaptured.toLocaleString()}
{t('Events')}
{!isError && !healthOk ? ( <>
{t('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;