@@ -2,9 +2,14 @@ import React from 'react';
2
2
3
3
import NiceModal from '@ebay/nice-modal-react' ;
4
4
import { Dialog , Tabs } from '@gravity-ui/uikit' ;
5
+ import { skipToken } from '@reduxjs/toolkit/query' ;
5
6
7
+ import { tenantApi } from '../../store/reducers/tenant/tenant' ;
6
8
import { cn } from '../../utils/cn' ;
9
+ import { useTypedSelector } from '../../utils/hooks' ;
10
+ import { useClusterNameFromQuery } from '../../utils/hooks/useDatabaseFromQuery' ;
7
11
import { LinkWithIcon } from '../LinkWithIcon/LinkWithIcon' ;
12
+ import { LoaderWrapper } from '../LoaderWrapper/LoaderWrapper' ;
8
13
import { YDBSyntaxHighlighterLazy } from '../SyntaxHighlighter/lazy' ;
9
14
10
15
import { getDocsLink } from './getDocsLink' ;
@@ -32,9 +37,26 @@ interface ConnectToDBDialogProps extends SnippetParams {
32
37
onClose : VoidFunction ;
33
38
}
34
39
35
- function ConnectToDBDialog ( { open, onClose, database, endpoint} : ConnectToDBDialogProps ) {
40
+ function ConnectToDBDialog ( {
41
+ open,
42
+ onClose,
43
+ database,
44
+ endpoint : endpointFromProps ,
45
+ } : ConnectToDBDialogProps ) {
36
46
const [ activeTab , setActiveTab ] = React . useState < SnippetLanguage > ( 'bash' ) ;
37
47
48
+ const clusterName = useClusterNameFromQuery ( ) ;
49
+ const singleClusterMode = useTypedSelector ( ( state ) => state . singleClusterMode ) ;
50
+
51
+ // If there is endpoint from props, we don't need to request tenant data
52
+ // Also we should not request tenant data if we are in single cluster mode
53
+ // Since there is no ControlPlane data in this case
54
+ const shouldRequestTenantData = database && ! endpointFromProps && ! singleClusterMode ;
55
+ const params = shouldRequestTenantData ? { path : database , clusterName} : skipToken ;
56
+ const { currentData : tenantData , isLoading : isTenantDataLoading } =
57
+ tenantApi . useGetTenantInfoQuery ( params ) ;
58
+ const endpoint = endpointFromProps ?? tenantData ?. ControlPlane ?. endpoint ;
59
+
38
60
const snippet = getSnippetCode ( activeTab , { database, endpoint} ) ;
39
61
const docsLink = getDocsLink ( activeTab ) ;
40
62
@@ -52,12 +74,14 @@ function ConnectToDBDialog({open, onClose, database, endpoint}: ConnectToDBDialo
52
74
className = { b ( 'dialog-tabs' ) }
53
75
/>
54
76
< div className = { b ( 'snippet-container' ) } >
55
- < YDBSyntaxHighlighterLazy
56
- language = { activeTab }
57
- text = { snippet }
58
- transparentBackground = { false }
59
- withClipboardButton = { { alwaysVisible : true } }
60
- />
77
+ < LoaderWrapper loading = { isTenantDataLoading } >
78
+ < YDBSyntaxHighlighterLazy
79
+ language = { activeTab }
80
+ text = { snippet }
81
+ transparentBackground = { false }
82
+ withClipboardButton = { { alwaysVisible : true } }
83
+ />
84
+ </ LoaderWrapper >
61
85
</ div >
62
86
{ docsLink ? (
63
87
< LinkWithIcon
0 commit comments