Skip to content

Commit 3e348bb

Browse files
committed
fix: better code
1 parent 08b44f0 commit 3e348bb

File tree

3 files changed

+2
-34
lines changed

3 files changed

+2
-34
lines changed

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import React from 'react';
33
import {Flex, Progress, Text} from '@gravity-ui/uikit';
44

55
import type {FormatProgressViewerValues} from '../../../../../components/ProgressViewer/ProgressViewer';
6-
import {cn} from '../../../../../utils/cn';
76
import {isNumeric, safeParseNumber} from '../../../../../utils/utils';
87

98
import {DEFAULT_PROGRESS_WIDTH, MAX_PERCENTAGE, MIN_PERCENTAGE, PROGRESS_SIZES} from './constants';
109
import i18n from './i18n';
1110

12-
import './ProgressWrapper.scss';
13-
1411
interface ProgressWrapperProps {
1512
value?: number | string;
1613
capacity?: number | string;
@@ -24,8 +21,6 @@ const defaultFormatValues: FormatProgressViewerValues = (value, total) => {
2421
return [value, total];
2522
};
2623

27-
const b = cn('progress-wrapper');
28-
2924
export function ProgressWrapper({
3025
value,
3126
capacity,
@@ -34,15 +29,13 @@ export function ProgressWrapper({
3429
className,
3530
width = DEFAULT_PROGRESS_WIDTH,
3631
}: ProgressWrapperProps) {
37-
// Input validation and error handling
3832
if (!isNumeric(value)) {
3933
return <div className={className}>{i18n('alert_no-data')}</div>;
4034
}
4135

4236
const numericValue = safeParseNumber(value);
4337
const numericCapacity = safeParseNumber(capacity);
4438

45-
// Handle edge cases: negative values, zero capacity
4639
if (numericValue < 0) {
4740
return <div className={className}>{i18n('alert_no-data')}</div>;
4841
}
@@ -51,38 +44,30 @@ export function ProgressWrapper({
5144
return <div className={className}>{i18n('alert_no-data')}</div>;
5245
}
5346

54-
// Calculate percentage for uikit Progress with proper bounds checking
5547
const rawPercentage = Math.floor((numericValue / numericCapacity) * MAX_PERCENTAGE);
5648
const fillWidth = Math.max(MIN_PERCENTAGE, rawPercentage);
5749
const clampedFillWidth = Math.min(fillWidth, MAX_PERCENTAGE);
5850

59-
// Get formatted display text - match original ProgressViewer exactly
6051
const [valueText, capacityText] = React.useMemo(() => {
6152
if (formatValues) {
6253
return formatValues(Number(value), Number(capacity));
6354
}
6455
return [value, capacity];
6556
}, [formatValues, value, capacity]);
6657

67-
// For storage variant, we always use the Figma green color regardless of colorizeProgress
68-
// This matches the original ProgressViewer behavior for storage size
69-
70-
// Memoize display text to avoid unnecessary recalculations
7158
const displayText = React.useMemo(() => {
7259
if (!isNumeric(numericCapacity) || numericCapacity <= 0) {
7360
return String(valueText);
7461
}
7562
return i18n('value_of_capacity', {value: valueText, capacity: capacityText});
7663
}, [valueText, capacityText, numericCapacity]);
7764

78-
// Validate width prop
7965
const validatedWidth = Math.max(0, width);
8066

81-
// For storage variant, use Flex layout similar to current ProgressViewer
8267
if (size === 'storage') {
8368
return (
8469
<Flex alignItems="center" gap="2" className={className}>
85-
<div className={b('storage-progress')} style={{width: `${validatedWidth}px`}}>
70+
<div style={{width: `${validatedWidth}px`}}>
8671
<Progress
8772
value={clampedFillWidth}
8873
theme="success"
@@ -96,7 +81,6 @@ export function ProgressWrapper({
9681
);
9782
}
9883

99-
// Default layout (though we're only using storage variant for now)
10084
return (
10185
<div className={className}>
10286
<Progress value={clampedFillWidth} text={displayText} size={PROGRESS_SIZES.DEFAULT} />
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// Progress wrapper constants following project patterns
21
export const DEFAULT_PROGRESS_WIDTH = 400;
3-
export const PROGRESS_HEIGHT = 10;
42
export const MAX_PERCENTAGE = 100;
53
export const MIN_PERCENTAGE = 0;
64

7-
// Progress size mappings for uikit Progress component
85
export const PROGRESS_SIZES = {
9-
STORAGE: 'xs',
6+
STORAGE: 's',
107
DEFAULT: 'm',
118
} as const;

0 commit comments

Comments
 (0)