Browse Source
Fixed long user email being truncated in the sidebar user menu (#16431 )
* Fixed long user email being truncated in the sidebar user menu
* Changed approach
* Simplified code
* Used popover background for email ellipsis fade and let domain use free width
---------
Co-authored-by: Vladyslav_Prykhodko <vprykhodko@thingsboard.io>
pull/16631/head
Maksym Tsymbarov
3 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
47 additions and
14 deletions
ui-ngx/src/app/shared/components/popover.component.scss
ui-ngx/src/app/shared/components/user-menu.component.html
ui-ngx/src/app/shared/components/user-menu.component.scss
ui-ngx/src/app/shared/components/user-menu.component.ts
ui-ngx/src/scss/constants.scss
@ -1,12 +1,12 @@
/ / SPDX-FileCopyrightText : Copyright The ThingsBoard Authors
/ / SPDX-FileCopyrightText : Modifications Copyright ThingsBoard , Inc .
/ / SPDX-License-Identifier : Apache-2 . 0 AND BUSL-1 . 1
@import ' ../../../scss/constants ' ;
@import ' ../../../scss/mixins ' ;
$popover-arrow-width : 6 ;
$popover-distance : $popover-arrow-width + 4 ;
$zindex-popover : 1030 ;
$popover-bg : #fff ;
$border-radius-base : 6 px ;
$popover-close-button-size : 30 px ;
$box-shadow-base : 0 3 px 6 px - 4 px rgba ( 0 , 0 , 0 , 0 .12 ) , 0 6 px 16 px 0 rgba ( 0 , 0 , 0 , 0 .08 ) ,
@ -40,14 +40,15 @@
@if (collapsed) {
@let fullName = userFullName$ | async;
@if (fullName?.length > 0) {
< div class = "tb-user-name" >
{{ fullName }}
< / div >
< div tbTruncateWithTooltip class = "tb-user-name" > {{ fullName }}< / div >
}
}
< div class = "tb-user-email" >
{{ userEmail$ | async }}
< / div >
@if (userEmail$ | async; as email) {
< div class = "tb-user-email" >
< span class = "tb-email-local" [ tbTruncateWithTooltip ] = " email . full " > {{ email.local }}< / span >
< span class = "tb-email-domain" [ tbTruncateWithTooltip ] = " email . full " > {{ email.domain }}< / span >
< / div >
}
< / div >
< button mat-button ( click ) = " menuPopoverFull ? . hide ( ) ; menuPopoverIcon ? . hide ( ) ; openAccount ( ) " >
< tb-icon matButtonIcon > mdi:account-circle-outline< / tb-icon >
@ -90,6 +90,7 @@ tb-user-menu {
. tb-user-menu-items {
min-width : 250 px ;
max-width : 320 px ;
display : flex ;
flex-direction : column ;
. tb-user-menu-header {
@ -102,17 +103,35 @@ tb-user-menu {
font-size : 14 px ;
font-weight : 600 ;
color : rgba ( 0 , 0 , 0 , 0 .87 ) ;
white-space : nowrap ;
overflow : hidden ;
text-overflow : ellipsis ;
}
. tb-user-email {
display : flex ;
font-size : 13 px ;
line-height : 16 px ;
color : rgba ( 0 , 0 , 0 , 0 .6 ) ;
white-space : nowrap ;
overflow : hidden ;
text-overflow : ellipsis ;
. tb-email-local , . tb-email-domain {
flex : 2 1 0 ;
min-width : 0 ;
max-width : max-content ;
}
@supports ( container-type : scroll-state ) {
. tb-email-local {
container-type : scroll - state ;
text-overflow : clip !important ;
}
@container scroll-state ( scrollable : inline-end ) {
. tb-email-local : : after {
content : " … " ;
position : sticky ;
right : 0 ;
padding-left : 0 .6 em ;
background : linear-gradient ( to right , transparent , $popover-bg 0 .6 em ) ;
}
}
}
. tb-email-domain {
flex-grow : 3 ;
}
}
. mat-mdc-button {
& : hover {
@ -58,7 +58,7 @@ export class UserMenuComponent {
userEmail $ = this . store . pipe (
select ( selectUserDetails ) ,
map ( ( user ) = > user ? . email )
map ( ( user ) = > this . splitEmail ( user ? . email ) )
) ;
constructor ( private store : Store < AppState > ,
@ -118,6 +118,17 @@ export class UserMenuComponent {
}
}
private splitEmail ( email : string ) : { full : string ; local : string ; domain : string } {
if ( ! email ) {
return null ;
}
const atIndex = email . lastIndexOf ( '@' ) ;
if ( atIndex <= 0 ) {
return { full : email , local : email , domain : '' } ;
}
return { full : email , local : email.substring ( 0 , atIndex ) , domain : email.substring ( atIndex ) } ;
}
openAccount ( ) : void {
this . menuClicked . emit ( ) ;
this . router . navigate ( [ 'account' ] ) ;
@ -20,4 +20,6 @@ $mat-gt-xxl: "screen and (min-width: 2448px)";
$mat-gt-xl : " screen and (min-width: 1920px) " ;
$mat-md-lg : " screen and (min-width: 960px) and (max-width: 1819px) " ;
$popover-bg : #fff ;
$sidenav-anim-timing : 400 ms cubic-bezier ( 0 .25 , 0 .8 , 0 .25 , 1 ) ;