import type {IconData, LabelProps} from '@gravity-ui/uikit'; import {Icon, Label, Tooltip} from '@gravity-ui/uikit'; import {capitalize} from 'lodash'; import {EFlag, isCapacityAlert} from '../../types/api/enums'; import {normalizeCapacityAlert} from '../../utils/capacityAlerts'; import {cn} from '../../utils/cn'; import {formatPDiskType} from '../../utils/disks/getPDiskType'; import {getDisplaySeverityColor} from '../../utils/disks/helpers'; import {getFlagIconWithColor} from '../../utils/disks/iconCalculators'; import {normalizeMediaType} from '../../utils/disks/normalizeMediaType'; import {calculateSpaceSeverity} from '../../utils/disks/severityCalculators'; import {EFlagToLabelTheme} from '../EntityStatus/EntityStatus'; import {getFlagStatusText} from '../VDisk/getFlagStatusText'; import i18n from './i18n'; import './DiskStatus.scss'; const b = cn('ydb-disk-status'); export interface DiskStatusLabelData { value: string; title?: string; theme?: LabelProps['theme']; icon?: IconData; tooltip?: string; dangerHeavy?: boolean; } export type TitledDiskStatusLabelData = Omit & { title: string; value?: string; }; export function DiskStatusLabel({ value, theme = 'normal', icon, title, tooltip, dangerHeavy, size = 's', iconSize = 12, className, }: (DiskStatusLabelData | TitledDiskStatusLabelData) & Pick & {iconSize?: number}) { const label = ( ); return tooltip ? ( {label} ) : ( label ); } export function DiskTypeLabel({type, size}: {type?: string} & Pick) { if (!type?.trim()) { return null; } const mediaType = normalizeMediaType(type); const value = formatPDiskType(mediaType) ?? mediaType; let tooltip: string | undefined; switch (mediaType) { case 'HDD': tooltip = i18n('context_hdd'); break; case 'SSD': tooltip = i18n('context_ssd'); break; case 'NVME': tooltip = i18n('context_nvme'); break; } return ( ); } export function DiskCapacityAlertLabel({ value, emptyText = i18n('value_no-data'), }: { value?: string; emptyText?: string; }) { const capacityAlert = normalizeCapacityAlert(value); if (!capacityAlert) { return ; } const color = isCapacityAlert(capacityAlert) ? getDisplaySeverityColor( calculateSpaceSeverity({CapacityAlert: capacityAlert}), ).toLowerCase() : undefined; return ( ); } export function DiskFlagLabel({ flag, title, icon, emptyText = i18n('value_no-data'), }: { flag?: EFlag; title?: string; icon?: IconData; emptyText?: string; }) { const resolvedFlag = flag || EFlag.Grey; return ( ); }