1+ import { useMemo } from 'react' ;
2+
13import { Flex } from '@gravity-ui/uikit' ;
24import { Link , useLocation } from 'react-router-dom' ;
35
@@ -10,7 +12,7 @@ import type {
1012 TenantStorageStats ,
1113} from '../../../../../store/reducers/tenants/utils' ;
1214import { cn } from '../../../../../utils/cn' ;
13- import { SHOW_NETWORK_UTILIZATION } from '../../../../../utils/constants' ;
15+ import { NON_BREAKING_SPACE , SHOW_NETWORK_UTILIZATION } from '../../../../../utils/constants' ;
1416import { useSetting , useTypedSelector } from '../../../../../utils/hooks' ;
1517import { calculateMetricAggregates } from '../../../../../utils/metrics' ;
1618import {
@@ -26,6 +28,10 @@ import './MetricsTabs.scss';
2628
2729const b = cn ( 'tenant-metrics-tabs' ) ;
2830
31+ // Placeholder values used for serverless layout filler cards
32+ const PLACEHOLDER_VALUE = 0 ;
33+ const PLACEHOLDER_LIMIT = 1 ;
34+
2935interface MetricsTabsProps {
3036 poolsCpuStats ?: TenantPoolsStats [ ] ;
3137 memoryStats ?: TenantMetricStats [ ] ;
@@ -71,21 +77,29 @@ export function MetricsTabs({
7177 } ;
7278
7379 // Use only pools that directly indicate resources available to perform user queries
74- const cpuPools = ( poolsCpuStats || [ ] ) . filter (
75- ( pool ) => ! ( pool . name === 'Batch' || pool . name === 'IO' ) ,
80+ const cpuPools = useMemo (
81+ ( ) =>
82+ ( poolsCpuStats || [ ] ) . filter ( ( pool ) => ! ( pool . name === 'Batch' || pool . name === 'IO' ) ) ,
83+ [ poolsCpuStats ] ,
7684 ) ;
77- const cpuMetrics = calculateMetricAggregates ( cpuPools ) ;
85+ const cpuMetrics = useMemo ( ( ) => calculateMetricAggregates ( cpuPools ) , [ cpuPools ] ) ;
7886
7987 // Calculate storage metrics using utility
80- const storageStats = tabletStorageStats || blobStorageStats || [ ] ;
81- const storageMetrics = calculateMetricAggregates ( storageStats ) ;
88+ const storageStats = useMemo (
89+ ( ) => tabletStorageStats || blobStorageStats || [ ] ,
90+ [ tabletStorageStats , blobStorageStats ] ,
91+ ) ;
92+ const storageMetrics = useMemo ( ( ) => calculateMetricAggregates ( storageStats ) , [ storageStats ] ) ;
8293
8394 // Calculate memory metrics using utility
84- const memoryMetrics = calculateMetricAggregates ( memoryStats ) ;
95+ const memoryMetrics = useMemo ( ( ) => calculateMetricAggregates ( memoryStats ) , [ memoryStats ] ) ;
8596
8697 // Calculate network metrics using utility
8798 const [ showNetworkUtilization ] = useSetting < boolean > ( SHOW_NETWORK_UTILIZATION ) ;
88- const networkMetrics = networkStats ? calculateMetricAggregates ( networkStats ) : null ;
99+ const networkMetrics = useMemo (
100+ ( ) => ( networkStats ? calculateMetricAggregates ( networkStats ) : null ) ,
101+ [ networkStats ] ,
102+ ) ;
89103
90104 const active = activeTab ?? metricsTab ;
91105
@@ -181,26 +195,26 @@ export function MetricsTabs({
181195 < div className = { b ( 'link-container' , { placeholder : true } ) } >
182196 < div className = { b ( 'link' ) } >
183197 < TabCard
184- text = { '\u00A0' }
185- value = { 0 }
186- limit = { 1 }
198+ text = { NON_BREAKING_SPACE }
199+ value = { PLACEHOLDER_VALUE }
200+ limit = { PLACEHOLDER_LIMIT }
187201 legendFormatter = { formatCoresLegend }
188202 active = { false }
189203 variant = { isServerless ? 'serverless' : 'default' }
190- subtitle = { '\u00A0' }
204+ subtitle = { NON_BREAKING_SPACE }
191205 />
192206 </ div >
193207 </ div >
194208 < div className = { b ( 'link-container' , { placeholder : true } ) } >
195209 < div className = { b ( 'link' ) } >
196210 < TabCard
197- text = { '\u00A0' }
198- value = { 0 }
199- limit = { 1 }
211+ text = { NON_BREAKING_SPACE }
212+ value = { PLACEHOLDER_VALUE }
213+ limit = { PLACEHOLDER_LIMIT }
200214 legendFormatter = { formatCoresLegend }
201215 active = { false }
202216 variant = { isServerless ? 'serverless' : 'default' }
203- subtitle = { '\u00A0' }
217+ subtitle = { NON_BREAKING_SPACE }
204218 />
205219 </ div >
206220 </ div >
0 commit comments