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
parent
commit
d89b4699ab
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      ui-ngx/src/app/shared/components/popover.component.scss
  2. 13
      ui-ngx/src/app/shared/components/user-menu.component.html
  3. 31
      ui-ngx/src/app/shared/components/user-menu.component.scss
  4. 13
      ui-ngx/src/app/shared/components/user-menu.component.ts
  5. 2
      ui-ngx/src/scss/constants.scss

2
ui-ngx/src/app/shared/components/popover.component.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: 6px;
$popover-close-button-size: 30px;
$box-shadow-base: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08),

13
ui-ngx/src/app/shared/components/user-menu.component.html

@ -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>

31
ui-ngx/src/app/shared/components/user-menu.component.scss

@ -90,6 +90,7 @@ tb-user-menu {
.tb-user-menu-items {
min-width: 250px;
max-width: 320px;
display: flex;
flex-direction: column;
.tb-user-menu-header {
@ -102,17 +103,35 @@ tb-user-menu {
font-size: 14px;
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: 13px;
line-height: 16px;
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.6em;
background: linear-gradient(to right, transparent, $popover-bg 0.6em);
}
}
}
.tb-email-domain {
flex-grow: 3;
}
}
.mat-mdc-button {
&:hover {

13
ui-ngx/src/app/shared/components/user-menu.component.ts

@ -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']);

2
ui-ngx/src/scss/constants.scss

@ -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: 400ms cubic-bezier(0.25, 0.8, 0.25, 1);

Loading…
Cancel
Save