@@ -3,21 +3,38 @@ import {DefinitionList, useTheme} from '@gravity-ui/uikit';
33import type { TMemoryStats } from '../../types/api/nodes' ;
44import { formatBytes } from '../../utils/bytesParsers' ;
55import { cn } from '../../utils/cn' ;
6+ import { GIGABYTE } from '../../utils/constants' ;
67import { calculateProgressStatus } from '../../utils/progress' ;
78import { isNumeric } from '../../utils/utils' ;
89import { HoverPopup } from '../HoverPopup/HoverPopup' ;
10+ import type { FormatProgressViewerValues } from '../ProgressViewer/ProgressViewer' ;
911import { ProgressViewer } from '../ProgressViewer/ProgressViewer' ;
1012
1113import { getMemorySegments } from './utils' ;
1214
1315import './MemoryViewer.scss' ;
1416
17+ const MIN_VISIBLE_MEMORY_SHARE = 1 ;
18+ const MIN_VISIBLE_MEMORY_VALUE = 0.01 * GIGABYTE ;
19+
1520const b = cn ( 'memory-viewer' ) ;
1621
17- type FormatProgressViewerValues = (
18- value ?: number ,
19- capacity ?: number ,
20- ) => ( string | number | undefined ) [ ] ;
22+ const formatDetailedValues : FormatProgressViewerValues = ( value , total ) => {
23+ return [
24+ formatBytes ( {
25+ value,
26+ size : 'gb' ,
27+ withSizeLabel : false ,
28+ precision : 2 ,
29+ } ) ,
30+ formatBytes ( {
31+ value : total ,
32+ size : 'gb' ,
33+ withSizeLabel : true ,
34+ precision : 1 ,
35+ } ) ,
36+ ] ;
37+ } ;
2138
2239export interface MemoryProgressViewerProps {
2340 stats : TMemoryStats ;
@@ -100,7 +117,7 @@ export function MemoryViewer({
100117 < ProgressViewer
101118 value = { segmentSize }
102119 capacity = { segmentCapacity }
103- formatValues = { formatValues }
120+ formatValues = { formatDetailedValues }
104121 colorizeProgress
105122 />
106123 ) : (
@@ -122,15 +139,23 @@ export function MemoryViewer({
122139 { memorySegments
123140 . filter ( ( { isInfo} ) => ! isInfo )
124141 . map ( ( segment ) => {
142+ if ( segment . value < MIN_VISIBLE_MEMORY_VALUE ) {
143+ return null ;
144+ }
145+
146+ const currentMemoryShare = Math . max (
147+ calculateMemoryShare ( segment . value ) ,
148+ MIN_VISIBLE_MEMORY_SHARE ,
149+ ) ;
125150 const position = currentPosition ;
126- currentPosition += calculateMemoryShare ( segment . value ) ;
151+ currentPosition += currentMemoryShare ;
127152
128153 return (
129154 < div
130155 key = { segment . key }
131156 className = { b ( 'segment' , { type : segment . key } ) }
132157 style = { {
133- width : `${ calculateMemoryShare ( segment . value ) . toFixed ( 2 ) } %` ,
158+ width : `${ currentMemoryShare } %` ,
134159 left : `${ position } %` ,
135160 } }
136161 />
0 commit comments