@@ -3,8 +3,7 @@ import {Flex, Text} from '@gravity-ui/uikit';
3
3
import { ResponseError } from '../../../components/Errors/ResponseError' ;
4
4
import { Tags } from '../../../components/Tags' ;
5
5
import 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' ;
8
7
import type { IResponseError } from '../../../types/api/error' ;
9
8
import { valueIsDefined } from '../../../utils' ;
10
9
import { formatNumber } from '../../../utils/dataFormatters/dataFormatters' ;
@@ -24,6 +23,13 @@ import {
24
23
25
24
import './ClusterDashboard.scss' ;
26
25
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
+
27
33
interface AmountProps {
28
34
value ?: number | string ;
29
35
}
@@ -39,43 +45,44 @@ function Amount({value}: AmountProps) {
39
45
) ;
40
46
}
41
47
42
- interface ClusterDashboardProps {
43
- cluster : TClusterInfo ;
48
+ interface ClusterDashboardProps < T = TClusterInfo > {
49
+ cluster : T ;
44
50
groupStats ?: ClusterGroupsStats ;
45
51
loading ?: boolean ;
46
52
error ?: IResponseError | string ;
47
53
}
48
54
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
+ }
50
60
if ( props . error ) {
51
61
return < ResponseError error = { props . error } className = { b ( 'error' ) } /> ;
52
62
}
53
63
return (
54
64
< div className = { b ( ) } >
55
65
< Flex gap = { 4 } wrap >
56
66
< Flex gap = { 4 } wrap = "nowrap" >
57
- < ClusterDoughnuts { ...props } />
67
+ < ClusterDoughnuts { ...props } cluster = { cluster } />
58
68
</ Flex >
59
69
< div className = { b ( 'cards-container' ) } >
60
- < ClusterDashboardCards { ...props } />
70
+ < ClusterDashboardCards { ...props } cluster = { cluster } />
61
71
</ div >
62
72
</ Flex >
63
73
</ div >
64
74
) ;
65
75
}
66
76
67
- function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps ) {
77
+ function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps < TClusterInfoV2 > ) {
68
78
if ( loading ) {
69
79
return < ClusterDashboardSkeleton /> ;
70
80
}
71
81
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" /> ) ;
79
86
}
80
87
const { StorageTotal, StorageUsed} = cluster ;
81
88
if ( valueIsDefined ( StorageTotal ) && valueIsDefined ( StorageUsed ) ) {
0 commit comments