Skip to content

Commit 89b0041

Browse files
committed
fixup! refactor: migrtae ProgressViewer to ts
1 parent efa2459 commit 89b0041

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/components/ProgressViewer/ProgressViewer.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cn from 'bem-cn-lite';
22

3-
import {ValueOf} from '../../types/common';
3+
import type {ValueOf} from '../../types/common';
44

55
import './ProgressViewer.scss';
66

@@ -20,20 +20,19 @@ type ProgressViewerSize = ValueOf<typeof PROGRESS_VIEWER_SIZE_IDS>;
2020

2121
/*
2222
23-
Описание props:
24-
1) value - величина прогресса
25-
2) capacity - предельно возможный прогресс
26-
3) formatValues - функция форматирования value и capacity
27-
4) percents - отображать ли заполненость в виде процентов
28-
5) className - кастомный класс
29-
6) colorizeProgress - менять ли цвет полосы прогресса в зависимости от его величины
30-
7) inverseColorize - инвертировать ли цвета при разукрашивании прогресса
23+
Props description:
24+
1) value - the amount of progress
25+
2) capacity - maximum possible progress value
26+
3) formatValues - function for formatting the value and capacity
27+
4) percents - display progress in percents
28+
5) colorizeProgress - change the color of the progress bar depending on its value
29+
6) inverseColorize - invert the colors of the progress bar
3130
*/
3231

3332
interface ProgressViewerProps {
3433
value?: number | string;
3534
capacity?: number | string;
36-
formatValues?: (value?: number, total?: number) => (string | undefined)[];
35+
formatValues?: (value?: number, capacity?: number) => (string | undefined)[];
3736
percents?: boolean;
3837
className?: string;
3938
size?: ProgressViewerSize;
@@ -54,13 +53,11 @@ export function ProgressViewer({
5453
let fillWidth = Math.round((parseFloat(String(value)) / parseFloat(String(capacity))) * 100);
5554
fillWidth = fillWidth > 100 ? 100 : fillWidth;
5655

57-
let valueText = String(Math.round(Number(value))),
58-
capacityText = capacity,
56+
let valueText: number | string | undefined = Math.round(Number(value)),
57+
capacityText: number | string | undefined = capacity,
5958
divider = '/';
60-
let formattedValue: string | undefined;
61-
let formattedCapacity: string | undefined;
6259
if (formatValues) {
63-
[formattedValue, formattedCapacity] = formatValues(Number(value), Number(capacity));
60+
[valueText, capacityText] = formatValues(Number(value), Number(capacity));
6461
} else if (percents) {
6562
valueText = fillWidth + '%';
6663
capacityText = '';
@@ -86,9 +83,9 @@ export function ProgressViewer({
8683
return (
8784
<div className={b({size}, className)}>
8885
<div className={b('line', {bg})} style={lineStyle}></div>
89-
<span className={b('text', {text})}>{`${formattedValue || valueText} ${divider} ${
90-
formattedCapacity || capacityText
91-
}`}</span>
86+
<span
87+
className={b('text', {text})}
88+
>{`${valueText} ${divider} ${capacityText}`}</span>
9289
</div>
9390
);
9491
}

src/utils/dataFormatters/dataFormatters.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {dateTimeParse} from '@gravity-ui/date-utils';
22

3-
import {TVDiskID, TVSlotId} from '../../types/api/vdisk';
3+
import type {TVDiskID, TVSlotId} from '../../types/api/vdisk';
44
import {DAY_IN_SECONDS, GIGABYTE, TERABYTE} from '../constants';
55
import {configuredNumeral} from '../numeral';
66
import {isNumeric} from '../utils';
@@ -36,8 +36,8 @@ export const stringifyVdiskId = (id?: TVDiskID | TVSlotId) => {
3636
return id ? Object.values(id).join('-') : '';
3737
};
3838

39-
export const getPDiskId = (info?: {NodeId?: number; PDiskId?: number}) => {
40-
return `${info?.NodeId}-${info?.PDiskId}`;
39+
export const getPDiskId = (info: {NodeId?: number; PDiskId?: number}) => {
40+
return info.NodeId && info.PDiskId ? `${info.NodeId}-${info.PDiskId}` : undefined;
4141
};
4242

4343
export const formatUptime = (seconds: number) => {
@@ -108,7 +108,7 @@ export const formatCPUWithLabel = (value?: number) => {
108108
};
109109

110110
export const formatDateTime = (value?: number | string) => {
111-
if (!isNumeric(value) || !value) {
111+
if (!isNumeric(value)) {
112112
return '';
113113
}
114114

@@ -124,5 +124,5 @@ export const calcUptimeInSeconds = (milliseconds: number | string) => {
124124
};
125125

126126
export const calcUptime = (milliseconds?: number | string) => {
127-
return milliseconds ? formatUptime(calcUptimeInSeconds(milliseconds)) : 'N/A';
127+
return formatUptime(calcUptimeInSeconds(Number(milliseconds)));
128128
};

0 commit comments

Comments
 (0)