@@ -6,15 +6,19 @@ import type {PreparedStorageGroup} from '../../store/reducers/storage/types';
66import { isCapacityAlert } from '../../types/api/enums' ;
77import { getCapacityAlertTheme , normalizeCapacityAlert } from '../../utils/capacityAlerts' ;
88import { EMPTY_DATA_PLACEHOLDER } from '../../utils/constants' ;
9+ import type { DiskDetailItem } from '../../utils/disks/diskInfo/getDiskLocationItems' ;
910import type { PreparedPDisk , PreparedVDisk } from '../../utils/disks/types' ;
1011import {
1112 formatMetricCountPair ,
1213 formatMetricPercent ,
1314 formatNormalizedMetricPercent ,
1415 formatStorageMetricPair ,
1516} from '../../utils/storageMetrics' ;
17+ import { DiskCapacityAlertLabel } from '../DiskStatus/DiskStatus' ;
1618import type { InfoViewerItem } from '../InfoViewer' ;
19+ import { pDiskInfoKeyset } from '../PDiskInfo/i18n' ;
1720import { TitleWithHelpMark } from '../TitleWithHelpmark/TitleWithHelpmark' ;
21+ import { vDiskInfoKeyset } from '../VDiskInfo/i18n' ;
1822import type { YDBDefinitionListItem } from '../YDBDefinitionList/YDBDefinitionList' ;
1923import {
2024 CAPACITY_CONFIGURATION_HELP_TEXT ,
@@ -98,22 +102,36 @@ export function getVDiskCapacityInfoItems(
98102
99103export function getPDiskCapacityInfoItems (
100104 data : PreparedPDisk | undefined ,
101- { withUsage, withCapacityAlert} : { withUsage : boolean ; withCapacityAlert : boolean } ,
105+ {
106+ withUsage,
107+ withCapacityAlert,
108+ fixedDecimalPlaces,
109+ useWhiteboardSize = true ,
110+ } : {
111+ withUsage : boolean ;
112+ withCapacityAlert : boolean ;
113+ fixedDecimalPlaces ?: number ;
114+ useWhiteboardSize ?: boolean ;
115+ } ,
102116) : DiskCapacityInfoItem [ ] {
103- const sizeData = data ?. WhiteboardSize ?? data ;
117+ const sizeData = useWhiteboardSize ? ( data ?. WhiteboardSize ?? data ) : data ;
104118 const items : DiskCapacityInfoItem [ ] = [
105119 {
106120 id : 'space' ,
107121 title : i18n ( 'field_space' ) ,
108- value : formatStorageMetricPair ( sizeData ?. AllocatedSize , sizeData ?. TotalSize ) ,
122+ value : formatStorageMetricPair (
123+ sizeData ?. AllocatedSize ,
124+ sizeData ?. TotalSize ,
125+ fixedDecimalPlaces ,
126+ ) ,
109127 } ,
110128 ] ;
111129
112130 if ( withUsage ) {
113131 items . push ( {
114132 id : 'pdisk-usage' ,
115133 title : CAPACITY_METRICS_COLUMN_TITLES . MaxPDiskUsage ,
116- value : formatMetricPercent ( data ?. PDiskUsage ) ,
134+ value : formatMetricPercent ( data ?. PDiskUsage , fixedDecimalPlaces ) ,
117135 note : CAPACITY_METRICS_HELP_TEXT . MaxPDiskUsage ,
118136 } ) ;
119137 }
@@ -144,6 +162,80 @@ export function getPDiskCapacityInfoItems(
144162 return items ;
145163}
146164
165+ export function getVDiskCapacityItems (
166+ data : PreparedVDisk ,
167+ { capacityMetricsEnabled} : { capacityMetricsEnabled : boolean } ,
168+ ) : DiskDetailItem [ ] {
169+ const size : Pick < PreparedVDisk , 'AllocatedSize' | 'SizeLimit' | 'HasCompleteSizeData' > =
170+ capacityMetricsEnabled ? ( data . WhiteboardSize ?? data ) : data ;
171+ const items : DiskDetailItem [ ] = [
172+ {
173+ id : 'group-size-in-units' ,
174+ name : vDiskInfoKeyset ( 'field_group-size-in-units' ) ,
175+ content : formatCapacityUnitCount ( data . GroupSizeInUnits ) ,
176+ note : CAPACITY_CONFIGURATION_HELP_TEXT . GroupSizeInUnits ,
177+ } ,
178+ {
179+ id : 'size' ,
180+ name : vDiskInfoKeyset ( 'size' ) ,
181+ content :
182+ size . HasCompleteSizeData === false
183+ ? EMPTY_DATA_PLACEHOLDER
184+ : formatStorageMetricPair ( size . AllocatedSize , size . SizeLimit , 2 ) ,
185+ } ,
186+ {
187+ id : 'capacity-alert' ,
188+ name : vDiskInfoKeyset ( 'field_capacity-alert' ) ,
189+ content : < DiskCapacityAlertLabel value = { data . CapacityAlert } /> ,
190+ note : CAPACITY_METRICS_HELP_TEXT . CapacityAlert ,
191+ } ,
192+ {
193+ id : 'vdisk-slot-usage' ,
194+ name : CAPACITY_METRICS_COLUMN_TITLES . MaxVDiskSlotUsage ,
195+ content : formatMetricPercent ( data . VDiskSlotUsage , 2 ) ,
196+ note : CAPACITY_METRICS_HELP_TEXT . MaxVDiskSlotUsage ,
197+ } ,
198+ {
199+ id : 'vdisk-raw-usage' ,
200+ name : CAPACITY_METRICS_COLUMN_TITLES . MaxVDiskRawUsage ,
201+ content : formatMetricPercent ( data . VDiskRawUsage , 2 ) ,
202+ note : CAPACITY_METRICS_HELP_TEXT . MaxVDiskRawUsage ,
203+ } ,
204+ ] ;
205+ return items . filter ( ( { id} ) => capacityMetricsEnabled || id === 'size' ) ;
206+ }
207+
208+ export function getPDiskCapacityItems (
209+ data : PreparedPDisk ,
210+ { useWhiteboardSize = true } : { useWhiteboardSize ?: boolean } = { } ,
211+ ) : DiskDetailItem [ ] {
212+ const fieldOrder = [ 'slot-size-in-units' , 'space' , 'capacity-alert' , 'pdisk-usage' , 'slots' ] ;
213+ const capacityItems = getPDiskCapacityInfoItems ( data , {
214+ withUsage : true ,
215+ withCapacityAlert : true ,
216+ fixedDecimalPlaces : 2 ,
217+ useWhiteboardSize,
218+ } ) ;
219+ const items : DiskDetailItem [ ] = [ ] ;
220+ for ( const id of fieldOrder ) {
221+ const field = capacityItems . find ( ( item ) => item . id === id ) ;
222+ if ( field ) {
223+ items . push ( {
224+ id,
225+ name : field . title ,
226+ content :
227+ id === 'capacity-alert' ? (
228+ < DiskCapacityAlertLabel value = { data . PDiskCapacityAlert } />
229+ ) : (
230+ field . value
231+ ) ,
232+ note : id === 'slots' ? pDiskInfoKeyset ( 'context_slots' ) : field . note ,
233+ } ) ;
234+ }
235+ }
236+ return items ;
237+ }
238+
147239export function getStorageGroupCapacityInfoItems (
148240 data : PreparedStorageGroup | undefined ,
149241) : DiskCapacityInfoItem [ ] {
0 commit comments