11import { useMemo } from 'react' ;
22
33import { Flex } from '@gravity-ui/uikit' ;
4- import { Link , useLocation } from 'react-router-dom' ;
4+ import { useLocation } from 'react-router-dom' ;
55
66import { parseQuery } from '../../../../../routes' ;
77import { TENANT_METRICS_TABS_IDS } from '../../../../../store/reducers/tenant/constants' ;
@@ -11,19 +11,16 @@ import type {
1111 TenantPoolsStats ,
1212 TenantStorageStats ,
1313} from '../../../../../store/reducers/tenants/utils' ;
14+ import type { ETenantType } from '../../../../../types/api/tenant' ;
1415import { cn } from '../../../../../utils/cn' ;
1516import { SHOW_NETWORK_UTILIZATION } from '../../../../../utils/constants' ;
1617import { useSetting } from '../../../../../utils/hooks' ;
1718import { calculateMetricAggregates } from '../../../../../utils/metrics' ;
18- import {
19- formatCoresLegend ,
20- formatSpeedLegend ,
21- formatStorageLegend ,
22- } from '../../../../../utils/metrics/formatMetricLegend' ;
19+ // no direct legend formatters needed here – handled in subcomponents
2320import { TenantTabsGroups , getTenantPath } from '../../../TenantPages' ;
24- import { TabCard } from '../TabCard/TabCard' ;
25- import i18n from '../i18n' ;
2621
22+ import { CommonMetricsTabs } from './CommonMetricsTabs' ;
23+ import { DedicatedMetricsTabs } from './DedicatedMetricsTabs' ;
2724import { ServerlessPlaceholderTabs } from './ServerlessPlaceholderTabs' ;
2825
2926import './MetricsTabs.scss' ;
@@ -37,7 +34,7 @@ interface MetricsTabsProps {
3734 tabletStorageStats ?: TenantStorageStats [ ] ;
3835 networkStats ?: TenantMetricStats [ ] ;
3936 storageGroupsCount ?: number ;
40- isServerless ?: boolean ;
37+ databaseType ?: ETenantType ;
4138 activeTab : TenantMetricsTab ;
4239}
4340
@@ -48,7 +45,7 @@ export function MetricsTabs({
4845 tabletStorageStats,
4946 networkStats,
5047 storageGroupsCount,
51- isServerless ,
48+ databaseType ,
5249 activeTab,
5350} : MetricsTabsProps ) {
5451 const location = useLocation ( ) ;
@@ -98,99 +95,36 @@ export function MetricsTabs({
9895 [ networkStats ] ,
9996 ) ;
10097
101- const cardVariant = isServerless ? 'serverless' : 'default' ;
98+ // card variant is handled within subcomponents
99+
100+ const isServerless = databaseType === 'Serverless' ;
102101
103102 return (
104103 < Flex className = { b ( { serverless : Boolean ( isServerless ) } ) } alignItems = "center" >
105- < div
106- className = { b ( 'link-container' , {
107- active : activeTab === TENANT_METRICS_TABS_IDS . cpu ,
108- } ) }
109- >
110- < Link to = { tabLinks . cpu } className = { b ( 'link' ) } >
111- < TabCard
112- text = { i18n ( 'context_cpu-load' ) }
113- value = { cpuMetrics . totalUsed }
114- limit = { cpuMetrics . totalLimit }
115- legendFormatter = { formatCoresLegend }
116- active = { activeTab === TENANT_METRICS_TABS_IDS . cpu }
117- helpText = { i18n ( 'context_cpu-description' ) }
118- variant = { cardVariant }
119- subtitle = { isServerless ? i18n ( 'context_serverless-autoscaled' ) : undefined }
120- />
121- </ Link >
122- </ div >
123- < div
124- className = { b ( 'link-container' , {
125- active : activeTab === TENANT_METRICS_TABS_IDS . storage ,
126- } ) }
127- >
128- < Link to = { tabLinks . storage } className = { b ( 'link' ) } >
129- < TabCard
130- text = {
131- storageGroupsCount === undefined || isServerless
132- ? i18n ( 'cards.storage-label' )
133- : i18n ( 'context_storage-groups' , { count : storageGroupsCount } )
134- }
135- value = { storageMetrics . totalUsed }
136- limit = { storageMetrics . totalLimit }
137- legendFormatter = { formatStorageLegend }
138- active = { activeTab === TENANT_METRICS_TABS_IDS . storage }
139- helpText = { i18n ( 'context_storage-description' ) }
140- variant = { cardVariant }
141- subtitle = {
142- isServerless && storageMetrics . totalLimit
143- ? i18n ( 'context_serverless-storage-subtitle' , {
144- groups : String ( storageGroupsCount ?? 0 ) ,
145- legend : formatStorageLegend ( {
146- value : storageMetrics . totalUsed ,
147- capacity : storageMetrics . totalLimit ,
148- } ) ,
149- } )
150- : undefined
151- }
152- />
153- </ Link >
154- </ div >
104+ < CommonMetricsTabs
105+ activeTab = { activeTab }
106+ tabLinks = { tabLinks }
107+ cpu = { { totalUsed : cpuMetrics . totalUsed , totalLimit : cpuMetrics . totalLimit } }
108+ storage = { {
109+ totalUsed : storageMetrics . totalUsed ,
110+ totalLimit : storageMetrics . totalLimit ,
111+ } }
112+ storageGroupsCount = { storageGroupsCount }
113+ databaseType = { databaseType }
114+ />
155115 { isServerless ? (
156116 < ServerlessPlaceholderTabs />
157117 ) : (
158- < >
159- < div
160- className = { b ( 'link-container' , {
161- active : activeTab === TENANT_METRICS_TABS_IDS . memory ,
162- } ) }
163- >
164- < Link to = { tabLinks . memory } className = { b ( 'link' ) } >
165- < TabCard
166- text = { i18n ( 'context_memory-used' ) }
167- value = { memoryMetrics . totalUsed }
168- limit = { memoryMetrics . totalLimit }
169- legendFormatter = { formatStorageLegend }
170- active = { activeTab === TENANT_METRICS_TABS_IDS . memory }
171- helpText = { i18n ( 'context_memory-description' ) }
172- />
173- </ Link >
174- </ div >
175- { showNetworkUtilization && networkStats && networkMetrics && (
176- < div
177- className = { b ( 'link-container' , {
178- active : activeTab === TENANT_METRICS_TABS_IDS . network ,
179- } ) }
180- >
181- < Link to = { tabLinks . network } className = { b ( 'link' ) } >
182- < TabCard
183- text = { i18n ( 'context_network-usage' ) }
184- value = { networkMetrics . totalUsed }
185- limit = { networkMetrics . totalLimit }
186- legendFormatter = { formatSpeedLegend }
187- active = { activeTab === TENANT_METRICS_TABS_IDS . network }
188- helpText = { i18n ( 'context_network-description' ) }
189- />
190- </ Link >
191- </ div >
192- ) }
193- </ >
118+ < DedicatedMetricsTabs
119+ activeTab = { activeTab }
120+ tabLinks = { tabLinks }
121+ memory = { {
122+ totalUsed : memoryMetrics . totalUsed ,
123+ totalLimit : memoryMetrics . totalLimit ,
124+ } }
125+ network = { networkMetrics }
126+ showNetwork = { Boolean ( showNetworkUtilization && networkStats && networkMetrics ) }
127+ />
194128 ) }
195129 </ Flex >
196130 ) ;
0 commit comments