Skip to content

Commit 80c59ae

Browse files
committed
fix: more explicit code
1 parent 1ffd9e7 commit 80c59ae

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/containers/Tenant/Diagnostics/TenantOverview/MetricsCards/MetricsCards.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {cn} from '../../../../../utils/cn';
1313
import {SHOW_NETWORK_UTILIZATION} from '../../../../../utils/constants';
1414
import {useSetting, useTypedSelector} from '../../../../../utils/hooks';
1515
import {calculateMetricAggregates} from '../../../../../utils/metrics';
16+
import {
17+
formatCoresLegend,
18+
formatStorageLegend,
19+
} from '../../../../../utils/metrics/formatMetricLegend';
1620
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
1721
import {TabCard} from '../TabCard/TabCard';
1822
import i18n from '../i18n';
@@ -86,7 +90,7 @@ export function MetricsCards({
8690
sublabel={i18n('context_cpu-load')}
8791
value={cpuMetrics.totalUsed}
8892
limit={cpuMetrics.totalLimit}
89-
unit="cores"
93+
legendFormatter={formatCoresLegend}
9094
active={metricsTab === TENANT_METRICS_TABS_IDS.cpu}
9195
helpText={i18n('context_cpu-description')}
9296
/>
@@ -103,7 +107,7 @@ export function MetricsCards({
103107
sublabel={i18n('context_storage-groups', {count: storageGroupCount})}
104108
value={storageMetrics.totalUsed}
105109
limit={storageMetrics.totalLimit}
106-
unit="bytes"
110+
legendFormatter={formatStorageLegend}
107111
active={metricsTab === TENANT_METRICS_TABS_IDS.storage}
108112
helpText={i18n('context_storage-description')}
109113
/>
@@ -120,7 +124,7 @@ export function MetricsCards({
120124
sublabel={i18n('context_memory-used')}
121125
value={memoryMetrics.totalUsed}
122126
limit={memoryMetrics.totalLimit}
123-
unit="bytes"
127+
legendFormatter={formatStorageLegend}
124128
active={metricsTab === TENANT_METRICS_TABS_IDS.memory}
125129
helpText={i18n('context_memory-description')}
126130
/>
@@ -134,7 +138,7 @@ export function MetricsCards({
134138
sublabel={i18n('context_network-evaluation')}
135139
value={networkMetrics.totalUsed}
136140
limit={networkMetrics.totalLimit}
137-
unit="bytes"
141+
legendFormatter={formatStorageLegend}
138142
active={false}
139143
clickable={false}
140144
helpText={i18n('context_network-description')}

src/containers/Tenant/Diagnostics/TenantOverview/TabCard/TabCard.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import {Card, Flex} from '@gravity-ui/uikit';
33
import {DoughnutMetrics} from '../../../../../components/DoughnutMetrics/DoughnutMetrics';
44
import {getDiagramValues} from '../../../../../containers/Cluster/ClusterOverview/utils';
55
import {cn} from '../../../../../utils/cn';
6-
import {
7-
formatCoresLegend,
8-
formatStorageLegend,
9-
} from '../../../../../utils/metrics/formatMetricLegend';
106

117
import './TabCard.scss';
128

@@ -17,24 +13,22 @@ interface TabCardProps {
1713
sublabel?: string;
1814
value: number;
1915
limit: number;
20-
unit: 'bytes' | 'cores';
2116
active?: boolean;
2217
helpText?: string;
2318
clickable?: boolean;
19+
legendFormatter: (params: {value: number; capacity: number}) => string;
2420
}
2521

2622
export function TabCard({
2723
label,
2824
sublabel,
2925
value,
3026
limit,
31-
unit,
3227
active,
3328
helpText,
3429
clickable = true,
30+
legendFormatter,
3531
}: TabCardProps) {
36-
const legendFormatter = unit === 'bytes' ? formatStorageLegend : formatCoresLegend;
37-
3832
const {status, percents, legend, fill} = getDiagramValues({
3933
value,
4034
capacity: limit,

0 commit comments

Comments
 (0)