@@ -22,6 +22,8 @@ import { Link } from 'uiSrc/components/base/link/Link'
22
22
import { DownloadIcon , SignoutIcon } from '@redis-ui/icons'
23
23
import { Menu } from 'uiSrc/components/base/layout/menu'
24
24
import { ProfileIcon } from 'uiSrc/components/base/layout/profile-icon/ProfileIcon'
25
+ import Loader from 'uiSrc/components/base/display/loader/Loader'
26
+ import { OutsideClickDetector } from 'uiSrc/components/base/utils'
25
27
26
28
export interface UserProfileBadgeProps {
27
29
'data-testid' ?: string
@@ -106,115 +108,142 @@ const UserProfileBadge = (props: UserProfileBadgeProps) => {
106
108
const { accounts, currentAccountId, name } = data
107
109
108
110
return (
109
- < Menu >
110
- < Menu . Trigger withButton onClick = { handleToggleProfile } >
111
- < ProfileIcon
112
- size = "L"
113
- fullName = { name }
114
- role = "presentation"
115
- data-testid = "user-profile-btn"
116
- style = { { cursor : 'pointer' } }
117
- />
118
- </ Menu . Trigger >
119
- < Menu . Content
120
- data-testid = "user-profile-popover-content"
121
- style = { { minWidth : 330 } }
122
- >
123
- < FeatureFlagComponent
124
- name = { FeatureFlags . envDependent }
125
- otherwise = {
126
- < Menu . Content . Label text = "Account" data-testid = "profile-title" />
127
- }
128
- >
129
- < Menu . Content . Label
130
- text = "Redis Cloud account"
131
- data-testid = "profile-title"
132
- />
133
- </ FeatureFlagComponent >
134
- < Menu . Content . Separator />
135
- < div data-testid = "user-profile-popover-accounts" >
136
- { accounts ?. map ( ( { name, id } ) => (
137
- < Menu . Content . Item
111
+ < OutsideClickDetector onOutsideClick = { ( ) => setIsProfileOpen ( false ) } >
112
+ < div data-testid = { dataTestId } >
113
+ < Menu open = { isProfileOpen } >
114
+ < Menu . Trigger
115
+ withButton
116
+ onClick = { handleToggleProfile }
117
+ data-testid = "user-profile-btn"
118
+ >
119
+ < ProfileIcon
120
+ size = "L"
121
+ fullName = { name }
138
122
role = "presentation"
139
- key = { id }
140
- text = { `${ name } #${ id } ` }
141
- selected = { id === currentAccountId }
142
- onClick = { ( ) => handleClickSelectAccount ?.( id ) }
143
- data-testid = { `profile-account-${ id } ${ id === currentAccountId ? '-selected' : '' } ` }
123
+ style = { { cursor : 'pointer' } }
144
124
/>
145
- ) ) }
146
- </ div >
147
- < Menu . Content . Separator />
148
- < FeatureFlagComponent
149
- name = { FeatureFlags . envDependent }
150
- otherwise = {
151
- < >
152
- < Menu . Content . Item . Compose >
153
- < Menu . Content . Item . Text >
154
- < Link
155
- external
156
- color = "text"
157
- href = { riDesktopLink }
158
- data-testid = "open-ri-desktop-link"
159
- variant = "inline"
160
- >
161
- Open in Redis Insight Desktop version
162
- </ Link >
163
- </ Menu . Content . Item . Text >
164
- </ Menu . Content . Item . Compose >
125
+ </ Menu . Trigger >
126
+ < Menu . Content
127
+ data-testid = "user-profile-popover-content"
128
+ style = { { minWidth : 330 } }
129
+ >
130
+ < FeatureFlagComponent
131
+ name = { FeatureFlags . envDependent }
132
+ otherwise = {
133
+ < Menu . Content . Label
134
+ text = "Account"
135
+ data-testid = "profile-title"
136
+ />
137
+ }
138
+ >
139
+ < Menu . Content . Label
140
+ text = "Redis Cloud account"
141
+ data-testid = "profile-title"
142
+ />
143
+ </ FeatureFlagComponent >
144
+ < Menu . Content . Separator />
145
+ < div data-testid = "user-profile-popover-accounts" >
146
+ { accounts ?. map ( ( { name, id } ) => (
147
+ < Menu . Content . Item . Compose
148
+ role = "presentation"
149
+ key = { id }
150
+ selected = { id === selectingAccountId }
151
+ onClick = { ( ) => handleClickSelectAccount ?.( id ) }
152
+ data-testid = { `profile-account-${ id } ${ id === currentAccountId ? '-selected' : '' } ` }
153
+ >
154
+ < Menu . Content . Item . Text >
155
+ { `${ name } #${ id } ` }
156
+ </ Menu . Content . Item . Text >
157
+ { id === selectingAccountId && (
158
+ < Loader
159
+ size = "m"
160
+ data-testid = { `user-profile-selecting-account-${ id } ` }
161
+ />
162
+ ) }
163
+ { id === currentAccountId && (
164
+ < Menu . Content . Item . Check
165
+ data-testid = { `user-profile-selected-account-${ id } ` }
166
+ />
167
+ ) }
168
+ </ Menu . Content . Item . Compose >
169
+ ) ) }
170
+ </ div >
171
+ < Menu . Content . Separator />
172
+ < FeatureFlagComponent
173
+ name = { FeatureFlags . envDependent }
174
+ otherwise = {
175
+ < >
176
+ < Menu . Content . Item . Compose >
177
+ < Menu . Content . Item . Text >
178
+ < Link
179
+ external
180
+ color = "text"
181
+ href = { riDesktopLink }
182
+ data-testid = "open-ri-desktop-link"
183
+ variant = "inline"
184
+ >
185
+ Open in Redis Insight Desktop version
186
+ </ Link >
187
+ </ Menu . Content . Item . Text >
188
+ </ Menu . Content . Item . Compose >
189
+ < Menu . Content . Item . Compose >
190
+ < Menu . Content . Item . Text >
191
+ < Link
192
+ external
193
+ color = "text"
194
+ variant = "inline"
195
+ target = "_blank"
196
+ href = { riConfig . app . smConsoleRedirect }
197
+ data-testid = "cloud-admin-console-link"
198
+ >
199
+ Back to Redis Cloud Admin console
200
+ </ Link >
201
+ </ Menu . Content . Item . Text >
202
+ </ Menu . Content . Item . Compose >
203
+ </ >
204
+ }
205
+ >
206
+ < Menu . Content . Item
207
+ role = "presentation"
208
+ subHead = "Import Cloud Databases"
209
+ text = ""
210
+ icon = { DownloadIcon }
211
+ onSelect = { handleClickImport }
212
+ data-testid = "profile-import-cloud-databases"
213
+ />
165
214
< Menu . Content . Item . Compose >
166
215
< Menu . Content . Item . Text >
167
216
< Link
168
217
external
169
218
color = "text"
170
219
variant = "inline"
171
220
target = "_blank"
172
- href = { riConfig . app . smConsoleRedirect }
173
- data-testid = "cloud-admin-console-link"
221
+ href = { getUtmExternalLink ( EXTERNAL_LINKS . cloudConsole , {
222
+ campaign : 'cloud_account' ,
223
+ } ) }
224
+ onClick = { handleClickCloudAccount }
225
+ data-testid = "cloud-console-link"
174
226
>
175
- Back to Redis Cloud Admin console
227
+ Cloud Console:
228
+ < span data-testid = "account-full-name" > { name } </ span >
176
229
</ Link >
177
230
</ Menu . Content . Item . Text >
178
231
</ Menu . Content . Item . Compose >
179
- </ >
180
- }
181
- >
182
- < Menu . Content . Item
183
- role = "presentation"
184
- subHead = "Import Cloud Databases"
185
- icon = { DownloadIcon }
186
- onSelect = { handleClickImport }
187
- data-testid = "profile-import-cloud-databases"
188
- />
189
- < Menu . Content . Item . Compose >
190
- < Menu . Content . Item . Text >
191
- < Link
192
- external
193
- color = "text"
194
- variant = "inline"
195
- target = "_blank"
196
- href = { getUtmExternalLink ( EXTERNAL_LINKS . cloudConsole , {
197
- campaign : 'cloud_account' ,
198
- } ) }
199
- onClick = { handleClickCloudAccount }
200
- data-testid = "cloud-console-link"
201
- >
202
- Cloud Console: { name }
203
- </ Link >
204
- </ Menu . Content . Item . Text >
205
- </ Menu . Content . Item . Compose >
206
- < Menu . Content . Separator />
207
- < Menu . Content . Item
208
- role = "presentation"
209
- subHead = "Logout"
210
- icon = { SignoutIcon }
211
- onClick = { handleClickLogout }
212
- data-testid = "profile-logout"
213
- />
214
- </ FeatureFlagComponent >
215
- < Menu . Content . DropdownArrow />
216
- </ Menu . Content >
217
- </ Menu >
232
+ < Menu . Content . Separator />
233
+ < Menu . Content . Item
234
+ role = "presentation"
235
+ subHead = "Logout"
236
+ text = ""
237
+ icon = { SignoutIcon }
238
+ onClick = { handleClickLogout }
239
+ data-testid = "profile-logout"
240
+ />
241
+ </ FeatureFlagComponent >
242
+ < Menu . Content . DropdownArrow />
243
+ </ Menu . Content >
244
+ </ Menu >
245
+ </ div >
246
+ </ OutsideClickDetector >
218
247
)
219
248
}
220
249
0 commit comments