@@ -13,15 +13,17 @@ import TextField from "../../../Main/TextField/TextField";
1313import useBoolean from "../../../../hooks/useBoolean" ;
1414import useStateSearchParams from "../../../../hooks/useStateSearchParams" ;
1515import { useSearchParams } from "react-router-dom" ;
16+ import { useAppState } from "../../../../state/common/StateContext" ;
1617
1718const TenantsFields : FC = ( ) => {
1819 const appModeEnable = getAppModeEnable ( ) ;
1920 const { isMobile } = useDeviceDetect ( ) ;
2021 const timeDispatch = useTimeDispatch ( ) ;
22+ const { tenantId } = useAppState ( ) ;
2123
2224 const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
23- const [ accountID , setAccountID ] = useStateSearchParams ( "0" , "accountID" ) ;
24- const [ projectID , setProjectID ] = useStateSearchParams ( "0" , "projectID" ) ;
25+ const [ accountID , setAccountID ] = useStateSearchParams ( tenantId ?. accountID || "0" , "accountID" ) ;
26+ const [ projectID , setProjectID ] = useStateSearchParams ( tenantId ?. projectID || "0" , "projectID" ) ;
2527 const formattedTenant = `${ accountID } :${ projectID } ` ;
2628
2729 const buttonRef = useRef < HTMLDivElement > ( null ) ;
@@ -41,107 +43,134 @@ const TenantsFields: FC = () => {
4143 } ;
4244
4345 const handleReset = ( ) => {
44- setAccountID ( searchParams . get ( "accountID" ) || "0" ) ;
45- setProjectID ( searchParams . get ( "projectID" ) || "0" ) ;
46+ setAccountID ( searchParams . get ( "accountID" ) || tenantId ?. accountID || "0" ) ;
47+ setProjectID ( searchParams . get ( "projectID" ) || tenantId ?. projectID || "0" ) ;
4648 } ;
4749
4850 useEffect ( ( ) => {
4951 if ( openPopup ) return ;
5052 handleReset ( ) ;
5153 } , [ openPopup ] ) ;
5254
55+ const isTenantStatic = ! ! ( tenantId ?. accountID || tenantId ?. projectID ) ;
56+ const tooltipMessage = isTenantStatic ? "Static tenant for a current user" : "Define Tenant ID if you need request to another storage" ;
57+
58+ const getTenantLabel = ( ) => {
59+ return (
60+ < div ref = { buttonRef } >
61+ < div
62+ className = "vm-mobile-option"
63+ onClick = { isTenantStatic ? undefined : toggleOpenPopup }
64+ >
65+ < span className = "vm-mobile-option__icon" > < StorageIcon /> </ span >
66+ < div className = "vm-mobile-option-text" >
67+ { isMobile && (
68+ < span className = "vm-mobile-option-text__label" > Tenant ID</ span >
69+ ) }
70+ < span className = "vm-mobile-option-text__value" > { formattedTenant } </ span >
71+ </ div >
72+ { ! isTenantStatic && (
73+ < span className = "vm-mobile-option__arrow" > < ArrowDownIcon /> </ span >
74+ ) }
75+ </ div >
76+ </ div >
77+ ) ;
78+ } ;
79+
5380 return (
54- < div className = "vm-tenant-input" >
55- < Tooltip title = "Define Tenant ID if you need request to another storage" >
56- < div ref = { buttonRef } >
57- { isMobile ? (
58- < div
59- className = "vm-mobile-option"
60- onClick = { toggleOpenPopup }
61- >
62- < span className = "vm-mobile-option__icon" > < StorageIcon /> </ span >
63- < div className = "vm-mobile-option-text" >
64- < span className = "vm-mobile-option-text__label" > Tenant ID</ span >
65- < span className = "vm-mobile-option-text__value" > { formattedTenant } </ span >
66- </ div >
67- < span className = "vm-mobile-option__arrow" > < ArrowDownIcon /> </ span >
68- </ div >
81+ < div
82+ className = { classNames ( {
83+ "vm-tenant-input" : true ,
84+ "vm-tenant-input_disabled" : isTenantStatic ,
85+ "vm-tenant-input_mobile" : isMobile ,
86+ } ) }
87+ >
88+ { isMobile ? (
89+ getTenantLabel ( )
90+ ) : (
91+ < Tooltip title = { tooltipMessage } >
92+ { isTenantStatic ? (
93+ getTenantLabel ( )
6994 ) : (
70- < Button
71- className = { appModeEnable ? "" : "vm-header-button" }
72- variant = "contained"
73- color = "primary"
74- fullWidth
75- startIcon = { < StorageIcon /> }
76- endIcon = { (
77- < div
78- className = { classNames ( {
79- "vm-execution-controls-buttons__arrow" : true ,
80- "vm-execution-controls-buttons__arrow_open" : openPopup ,
81- } ) }
82- >
83- < ArrowDownIcon />
84- </ div >
85- ) }
86- onClick = { toggleOpenPopup }
87- >
88- { formattedTenant }
89- </ Button >
95+ < div ref = { buttonRef } >
96+ < Button
97+ className = { appModeEnable ? "" : "vm-header-button" }
98+ variant = "contained"
99+ color = "primary"
100+ fullWidth
101+ startIcon = { < StorageIcon /> }
102+ endIcon = { (
103+ < div
104+ className = { classNames ( {
105+ "vm-execution-controls-buttons__arrow" : true ,
106+ "vm-execution-controls-buttons__arrow_open" : openPopup ,
107+ } ) }
108+ >
109+ < ArrowDownIcon />
110+ </ div >
111+ ) }
112+ onClick = { toggleOpenPopup }
113+ >
114+ { formattedTenant }
115+ </ Button >
116+ </ div >
90117 ) }
91- </ div >
92- </ Tooltip >
93- < Popper
94- open = { openPopup }
95- placement = "bottom-right"
96- onClose = { handleClosePopup }
97- buttonRef = { buttonRef }
98- title = { isMobile ? "Define Tenant ID" : undefined }
99- >
100- < div
101- className = { classNames ( {
102- "vm-list vm-tenant-input-list" : true ,
103- "vm-list vm-tenant-input-list_mobile" : isMobile ,
104- "vm-tenant-input-list_inline" : true ,
105- } ) }
118+ </ Tooltip >
119+ ) }
120+ { ! isTenantStatic && (
121+ < Popper
122+ open = { openPopup }
123+ placement = "bottom-right"
124+ onClose = { handleClosePopup }
125+ buttonRef = { buttonRef }
126+ title = { isMobile ? "Define Tenant ID" : undefined }
106127 >
107- < TextField
108- autofocus
109- label = "accountID"
110- value = { accountID }
111- onChange = { setAccountID }
112- type = "number"
113- />
114- < TextField
115- autofocus
116- label = "projectID"
117- value = { projectID }
118- onChange = { setProjectID }
119- type = "number"
120- />
121- < div className = "vm-tenant-input-list__buttons" >
122- < Tooltip title = "Multitenancy in VictoriaLogs documentation" >
123- < a
124- href = "https://docs.victoriametrics.com/victorialogs/#multitenancy"
125- target = "_blank"
126- rel = "help noreferrer"
128+ < div
129+ className = { classNames ( {
130+ "vm-list vm-tenant-input-list" : true ,
131+ "vm-list vm-tenant-input-list_mobile" : isMobile ,
132+ "vm-tenant-input-list_inline" : true ,
133+ } ) }
134+ >
135+ < TextField
136+ autofocus
137+ label = "accountID"
138+ value = { accountID }
139+ onChange = { setAccountID }
140+ type = "number"
141+ />
142+ < TextField
143+ autofocus
144+ label = "projectID"
145+ value = { projectID }
146+ onChange = { setProjectID }
147+ type = "number"
148+ />
149+ < div className = "vm-tenant-input-list__buttons" >
150+ < Tooltip title = "Multitenancy in VictoriaLogs documentation" >
151+ < a
152+ href = "https://docs.victoriametrics.com/victorialogs/#multitenancy"
153+ target = "_blank"
154+ rel = "help noreferrer"
155+ >
156+ < Button
157+ variant = "text"
158+ color = "gray"
159+ startIcon = { < QuestionIcon /> }
160+ />
161+ </ a >
162+ </ Tooltip >
163+ < Button
164+ variant = "contained"
165+ color = "primary"
166+ onClick = { applyChanges }
127167 >
128- < Button
129- variant = "text"
130- color = "gray"
131- startIcon = { < QuestionIcon /> }
132- />
133- </ a >
134- </ Tooltip >
135- < Button
136- variant = "contained"
137- color = "primary"
138- onClick = { applyChanges }
139- >
140- Apply
141- </ Button >
168+ Apply
169+ </ Button >
170+ </ div >
142171 </ div >
143- </ div >
144- </ Popper >
172+ </ Popper >
173+ ) }
145174 </ div >
146175 ) ;
147176} ;
0 commit comments