import React from 'react'; import {Flex, Icon} from '@gravity-ui/uikit'; import {useDrawerContextInternal} from '../../../components/Drawer/DrawerContext'; import {ResponseError} from '../../../components/Errors/ResponseError'; import {Fullscreen} from '../../../components/Fullscreen/Fullscreen'; import {HealthcheckStatus} from '../../../components/HealthcheckStatus/HealthcheckStatus'; import {Loader} from '../../../components/Loader'; import type {IssuesTree} from '../../../store/reducers/healthcheckInfo/types'; import {SelfCheckResult} from '../../../types/api/healthcheck'; import type {ETenantType} from '../../../types/api/tenant'; import {uiFactory} from '../../../uiFactory/uiFactory'; import {useTypedSelector} from '../../../utils/hooks'; import {getIllustration} from '../../../utils/illustrations'; import {HEALTHCHECK_RESULT_TO_TEXT} from '../constants'; import {HealthcheckContext} from './HealthcheckContext'; import {HealthcheckFilter} from './components/HealthcheckFilter'; import {Issues} from './components/HealthcheckIssues'; import {HealthcheckRefresh} from './components/HealthcheckRefresh'; import {HealthcheckView} from './components/HealthcheckView'; import i18n from './i18n'; import {b} from './shared'; import type {HealthcheckAssistantSnapshot, HealthcheckAssistantTarget} from './types'; import {useClusterHealthcheck, useHealthcheck} from './useHealthcheck'; import { countHealthcheckIssuesByCategory, getDatabaseHealthcheckAssistantTarget, getHealthcheckAssistantContext, } from './utils'; import cryCatIcon from '../../../assets/icons/cry-cat.svg'; import './Healthcheck.scss'; type HealthcheckDetailsProps = ( | { database: string; clusterName?: string; databaseType?: ETenantType; scope?: 'cluster' | 'database'; } | { clusterName: string; database?: undefined; databaseType?: undefined; scope?: 'cluster'; } ) & { targetIssueId?: string; targetLeafIssueId?: string; targetLeafIssueRef?: React.Ref; }; export function Healthcheck(props: HealthcheckDetailsProps) { if (props.database !== undefined) { return ( ); } return ( ); } function DatabaseHealthcheckInner({ database, clusterName, databaseType, scope = 'database', targetIssueId, targetLeafIssueId, targetLeafIssueRef, }: { database: string; clusterName?: string; databaseType?: ETenantType; scope?: 'cluster' | 'database'; targetIssueId?: string; targetLeafIssueId?: string; targetLeafIssueRef?: React.Ref; }) { const healthcheck = useHealthcheck(database, {clusterName, databaseType}); const target = getDatabaseHealthcheckAssistantTarget({database, clusterName, scope}); return ( ); } function ClusterHealthcheckInner({clusterName}: {clusterName: string}) { const healthcheck = useClusterHealthcheck(clusterName); return ( ); } interface HealthcheckResult { leavesIssues: IssuesTree[]; issues: HealthcheckAssistantSnapshot['issues']; loading: boolean; successful: boolean; error?: unknown; refetch: () => void; selfCheckResult: SelfCheckResult; fulfilledTimeStamp?: number; } function HealthcheckContent({ healthcheck, target, targetIssueId, targetLeafIssueId, targetLeafIssueRef, }: { healthcheck: HealthcheckResult; target: HealthcheckAssistantTarget; targetIssueId?: string; targetLeafIssueId?: string; targetLeafIssueRef?: React.Ref; }) { const SuccessImage = getIllustration('SuccessOperation'); const renderAssistantAction = uiFactory.healthcheck.renderAssistantAction; const healthcheckContext = React.useContext(HealthcheckContext); const {visibleRightInset} = useDrawerContextInternal(); const fullscreen = useTypedSelector((state) => state.fullscreen); const { loading, successful, error, selfCheckResult, fulfilledTimeStamp, leavesIssues, issues, refetch, } = healthcheck; const snapshot = React.useMemo( () => ({ selfCheckResult, issues, fulfilledAt: fulfilledTimeStamp, }), [fulfilledTimeStamp, issues, selfCheckResult], ); const issuesCount = React.useMemo( () => countHealthcheckIssuesByCategory(leavesIssues), [leavesIssues], ); const assistant = getHealthcheckAssistantContext({ renderAction: renderAssistantAction, successful, target, snapshot, }); const renderControls = () => { return ( {assistant && issues.length > 0 ? ( {assistant.renderAction({ action: 'diagnostics', target: assistant.target, snapshot: assistant.snapshot, })} ) : ( )} ); }; const renderContent = () => { if (error) { return ( ); } if (loading) { return ; } if (selfCheckResult === SelfCheckResult.GOOD && (!leavesIssues || !leavesIssues.length)) { return ( {HEALTHCHECK_RESULT_TO_TEXT[selfCheckResult]} ); } return ( {renderControls()} ); }; return ( {renderContent()} ); }