@@ -3,8 +3,7 @@ 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 { isClusterInfoV2 } from '../../../types/api/cluster' ;
7- import type { TClusterInfo } from '../../../types/api/cluster' ;
6+ import type { TClusterInfo , TClusterInfoV2 } from '../../../types/api/cluster' ;
87import type { IResponseError } from '../../../types/api/error' ;
98import { valueIsDefined } from '../../../utils' ;
109import { formatNumber } from '../../../utils/dataFormatters/dataFormatters' ;
@@ -24,6 +23,13 @@ import {
2423
2524import './ClusterDashboard.scss' ;
2625
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+
2733interface AmountProps {
2834 value ?: number | string ;
2935}
@@ -39,43 +45,44 @@ function Amount({value}: AmountProps) {
3945 ) ;
4046}
4147
42- interface ClusterDashboardProps {
43- cluster : TClusterInfo ;
48+ interface ClusterDashboardProps < T = TClusterInfo > {
49+ cluster : T ;
4450 groupStats ?: ClusterGroupsStats ;
4551 loading ?: boolean ;
4652 error ?: IResponseError | string ;
4753}
4854
49- export function ClusterDashboard ( props : ClusterDashboardProps ) {
55+ export function ClusterDashboard ( { cluster, ...props } : ClusterDashboardProps ) {
56+ const isSupportedClusterResponse = isClusterInfoV5 ( cluster ) ;
57+ if ( ! isSupportedClusterResponse ) {
58+ return null ;
59+ }
5060 if ( props . error ) {
5161 return < ResponseError error = { props . error } className = { b ( 'error' ) } /> ;
5262 }
5363 return (
5464 < div className = { b ( ) } >
5565 < Flex gap = { 4 } wrap >
5666 < Flex gap = { 4 } wrap = "nowrap" >
57- < ClusterDoughnuts { ...props } />
67+ < ClusterDoughnuts { ...props } cluster = { cluster } />
5868 </ Flex >
5969 < div className = { b ( 'cards-container' ) } >
60- < ClusterDashboardCards { ...props } />
70+ < ClusterDashboardCards { ...props } cluster = { cluster } />
6171 </ div >
6272 </ Flex >
6373 </ div >
6474 ) ;
6575}
6676
67- function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps ) {
77+ function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps < TClusterInfoV2 > ) {
6878 if ( loading ) {
6979 return < ClusterDashboardSkeleton /> ;
7080 }
7181 const metricsCards = [ ] ;
72- if ( isClusterInfoV2 ( cluster ) ) {
73- const { CoresUsed, NumberOfCpus} = cluster ;
74- if ( valueIsDefined ( CoresUsed ) && valueIsDefined ( NumberOfCpus ) ) {
75- metricsCards . push (
76- < ClusterMetricsCores value = { CoresUsed } capacity = { NumberOfCpus } key = "cores" /> ,
77- ) ;
78- }
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" /> ) ;
7986 }
8087 const { StorageTotal, StorageUsed} = cluster ;
8188 if ( valueIsDefined ( StorageTotal ) && valueIsDefined ( StorageUsed ) ) {
0 commit comments