Skip to content

Commit 4595c07

Browse files
committed
fix: min visible share
1 parent 45041ca commit 4595c07

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/components/MemoryViewer/MemoryViewer.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,38 @@ import {DefinitionList, useTheme} from '@gravity-ui/uikit';
33
import type {TMemoryStats} from '../../types/api/nodes';
44
import {formatBytes} from '../../utils/bytesParsers';
55
import {cn} from '../../utils/cn';
6+
import {GIGABYTE} from '../../utils/constants';
67
import {calculateProgressStatus} from '../../utils/progress';
78
import {isNumeric} from '../../utils/utils';
89
import {HoverPopup} from '../HoverPopup/HoverPopup';
10+
import type {FormatProgressViewerValues} from '../ProgressViewer/ProgressViewer';
911
import {ProgressViewer} from '../ProgressViewer/ProgressViewer';
1012

1113
import {getMemorySegments} from './utils';
1214

1315
import './MemoryViewer.scss';
1416

17+
const MIN_VISIBLE_MEMORY_SHARE = 1;
18+
const MIN_VISIBLE_MEMORY_VALUE = 0.01 * GIGABYTE;
19+
1520
const 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

2239
export 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
/>

src/components/ProgressViewer/ProgressViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const b = cn('progress-viewer');
1111

1212
type ProgressViewerSize = 'xs' | 's' | 'ns' | 'm' | 'n' | 'l' | 'head';
1313

14-
type FormatProgressViewerValues = (
14+
export type FormatProgressViewerValues = (
1515
value?: number,
1616
capacity?: number,
1717
) => (string | number | undefined)[];

0 commit comments

Comments
 (0)