11import { ClipboardButton } from '@gravity-ui/uikit' ;
2- import { isNil } from 'lodash' ;
32
43import { useClusterBaseInfo } from '../../../store/reducers/cluster/cluster' ;
5- import type { AdditionalClusterProps , AdditionalTenantsProps } from '../../../types/additionalProps' ;
6- import type { ETenantType } from '../../../types/api/tenant ' ;
4+ import type { AdditionalClusterProps } from '../../../types/additionalProps' ;
5+ import type { GetClusterLinks , GetDatabaseLinks } from '../../../uiFactory/types ' ;
76import { cn } from '../../../utils/cn' ;
8- import { USE_CLUSTER_BALANCER_AS_BACKEND_KEY } from '../../../utils/constants' ;
9- import { useSetting } from '../../../utils/hooks' ;
107import { useAdditionalNodesProps } from '../../../utils/hooks/useAdditionalNodesProps' ;
118import type { GetLogsLink } from '../../../utils/logs' ;
129import type { GetMonitoringClusterLink , GetMonitoringLink } from '../../../utils/monitoring' ;
13- import { getCleanBalancerValue , prepareBackendFromBalancer } from '../../../utils/parseBalancer' ;
14- import { getBackendFromBalancerAndNodeId } from '../../../utils/prepareBackend' ;
10+ import { getCleanBalancerValue } from '../../../utils/parseBalancer' ;
1511import type { Cluster } from '../../Cluster/Cluster' ;
12+ import { useAdditionalTenantsProps } from '../utils/useAdditionalTenantsProps' ;
1613
1714import './ExtendedCluster.scss' ;
1815
@@ -33,133 +30,68 @@ const getAdditionalBalancerInfo = (balancer: string) => {
3330} ;
3431
3532interface GetAdditionalClusterProps {
36- clusterName : string | undefined ;
37- monitoring : string | undefined ;
38- balancer : string | undefined ;
3933 getMonitoringClusterLink ?: GetMonitoringClusterLink ;
34+ getClusterLinks ?: GetClusterLinks ;
4035}
4136
42- const getAdditionalClusterProps = ( {
43- clusterName,
44- monitoring,
45- balancer,
37+ const useAdditionalClusterProps = ( {
4638 getMonitoringClusterLink,
39+ getClusterLinks,
4740} : GetAdditionalClusterProps ) => {
48- const additionalClusterProps : AdditionalClusterProps = { } ;
41+ const clusterInfo = useClusterBaseInfo ( ) ;
42+ const { name : clusterName , balancer, monitoring} = clusterInfo ;
4943
44+ const additionalClusterProps : AdditionalClusterProps = { } ;
45+ additionalClusterProps . links = [ ] ;
5046 if ( monitoring && getMonitoringClusterLink ) {
5147 const clusterLink = getMonitoringClusterLink ( monitoring , clusterName ) ;
5248
5349 if ( clusterLink ) {
54- additionalClusterProps . links = [ { title : 'Monitoring' , url : clusterLink } ] ;
50+ additionalClusterProps . links . push ( { title : 'Monitoring' , url : clusterLink } ) ;
5551 }
5652 }
5753
54+ if ( getClusterLinks ) {
55+ const clusterLinks = getClusterLinks ( { clusterInfo} ) ;
56+ additionalClusterProps . links . push ( ...clusterLinks ) ;
57+ }
58+
5859 if ( balancer ) {
5960 additionalClusterProps . info = [ getAdditionalBalancerInfo ( balancer ) ] ;
6061 }
6162
6263 return additionalClusterProps ;
6364} ;
6465
65- interface GetAdditionalTenantsProps {
66- clusterName : string | undefined ;
67- monitoring : string | undefined ;
68- balancer : string | undefined ;
69- logging : string | undefined ;
70- useClusterBalancerAsBackend : boolean | undefined ;
71- getMonitoringLink ?: GetMonitoringLink ;
72- getLogsLink ?: GetLogsLink ;
73- }
74-
75- const getAdditionalTenantsProps = ( {
76- clusterName,
77- monitoring,
78- balancer,
79- logging,
80- useClusterBalancerAsBackend,
81- getMonitoringLink,
82- getLogsLink,
83- } : GetAdditionalTenantsProps ) => {
84- const additionalTenantsProps : AdditionalTenantsProps = { } ;
85-
86- additionalTenantsProps . prepareTenantBackend = ( nodeId ) => {
87- // Balancer value is used to create path, so it's necessary
88- if ( ! balancer ) {
89- return undefined ;
90- }
91-
92- if ( useClusterBalancerAsBackend ) {
93- return prepareBackendFromBalancer ( balancer ) ;
94- }
95-
96- if ( isNil ( nodeId ) ) {
97- return undefined ;
98- }
99-
100- return getBackendFromBalancerAndNodeId ( nodeId , balancer ) ?? undefined ;
101- } ;
102-
103- if ( monitoring && getMonitoringLink ) {
104- additionalTenantsProps . getMonitoringLink = ( dbName ?: string , dbType ?: ETenantType ) => {
105- if ( dbName && dbType ) {
106- return getMonitoringLink ( { monitoring, dbName, dbType, clusterName} ) ;
107- }
108-
109- return null ;
110- } ;
111- }
112-
113- if ( logging && getLogsLink ) {
114- additionalTenantsProps . getLogsLink = ( dbName ?: string ) => {
115- if ( dbName ) {
116- return getLogsLink ( {
117- dbName,
118- logging,
119- } ) ;
120- }
121-
122- return null ;
123- } ;
124- }
125-
126- return additionalTenantsProps ;
127- } ;
128-
12966interface ExtendedClusterProps {
13067 component : typeof Cluster ;
13168 getMonitoringLink ?: GetMonitoringLink ;
13269 getMonitoringClusterLink ?: GetMonitoringClusterLink ;
13370 getLogsLink ?: GetLogsLink ;
71+ getDatabaseLinks ?: GetDatabaseLinks ;
72+ getClusterLinks ?: GetClusterLinks ;
13473}
13574export function ExtendedCluster ( {
13675 component : ClusterComponent ,
13776 getMonitoringLink,
13877 getMonitoringClusterLink,
13978 getLogsLink,
79+ getDatabaseLinks,
80+ getClusterLinks,
14081} : ExtendedClusterProps ) {
14182 const additionalNodesProps = useAdditionalNodesProps ( ) ;
142- const { name, balancer, monitoring, logging} = useClusterBaseInfo ( ) ;
143-
144- const [ useClusterBalancerAsBackend ] = useSetting < boolean > ( USE_CLUSTER_BALANCER_AS_BACKEND_KEY ) ;
14583
14684 return (
14785 < div className = { b ( ) } >
14886 < ClusterComponent
149- additionalClusterProps = { getAdditionalClusterProps ( {
150- clusterName : name ,
151- monitoring,
152- balancer,
87+ additionalClusterProps = { useAdditionalClusterProps ( {
15388 getMonitoringClusterLink,
89+ getClusterLinks,
15490 } ) }
155- additionalTenantsProps = { getAdditionalTenantsProps ( {
156- clusterName : name ,
157- monitoring,
158- balancer,
159- logging,
160- useClusterBalancerAsBackend,
91+ additionalTenantsProps = { useAdditionalTenantsProps ( {
16192 getMonitoringLink,
16293 getLogsLink,
94+ getDatabaseLinks,
16395 } ) }
16496 additionalNodesProps = { additionalNodesProps }
16597 />
0 commit comments