import DataTable from '@gravity-ui/react-data-table'; import type {LabelProps} from '@gravity-ui/uikit'; import {Label} from '@gravity-ui/uikit'; import {isCapacityAlert} from '../../types/api/enums'; import {getCapacityAlertTheme, normalizeCapacityAlert} from '../../utils/capacityAlerts'; import {EMPTY_DATA_PLACEHOLDER} from '../../utils/constants'; import {formatNormalizedMetricPercent} from '../../utils/storageMetrics'; import type {Column} from '../../utils/tableUtils/types'; import {isNumeric, parseOptionalNonNegativeNumber} from '../../utils/utils'; import {TitleWithHelpMark} from '../TitleWithHelpmark/TitleWithHelpmark'; import { CAPACITY_METRICS_COLUMN_IDS, CAPACITY_METRICS_COLUMN_TITLES, CAPACITY_METRICS_HELP_TEXT, } from './constants'; export function getPDiskUsageColumn(): Column { return { name: CAPACITY_METRICS_COLUMN_IDS.MaxPDiskUsage, header: ( ), width: 150, render: ({row}) => { return formatNormalizedMetricPercent(row.MaxPDiskUsage); }, align: DataTable.RIGHT, }; } export function getVDiskSlotUsageColumn< T extends {MaxVDiskSlotUsage?: number; CapacityAlert?: string}, >(): Column { return { name: CAPACITY_METRICS_COLUMN_IDS.MaxVDiskSlotUsage, header: ( ), width: 180, render: ({row}) => { const theme: LabelProps['theme'] = isCapacityAlert(row.CapacityAlert) ? getCapacityAlertTheme(row.CapacityAlert) : 'normal'; return isNumeric(row.MaxVDiskSlotUsage) ? ( ) : ( EMPTY_DATA_PLACEHOLDER ); }, align: DataTable.RIGHT, }; } export function getCapacityAlertColumn(): Column { return { name: CAPACITY_METRICS_COLUMN_IDS.CapacityAlert, header: ( ), width: 150, render: ({row}) => { return normalizeCapacityAlert(row.CapacityAlert) ?? EMPTY_DATA_PLACEHOLDER; }, align: DataTable.CENTER, }; } export function getVDiskRawUsageColumn(): Column { return { name: CAPACITY_METRICS_COLUMN_IDS.MaxVDiskRawUsage, header: ( ), width: 180, render: ({row}) => { return formatNormalizedMetricPercent(row.MaxVDiskRawUsage); }, align: DataTable.RIGHT, }; } export function getNormalizedOccupancyColumn< T extends {MaxNormalizedOccupancy?: number}, >(): Column { return { name: CAPACITY_METRICS_COLUMN_IDS.MaxNormalizedOccupancy, header: ( ), width: 200, render: ({row}) => { const normalizedOccupancy = parseOptionalNonNegativeNumber(row.MaxNormalizedOccupancy); return normalizedOccupancy === undefined ? EMPTY_DATA_PLACEHOLDER : normalizedOccupancy.toFixed(2); }, align: DataTable.RIGHT, }; }