1
1
import { ClipboardButton } from '@gravity-ui/uikit' ;
2
- import { isNil } from 'lodash' ;
3
2
4
3
import { 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 ' ;
7
6
import { cn } from '../../../utils/cn' ;
8
- import { USE_CLUSTER_BALANCER_AS_BACKEND_KEY } from '../../../utils/constants' ;
9
- import { useSetting } from '../../../utils/hooks' ;
10
7
import { useAdditionalNodesProps } from '../../../utils/hooks/useAdditionalNodesProps' ;
11
8
import type { GetLogsLink } from '../../../utils/logs' ;
12
9
import 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' ;
15
11
import type { Cluster } from '../../Cluster/Cluster' ;
12
+ import { useAdditionalTenantsProps } from '../utils/useAdditionalTenantsProps' ;
16
13
17
14
import './ExtendedCluster.scss' ;
18
15
@@ -33,133 +30,68 @@ const getAdditionalBalancerInfo = (balancer: string) => {
33
30
} ;
34
31
35
32
interface GetAdditionalClusterProps {
36
- clusterName : string | undefined ;
37
- monitoring : string | undefined ;
38
- balancer : string | undefined ;
39
33
getMonitoringClusterLink ?: GetMonitoringClusterLink ;
34
+ getClusterLinks ?: GetClusterLinks ;
40
35
}
41
36
42
- const getAdditionalClusterProps = ( {
43
- clusterName,
44
- monitoring,
45
- balancer,
37
+ const useAdditionalClusterProps = ( {
46
38
getMonitoringClusterLink,
39
+ getClusterLinks,
47
40
} : GetAdditionalClusterProps ) => {
48
- const additionalClusterProps : AdditionalClusterProps = { } ;
41
+ const clusterInfo = useClusterBaseInfo ( ) ;
42
+ const { name : clusterName , balancer, monitoring} = clusterInfo ;
49
43
44
+ const additionalClusterProps : AdditionalClusterProps = { } ;
45
+ additionalClusterProps . links = [ ] ;
50
46
if ( monitoring && getMonitoringClusterLink ) {
51
47
const clusterLink = getMonitoringClusterLink ( monitoring , clusterName ) ;
52
48
53
49
if ( clusterLink ) {
54
- additionalClusterProps . links = [ { title : 'Monitoring' , url : clusterLink } ] ;
50
+ additionalClusterProps . links . push ( { title : 'Monitoring' , url : clusterLink } ) ;
55
51
}
56
52
}
57
53
54
+ if ( getClusterLinks ) {
55
+ const clusterLinks = getClusterLinks ( { clusterInfo} ) ;
56
+ additionalClusterProps . links . push ( ...clusterLinks ) ;
57
+ }
58
+
58
59
if ( balancer ) {
59
60
additionalClusterProps . info = [ getAdditionalBalancerInfo ( balancer ) ] ;
60
61
}
61
62
62
63
return additionalClusterProps ;
63
64
} ;
64
65
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
-
129
66
interface ExtendedClusterProps {
130
67
component : typeof Cluster ;
131
68
getMonitoringLink ?: GetMonitoringLink ;
132
69
getMonitoringClusterLink ?: GetMonitoringClusterLink ;
133
70
getLogsLink ?: GetLogsLink ;
71
+ getDatabaseLinks ?: GetDatabaseLinks ;
72
+ getClusterLinks ?: GetClusterLinks ;
134
73
}
135
74
export function ExtendedCluster ( {
136
75
component : ClusterComponent ,
137
76
getMonitoringLink,
138
77
getMonitoringClusterLink,
139
78
getLogsLink,
79
+ getDatabaseLinks,
80
+ getClusterLinks,
140
81
} : ExtendedClusterProps ) {
141
82
const additionalNodesProps = useAdditionalNodesProps ( ) ;
142
- const { name, balancer, monitoring, logging} = useClusterBaseInfo ( ) ;
143
-
144
- const [ useClusterBalancerAsBackend ] = useSetting < boolean > ( USE_CLUSTER_BALANCER_AS_BACKEND_KEY ) ;
145
83
146
84
return (
147
85
< div className = { b ( ) } >
148
86
< ClusterComponent
149
- additionalClusterProps = { getAdditionalClusterProps ( {
150
- clusterName : name ,
151
- monitoring,
152
- balancer,
87
+ additionalClusterProps = { useAdditionalClusterProps ( {
153
88
getMonitoringClusterLink,
89
+ getClusterLinks,
154
90
} ) }
155
- additionalTenantsProps = { getAdditionalTenantsProps ( {
156
- clusterName : name ,
157
- monitoring,
158
- balancer,
159
- logging,
160
- useClusterBalancerAsBackend,
91
+ additionalTenantsProps = { useAdditionalTenantsProps ( {
161
92
getMonitoringLink,
162
93
getLogsLink,
94
+ getDatabaseLinks,
163
95
} ) }
164
96
additionalNodesProps = { additionalNodesProps }
165
97
/>
0 commit comments