@@ -3,7 +3,8 @@ import {Flex, Text} from '@gravity-ui/uikit';
33import { ResponseError } from '../../../components/Errors/ResponseError' ;
44import { Tags } from '../../../components/Tags' ;
55import type { ClusterGroupsStats } from '../../../store/reducers/cluster/types' ;
6- import type { TClusterInfo , TClusterInfoV2 } from '../../../types/api/cluster' ;
6+ import { isClusterInfoV2 } from '../../../types/api/cluster' ;
7+ import type { TClusterInfo } from '../../../types/api/cluster' ;
78import type { IResponseError } from '../../../types/api/error' ;
89import { valueIsDefined } from '../../../utils' ;
910import { formatNumber } from '../../../utils/dataFormatters/dataFormatters' ;
@@ -23,13 +24,6 @@ import {
2324
2425import './ClusterDashboard.scss' ;
2526
26- // fixed CPU calculation
27- export function isClusterInfoV5 ( info ?: TClusterInfo ) : info is TClusterInfoV2 {
28- return info
29- ? 'Version' in info && typeof info . Version === 'number' && info . Version >= 5
30- : false ;
31- }
32-
3327interface AmountProps {
3428 value ?: number | string ;
3529}
@@ -45,18 +39,14 @@ function Amount({value}: AmountProps) {
4539 ) ;
4640}
4741
48- interface ClusterDashboardProps < T = TClusterInfo > {
49- cluster : T ;
42+ interface ClusterDashboardProps {
43+ cluster : TClusterInfo ;
5044 groupStats ?: ClusterGroupsStats ;
5145 loading ?: boolean ;
5246 error ?: IResponseError | string ;
5347}
5448
5549export function ClusterDashboard ( { cluster, ...props } : ClusterDashboardProps ) {
56- const isSupportedClusterResponse = isClusterInfoV5 ( cluster ) ;
57- if ( ! isSupportedClusterResponse ) {
58- return null ;
59- }
6050 if ( props . error ) {
6151 return < ResponseError error = { props . error } className = { b ( 'error' ) } /> ;
6252 }
@@ -74,15 +64,19 @@ export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) {
7464 ) ;
7565}
7666
77- function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps < TClusterInfoV2 > ) {
67+ function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps ) {
7868 if ( loading ) {
7969 return < ClusterDashboardSkeleton /> ;
8070 }
8171 const metricsCards = [ ] ;
82- const { CoresUsed, NumberOfCpus, CoresTotal} = cluster ;
83- const total = CoresTotal ?? NumberOfCpus ;
84- if ( valueIsDefined ( CoresUsed ) && valueIsDefined ( total ) ) {
85- metricsCards . push ( < ClusterMetricsCores value = { CoresUsed } capacity = { total } key = "cores" /> ) ;
72+ if ( isClusterInfoV2 ( cluster ) ) {
73+ const { CoresUsed, NumberOfCpus, CoresTotal} = cluster ;
74+ const total = CoresTotal ?? NumberOfCpus ;
75+ if ( valueIsDefined ( CoresUsed ) && valueIsDefined ( total ) ) {
76+ metricsCards . push (
77+ < ClusterMetricsCores value = { CoresUsed } capacity = { total } key = "cores" /> ,
78+ ) ;
79+ }
8680 }
8781 const { StorageTotal, StorageUsed} = cluster ;
8882 if ( valueIsDefined ( StorageTotal ) && valueIsDefined ( StorageUsed ) ) {
0 commit comments