|
| 1 | +import { |
| 2 | + CircleCheck, |
| 3 | + CircleExclamation, |
| 4 | + CircleInfo, |
| 5 | + PlugConnection, |
| 6 | + TriangleExclamation, |
| 7 | +} from '@gravity-ui/icons'; |
| 8 | +import type {LabelProps} from '@gravity-ui/uikit'; |
| 9 | +import {Icon, Label} from '@gravity-ui/uikit'; |
| 10 | + |
| 11 | +import {SelfCheckResult} from '../../types/api/healthcheck'; |
| 12 | + |
| 13 | +import i18n from './i18n'; |
| 14 | + |
| 15 | +const SelfCheckResultToLabelTheme: Record<SelfCheckResult, LabelProps['theme']> = { |
| 16 | + [SelfCheckResult.GOOD]: 'success', |
| 17 | + [SelfCheckResult.DEGRADED]: 'info', |
| 18 | + [SelfCheckResult.MAINTENANCE_REQUIRED]: 'warning', |
| 19 | + [SelfCheckResult.EMERGENCY]: 'danger', |
| 20 | + [SelfCheckResult.UNSPECIFIED]: 'normal', |
| 21 | +}; |
| 22 | + |
| 23 | +const SelfCheckResultToIcon: Record< |
| 24 | + SelfCheckResult, |
| 25 | + (props: React.SVGProps<SVGSVGElement>) => React.JSX.Element |
| 26 | +> = { |
| 27 | + [SelfCheckResult.GOOD]: CircleCheck, |
| 28 | + [SelfCheckResult.DEGRADED]: CircleInfo, |
| 29 | + [SelfCheckResult.MAINTENANCE_REQUIRED]: TriangleExclamation, |
| 30 | + [SelfCheckResult.EMERGENCY]: CircleExclamation, |
| 31 | + [SelfCheckResult.UNSPECIFIED]: PlugConnection, |
| 32 | +}; |
| 33 | + |
| 34 | +const SelfCheckResultToText: Record<SelfCheckResult, string> = { |
| 35 | + get [SelfCheckResult.GOOD]() { |
| 36 | + return i18n('title_good'); |
| 37 | + }, |
| 38 | + get [SelfCheckResult.DEGRADED]() { |
| 39 | + return i18n('title_degraded'); |
| 40 | + }, |
| 41 | + get [SelfCheckResult.MAINTENANCE_REQUIRED]() { |
| 42 | + return i18n('title_maintenance'); |
| 43 | + }, |
| 44 | + get [SelfCheckResult.EMERGENCY]() { |
| 45 | + return i18n('title_emergency'); |
| 46 | + }, |
| 47 | + get [SelfCheckResult.UNSPECIFIED]() { |
| 48 | + return i18n('title_unspecified'); |
| 49 | + }, |
| 50 | +}; |
| 51 | + |
| 52 | +interface HealthcheckStatusProps { |
| 53 | + status: SelfCheckResult; |
| 54 | + size?: LabelProps['size']; |
| 55 | +} |
| 56 | + |
| 57 | +export function HealthcheckStatus({status, size = 'm'}: HealthcheckStatusProps) { |
| 58 | + const theme = SelfCheckResultToLabelTheme[status]; |
| 59 | + |
| 60 | + return ( |
| 61 | + <Label |
| 62 | + theme={theme} |
| 63 | + icon={<Icon size={14} data={SelfCheckResultToIcon[status]} />} |
| 64 | + size={size} |
| 65 | + > |
| 66 | + {SelfCheckResultToText[status]} |
| 67 | + </Label> |
| 68 | + ); |
| 69 | +} |
0 commit comments