Skip to content

Commit 4c32c58

Browse files
committed
fix: review fixes
1 parent 69833fa commit 4c32c58

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

src/components/MemoryViewer/MemoryViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import type {TMemoryStats} from '../../types/api/nodes';
44
import {formatBytes} from '../../utils/bytesParsers';
55
import {cn} from '../../utils/cn';
66
import {GIGABYTE} from '../../utils/constants';
7+
import type {FormatProgressViewerValues} from '../../utils/progress';
78
import {calculateProgressStatus} from '../../utils/progress';
89
import {isNumeric} from '../../utils/utils';
910
import {HoverPopup} from '../HoverPopup/HoverPopup';
10-
import type {FormatProgressViewerValues} from '../ProgressViewer/ProgressViewer';
1111
import {ProgressViewer} from '../ProgressViewer/ProgressViewer';
1212

1313
import {calculateAllocatedMemory, getMemorySegments} from './utils';

src/components/ProgressViewer/ProgressViewer.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {useTheme} from '@gravity-ui/uikit';
22

33
import {cn} from '../../utils/cn';
4-
import {formatNumber, roundToPrecision} from '../../utils/dataFormatters/dataFormatters';
5-
import {calculateProgressStatus} from '../../utils/progress';
4+
import {calculateProgressStatus, defaultFormatProgressValues} from '../../utils/progress';
5+
import type {FormatProgressViewerValues} from '../../utils/progress';
66
import {isNumeric} from '../../utils/utils';
77

88
import './ProgressViewer.scss';
@@ -11,19 +11,6 @@ const b = cn('progress-viewer');
1111

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

14-
export type FormatProgressViewerValues = (
15-
value?: number,
16-
capacity?: number,
17-
) => (string | number | undefined)[];
18-
19-
const formatValue = (value?: number) => {
20-
return formatNumber(roundToPrecision(Number(value), 2));
21-
};
22-
23-
const defaultFormatValues: FormatProgressViewerValues = (value, total) => {
24-
return [formatValue(value), formatValue(total)];
25-
};
26-
2714
/*
2815
2916
Props description:
@@ -56,7 +43,7 @@ export interface ProgressViewerProps {
5643
export function ProgressViewer({
5744
value,
5845
capacity,
59-
formatValues = defaultFormatValues,
46+
formatValues = defaultFormatProgressValues,
6047
percents,
6148
withOverflow,
6249
className,

src/containers/Tenant/Diagnostics/TenantOverview/TenantStorage/ProgressWrapper.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react';
22

33
import {Flex, Progress, Text} from '@gravity-ui/uikit';
44

5-
import type {FormatProgressViewerValues} from '../../../../../components/ProgressViewer/ProgressViewer';
5+
import {defaultFormatProgressValues} from '../../../../../utils/progress';
6+
import type {FormatProgressViewerValues} from '../../../../../utils/progress';
67
import {isNumeric, safeParseNumber} from '../../../../../utils/utils';
78

89
import {DEFAULT_PROGRESS_WIDTH, MAX_PERCENTAGE, MIN_PERCENTAGE, PROGRESS_SIZE} from './constants';
@@ -16,14 +17,10 @@ interface ProgressWrapperProps {
1617
width?: number;
1718
}
1819

19-
const defaultFormatValues: FormatProgressViewerValues = (value, total) => {
20-
return [value, total];
21-
};
22-
2320
export function ProgressWrapper({
2421
value,
2522
capacity,
26-
formatValues = defaultFormatValues,
23+
formatValues = defaultFormatProgressValues,
2724
className,
2825
width = DEFAULT_PROGRESS_WIDTH,
2926
}: ProgressWrapperProps) {

src/utils/progress.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import {DEFAULT_DANGER_THRESHOLD, DEFAULT_WARNING_THRESHOLD} from './constants';
2+
import {formatNumber, roundToPrecision} from './dataFormatters/dataFormatters';
23

34
export type ProgressStatus = 'good' | 'warning' | 'danger';
45

6+
export type FormatProgressViewerValues = (
7+
value?: number,
8+
capacity?: number,
9+
) => (string | number | undefined)[];
10+
11+
const formatValue = (value?: number) => {
12+
return formatNumber(roundToPrecision(Number(value), 2));
13+
};
14+
15+
export const defaultFormatProgressValues: FormatProgressViewerValues = (value, total) => {
16+
return [formatValue(value), formatValue(total)];
17+
};
18+
519
interface CalculateProgressStatusProps {
620
inverseColorize?: boolean;
721
dangerThreshold?: number;

0 commit comments

Comments
 (0)