@@ -2,9 +2,14 @@ import React from 'react';
22
33import NiceModal from '@ebay/nice-modal-react' ;
44import { Dialog , Tabs } from '@gravity-ui/uikit' ;
5+ import { skipToken } from '@reduxjs/toolkit/query' ;
56
7+ import { tenantApi } from '../../store/reducers/tenant/tenant' ;
68import { cn } from '../../utils/cn' ;
9+ import { useTypedSelector } from '../../utils/hooks' ;
10+ import { useClusterNameFromQuery } from '../../utils/hooks/useDatabaseFromQuery' ;
711import { LinkWithIcon } from '../LinkWithIcon/LinkWithIcon' ;
12+ import { LoaderWrapper } from '../LoaderWrapper/LoaderWrapper' ;
813import { YDBSyntaxHighlighterLazy } from '../SyntaxHighlighter/lazy' ;
914
1015import { getDocsLink } from './getDocsLink' ;
@@ -32,9 +37,26 @@ interface ConnectToDBDialogProps extends SnippetParams {
3237 onClose : VoidFunction ;
3338}
3439
35- function ConnectToDBDialog ( { open, onClose, database, endpoint} : ConnectToDBDialogProps ) {
40+ function ConnectToDBDialog ( {
41+ open,
42+ onClose,
43+ database,
44+ endpoint : endpointFromProps ,
45+ } : ConnectToDBDialogProps ) {
3646 const [ activeTab , setActiveTab ] = React . useState < SnippetLanguage > ( 'bash' ) ;
3747
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+
3860 const snippet = getSnippetCode ( activeTab , { database, endpoint} ) ;
3961 const docsLink = getDocsLink ( activeTab ) ;
4062
@@ -52,12 +74,14 @@ function ConnectToDBDialog({open, onClose, database, endpoint}: ConnectToDBDialo
5274 className = { b ( 'dialog-tabs' ) }
5375 />
5476 < 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 >
6185 </ div >
6286 { docsLink ? (
6387 < LinkWithIcon
0 commit comments