@@ -3,7 +3,8 @@ 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 type { TClusterInfo , TClusterInfoV2 } from '../../../types/api/cluster' ;
6
+ import { isClusterInfoV2 } from '../../../types/api/cluster' ;
7
+ import type { TClusterInfo } from '../../../types/api/cluster' ;
7
8
import type { IResponseError } from '../../../types/api/error' ;
8
9
import { valueIsDefined } from '../../../utils' ;
9
10
import { formatNumber } from '../../../utils/dataFormatters/dataFormatters' ;
@@ -23,13 +24,6 @@ import {
23
24
24
25
import './ClusterDashboard.scss' ;
25
26
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
-
33
27
interface AmountProps {
34
28
value ?: number | string ;
35
29
}
@@ -45,18 +39,14 @@ function Amount({value}: AmountProps) {
45
39
) ;
46
40
}
47
41
48
- interface ClusterDashboardProps < T = TClusterInfo > {
49
- cluster : T ;
42
+ interface ClusterDashboardProps {
43
+ cluster : TClusterInfo ;
50
44
groupStats ?: ClusterGroupsStats ;
51
45
loading ?: boolean ;
52
46
error ?: IResponseError | string ;
53
47
}
54
48
55
49
export function ClusterDashboard ( { cluster, ...props } : ClusterDashboardProps ) {
56
- const isSupportedClusterResponse = isClusterInfoV5 ( cluster ) ;
57
- if ( ! isSupportedClusterResponse ) {
58
- return null ;
59
- }
60
50
if ( props . error ) {
61
51
return < ResponseError error = { props . error } className = { b ( 'error' ) } /> ;
62
52
}
@@ -74,15 +64,19 @@ export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) {
74
64
) ;
75
65
}
76
66
77
- function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps < TClusterInfoV2 > ) {
67
+ function ClusterDoughnuts ( { cluster, loading} : ClusterDashboardProps ) {
78
68
if ( loading ) {
79
69
return < ClusterDashboardSkeleton /> ;
80
70
}
81
71
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
+ }
86
80
}
87
81
const { StorageTotal, StorageUsed} = cluster ;
88
82
if ( valueIsDefined ( StorageTotal ) && valueIsDefined ( StorageUsed ) ) {
0 commit comments