diff --git a/src/components/NodeHostWrapper/NodeHostWrapper.tsx b/src/components/NodeHostWrapper/NodeHostWrapper.tsx index 2a9e18d0db..6ddf3ca374 100644 --- a/src/components/NodeHostWrapper/NodeHostWrapper.tsx +++ b/src/components/NodeHostWrapper/NodeHostWrapper.tsx @@ -1,7 +1,7 @@ import {PopoverBehavior} from '@gravity-ui/uikit'; import {getDefaultNodePath} from '../../containers/Node/NodePages'; -import type {NodeAddress} from '../../types/additionalProps'; +import type {GetNodeRefFunc, NodeAddress} from '../../types/additionalProps'; import type {TNodeInfo, TSystemStateInfo} from '../../types/api/nodes'; import { createDeveloperUIInternalPageHref, @@ -23,7 +23,7 @@ export type StatusForIcon = 'SystemState' | 'ConnectStatus'; interface NodeHostWrapperProps { node: NodeHostData; - getNodeRef?: (node?: NodeAddress) => string | null; + getNodeRef?: GetNodeRefFunc; database?: string; statusForIcon?: StatusForIcon; } diff --git a/src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx b/src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx index 92c2fbdc81..e0d2969d1e 100644 --- a/src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx +++ b/src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx @@ -11,11 +11,14 @@ import type {MetaClusterVersion} from '../../../types/api/meta'; import type {ETenantType} from '../../../types/api/tenant'; import {getVersionColors, getVersionMap} from '../../../utils/clusterVersionColors'; import {cn} from '../../../utils/cn'; +import {USE_CLUSTER_BALANCER_AS_BACKEND_KEY} from '../../../utils/constants'; +import {useSetting} from '../../../utils/hooks'; +import {useAdditionalNodesProps} from '../../../utils/hooks/useAdditionalNodesProps'; import type {GetMonitoringClusterLink, GetMonitoringLink} from '../../../utils/monitoring'; import {getCleanBalancerValue, removeViewerPathname} from '../../../utils/parseBalancer'; import {getBackendFromNodeHost, getBackendFromRawNodeData} from '../../../utils/prepareBackend'; import type {Cluster} from '../../Cluster/Cluster'; -import {useClusterData} from '../useClusterData'; +import {useClusterVersions} from '../useClusterData'; import './ExtendedCluster.scss'; @@ -123,10 +126,12 @@ export function ExtendedCluster({ getMonitoringLink, getMonitoringClusterLink, }: ExtendedClusterProps) { - const {versions, useClusterBalancerAsBackend, additionalNodesProps} = useClusterData(); - + const versions = useClusterVersions(); + const additionalNodesProps = useAdditionalNodesProps(); const {name, balancer, monitoring} = useClusterBaseInfo(); + const [useClusterBalancerAsBackend] = useSetting(USE_CLUSTER_BALANCER_AS_BACKEND_KEY); + return (
{ diff --git a/src/containers/AppWithClusters/useClusterData.ts b/src/containers/AppWithClusters/useClusterData.ts index e8ff56c1d4..3d0368c956 100644 --- a/src/containers/AppWithClusters/useClusterData.ts +++ b/src/containers/AppWithClusters/useClusterData.ts @@ -3,34 +3,15 @@ import React from 'react'; import {StringParam, useQueryParam} from 'use-query-params'; import {clustersApi} from '../../store/reducers/clusters/clusters'; -import {getAdditionalNodesProps} from '../../utils/additionalProps'; -import {USE_CLUSTER_BALANCER_AS_BACKEND_KEY} from '../../utils/constants'; -import {useSetting} from '../../utils/hooks'; -export function useClusterData() { +export function useClusterVersions() { const [clusterName] = useQueryParam('clusterName', StringParam); const {data} = clustersApi.useGetClustersListQuery(undefined); - const info = React.useMemo(() => { + return React.useMemo(() => { const clusters = data || []; - return clusters.find((cluster) => cluster.name === clusterName); + const info = clusters.find((cluster) => cluster.name === clusterName); + return info?.versions; }, [data, clusterName]); - - const {solomon: monitoring, balancer, versions} = info || {}; - - return { - monitoring, - balancer, - versions, - ...useAdditionalNodeProps({balancer}), - }; -} - -export function useAdditionalNodeProps({balancer}: {balancer?: string}) { - const [useClusterBalancerAsBackend] = useSetting(USE_CLUSTER_BALANCER_AS_BACKEND_KEY); - - const additionalNodesProps = getAdditionalNodesProps(balancer, useClusterBalancerAsBackend); - - return {additionalNodesProps, useClusterBalancerAsBackend}; } diff --git a/src/containers/Cluster/Cluster.tsx b/src/containers/Cluster/Cluster.tsx index 5ca09c9cbc..888ef127ad 100644 --- a/src/containers/Cluster/Cluster.tsx +++ b/src/containers/Cluster/Cluster.tsx @@ -168,7 +168,6 @@ export function Cluster({ > { - const {balancer} = useClusterBaseInfo(); - const {additionalNodesProps} = useAdditionalNodeProps({balancer}); + const additionalNodesProps = useAdditionalNodesProps(); - const columns = getColumns({getNodeRef: additionalNodesProps.getNodeRef}); + const columns = getColumns({getNodeRef: additionalNodesProps?.getNodeRef}); return ( ; -export type GetNodeRefFunc = (node?: NodeAddress) => string | null; +export type GetNodeRefFunc = (node?: NodeAddress) => string | undefined; export interface AdditionalNodesProps extends Record { getNodeRef?: GetNodeRefFunc; diff --git a/src/utils/hooks/useAdditionalNodesProps.ts b/src/utils/hooks/useAdditionalNodesProps.ts new file mode 100644 index 0000000000..0015bc3ee5 --- /dev/null +++ b/src/utils/hooks/useAdditionalNodesProps.ts @@ -0,0 +1,17 @@ +import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster'; +import {getAdditionalNodesProps} from '../additionalProps'; +import {USE_CLUSTER_BALANCER_AS_BACKEND_KEY} from '../constants'; + +import {useSetting} from './useSetting'; +import {useTypedSelector} from './useTypedSelector'; + +/** For multi-cluster version */ +export function useAdditionalNodesProps() { + const {balancer} = useClusterBaseInfo(); + const [useClusterBalancerAsBackend] = useSetting(USE_CLUSTER_BALANCER_AS_BACKEND_KEY); + const singleClusterMode = useTypedSelector((state) => state.singleClusterMode); + + const additionalNodesProps = getAdditionalNodesProps(balancer, useClusterBalancerAsBackend); + + return singleClusterMode ? undefined : additionalNodesProps; +} diff --git a/src/utils/hooks/useNodeDeveloperUIHref.ts b/src/utils/hooks/useNodeDeveloperUIHref.ts index 868e1fce75..e21159bb2a 100644 --- a/src/utils/hooks/useNodeDeveloperUIHref.ts +++ b/src/utils/hooks/useNodeDeveloperUIHref.ts @@ -1,16 +1,14 @@ -import {useAdditionalNodeProps} from '../../containers/AppWithClusters/useClusterData'; -import {useClusterBaseInfo} from '../../store/reducers/cluster/cluster'; import type {PreparedNode} from '../../store/reducers/node/types'; import { createDeveloperUIInternalPageHref, createDeveloperUILinkWithNodeId, } from '../developerUI/developerUI'; +import {useAdditionalNodesProps} from './useAdditionalNodesProps'; import {useIsUserAllowedToMakeChanges} from './useIsUserAllowedToMakeChanges'; export function useNodeDeveloperUIHref(node?: PreparedNode) { - const {balancer} = useClusterBaseInfo(); - const {additionalNodesProps} = useAdditionalNodeProps({balancer}); + const additionalNodesProps = useAdditionalNodesProps(); const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges(); if (!isUserAllowedToMakeChanges) { diff --git a/src/utils/prepareBackend.ts b/src/utils/prepareBackend.ts index 04855f48ae..87ca7cded3 100644 --- a/src/utils/prepareBackend.ts +++ b/src/utils/prepareBackend.ts @@ -20,6 +20,7 @@ export const getBackendFromNodeHost = (nodeHost: string, balancer: string) => { return https + preparedHost; }; +/** For multi-cluster version */ export const getBackendFromRawNodeData = ( node: NodeAddress, balancer: string, @@ -36,7 +37,7 @@ export const getBackendFromRawNodeData = ( const nodePort = Endpoints.find((endpoint) => endpoint.Name === 'http-mon')?.Address; if (!nodePort || !Host) { - return null; + return undefined; } const hostWithPort = Host + nodePort; @@ -46,5 +47,5 @@ export const getBackendFromRawNodeData = ( return getBackendFromNodeHost(hostWithPort, balancer); } - return null; + return undefined; };