From e83645a49c2563954f59836880f774aa78c4893e Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Tue, 29 Oct 2024 17:48:21 +0300 Subject: [PATCH] fix(Cluster): use /capabilities to show dashboard --- src/containers/Cluster/Cluster.tsx | 16 ++++++---- .../ClusterDashboard/ClusterDashboard.tsx | 32 ++++++++----------- src/store/reducers/capabilities/hooks.ts | 3 ++ src/types/api/capabilities.ts | 1 + 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/containers/Cluster/Cluster.tsx b/src/containers/Cluster/Cluster.tsx index 83b3ccf69..81105958f 100644 --- a/src/containers/Cluster/Cluster.tsx +++ b/src/containers/Cluster/Cluster.tsx @@ -9,6 +9,7 @@ import {AutoRefreshControl} from '../../components/AutoRefreshControl/AutoRefres import {EntityStatus} from '../../components/EntityStatus/EntityStatus'; import {InternalLink} from '../../components/InternalLink'; import routes, {getLocationObjectFromHref} from '../../routes'; +import {useClusterDashboardAvailable} from '../../store/reducers/capabilities/hooks'; import { clusterApi, selectClusterTabletsWithFqdn, @@ -54,6 +55,7 @@ export function Cluster({ additionalVersionsProps, }: ClusterProps) { const container = React.useRef(null); + const isClusterDashboardAvailable = useClusterDashboardAvailable(); const dispatch = useTypedDispatch(); @@ -123,12 +125,14 @@ export function Cluster({
- + {isClusterDashboardAvailable && ( + + )}
= 5 - : false; -} - interface AmountProps { value?: number | string; } @@ -45,18 +39,14 @@ function Amount({value}: AmountProps) { ); } -interface ClusterDashboardProps { - cluster: T; +interface ClusterDashboardProps { + cluster: TClusterInfo; groupStats?: ClusterGroupsStats; loading?: boolean; error?: IResponseError | string; } export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) { - const isSupportedClusterResponse = isClusterInfoV5(cluster); - if (!isSupportedClusterResponse) { - return null; - } if (props.error) { return ; } @@ -74,15 +64,19 @@ export function ClusterDashboard({cluster, ...props}: ClusterDashboardProps) { ); } -function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps) { +function ClusterDoughnuts({cluster, loading}: ClusterDashboardProps) { if (loading) { return ; } const metricsCards = []; - const {CoresUsed, NumberOfCpus, CoresTotal} = cluster; - const total = CoresTotal ?? NumberOfCpus; - if (valueIsDefined(CoresUsed) && valueIsDefined(total)) { - metricsCards.push(); + if (isClusterInfoV2(cluster)) { + const {CoresUsed, NumberOfCpus, CoresTotal} = cluster; + const total = CoresTotal ?? NumberOfCpus; + if (valueIsDefined(CoresUsed) && valueIsDefined(total)) { + metricsCards.push( + , + ); + } } const {StorageTotal, StorageUsed} = cluster; if (valueIsDefined(StorageTotal) && valueIsDefined(StorageUsed)) { diff --git a/src/store/reducers/capabilities/hooks.ts b/src/store/reducers/capabilities/hooks.ts index 321d5a413..2ee301f81 100644 --- a/src/store/reducers/capabilities/hooks.ts +++ b/src/store/reducers/capabilities/hooks.ts @@ -42,3 +42,6 @@ export const useViewerNodesHandlerHasGrouping = () => { export const useFeatureFlagsAvailable = () => { return useGetFeatureVersion('/viewer/feature_flags') > 1; }; +export const useClusterDashboardAvailable = () => { + return useGetFeatureVersion('/viewer/cluster') > 4; +}; diff --git a/src/types/api/capabilities.ts b/src/types/api/capabilities.ts index 36b829acb..cb40134f9 100644 --- a/src/types/api/capabilities.ts +++ b/src/types/api/capabilities.ts @@ -12,4 +12,5 @@ export type Capability = | '/storage/groups' | '/viewer/query' | '/viewer/feature_flags' + | '/viewer/cluster' | '/viewer/nodes';