Skip to content

Commit 7811347

Browse files
authored
fix(Cluster): use /capabilities to show dashboard (#1556)
1 parent 630ccc1 commit 7811347

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

src/containers/Cluster/Cluster.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {AutoRefreshControl} from '../../components/AutoRefreshControl/AutoRefres
99
import {EntityStatus} from '../../components/EntityStatus/EntityStatus';
1010
import {InternalLink} from '../../components/InternalLink';
1111
import routes, {getLocationObjectFromHref} from '../../routes';
12+
import {useClusterDashboardAvailable} from '../../store/reducers/capabilities/hooks';
1213
import {
1314
clusterApi,
1415
selectClusterTabletsWithFqdn,
@@ -54,6 +55,7 @@ export function Cluster({
5455
additionalVersionsProps,
5556
}: ClusterProps) {
5657
const container = React.useRef<HTMLDivElement>(null);
58+
const isClusterDashboardAvailable = useClusterDashboardAvailable();
5759

5860
const dispatch = useTypedDispatch();
5961

@@ -123,12 +125,14 @@ export function Cluster({
123125
<div className={b('sticky-wrapper')}>
124126
<AutoRefreshControl className={b('auto-refresh-control')} />
125127
</div>
126-
<ClusterDashboard
127-
cluster={cluster}
128-
groupStats={groupsStats}
129-
loading={infoLoading}
130-
error={clusterError || cluster?.error}
131-
/>
128+
{isClusterDashboardAvailable && (
129+
<ClusterDashboard
130+
cluster={cluster}
131+
groupStats={groupsStats}
132+
loading={infoLoading}
133+
error={clusterError || cluster?.error}
134+
/>
135+
)}
132136
<div className={b('tabs-sticky-wrapper')}>
133137
<Tabs
134138
size="l"

src/containers/Cluster/ClusterDashboard/ClusterDashboard.tsx

+13-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {Flex, Text} from '@gravity-ui/uikit';
33
import {ResponseError} from '../../../components/Errors/ResponseError';
44
import {Tags} from '../../../components/Tags';
55
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';
78
import type {IResponseError} from '../../../types/api/error';
89
import {valueIsDefined} from '../../../utils';
910
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
@@ -23,13 +24,6 @@ import {
2324

2425
import './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-
3327
interface 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

5549
export 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)) {

src/store/reducers/capabilities/hooks.ts

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ export const useViewerNodesHandlerHasGrouping = () => {
4242
export const useFeatureFlagsAvailable = () => {
4343
return useGetFeatureVersion('/viewer/feature_flags') > 1;
4444
};
45+
export const useClusterDashboardAvailable = () => {
46+
return useGetFeatureVersion('/viewer/cluster') > 4;
47+
};

src/types/api/capabilities.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export type Capability =
1212
| '/storage/groups'
1313
| '/viewer/query'
1414
| '/viewer/feature_flags'
15+
| '/viewer/cluster'
1516
| '/viewer/nodes';

0 commit comments

Comments
 (0)