Browse Source

fix: hiding a Home card shows the platform's toast with Undo, styled as the design's dark message; the platform's toast can carry an action in place of Close

pull/16848/head
Igor Kulikov 2 weeks ago
parent
commit
8ccffaa97d
  1. 5
      ui-ngx/src/app/core/notification/notification.models.ts
  2. 19
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts
  3. 49
      ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss
  4. 11
      ui-ngx/src/app/shared/components/snack-bar-component.html
  5. 4
      ui-ngx/src/app/shared/components/toast.directive.ts

5
ui-ngx/src/app/core/notification/notification.models.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
export interface NotificationState {
notification: NotificationMessage;
hideNotification: HideNotification;
@ -19,6 +20,8 @@ export class NotificationMessage {
verticalPosition?: NotificationVerticalPosition;
panelClass?: string | string[];
modern?: boolean;
actionLabel?: string;
onAction?: () => void;
}
export class HideNotification {

19
ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts

@ -2,7 +2,7 @@
// SPDX-License-Identifier: BUSL-1.1
import { ChangeDetectionStrategy, Component, inject, input } from '@angular/core';
import { Store } from '@ngrx/store';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ToastNotificationService } from '@core/services/toast-notification.service';
import { TranslateService } from '@ngx-translate/core';
import { AppState } from '@core/core.state';
import { ActionPreferencesUpdateHomeCards } from '@core/auth/auth.actions';
@ -41,7 +41,7 @@ const UNDO_MS = 6000;
<ng-content></ng-content>
</section>
`,
styleUrls: ['./home-card.component.scss'],
styleUrls: ['./home-card.component.scss', './home-toast.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
@ -54,17 +54,22 @@ export class HomeCardComponent {
expanded = input(false);
private store = inject(Store<AppState>);
private snackBar = inject(MatSnackBar);
private translate = inject(TranslateService);
private toast = inject(ToastNotificationService);
hide(): void {
const id = this.card().id;
const name = this.translate.instant(this.card().name);
this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: false}));
this.snackBar.open(this.translate.instant('home.customize.hidden', {name}), this.translate.instant('home.customize.undo'), {
this.toast.dispatchNotification({
message: this.translate.instant('home.customize.hidden', {name}),
type: 'info',
duration: UNDO_MS,
horizontalPosition: 'end',
verticalPosition: 'bottom'
}).onAction().subscribe(() => this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true})));
horizontalPosition: 'right',
verticalPosition: 'bottom',
panelClass: 'tb-home-toast',
actionLabel: this.translate.instant('home.customize.undo'),
onAction: () => this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true}))
});
}
}

49
ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss

@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
::ng-deep .mat-mdc-snack-bar-container.tb-home-toast.tb-home-toast {
.tb-toast.tb-toast.tb-toast {
gap: 4px;
box-sizing: border-box;
max-width: min(480px, calc(100vw - 16px));
margin: 8px;
padding: 6px 6px 6px 16px;
border-radius: 4px;
background: #323232;
box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2), 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12);
font: 400 14px/20px var(--tb-font, Roboto, sans-serif);
letter-spacing: .25px;
color: rgba(255, 255, 255, 0.92);
}
.tb-toast .toast-text.toast-text {
flex: 1 1 auto;
min-width: 0;
padding: 4px 8px 4px 0;
font: inherit;
letter-spacing: inherit;
color: inherit;
}
.tb-toast .mat-mdc-button.mat-mdc-button-base.mat-mdc-button-base {
--mat-button-text-label-text-color: rgba(255, 255, 255, 0.92);
--mdc-text-button-label-text-color: rgba(255, 255, 255, 0.92);
flex: none;
min-width: 0;
height: 32px;
margin: 0;
padding: 0 10px;
border-radius: 4px;
font: 500 14px/32px var(--tb-font, Roboto, sans-serif);
letter-spacing: 0.03125em;
color: rgba(255, 255, 255, 0.92);
&:hover {
background: rgba(255, 255, 255, 0.08);
}
&:focus-visible {
outline: 2px solid #fff;
outline-offset: -2px;
}
}
}

11
ui-ngx/src/app/shared/components/snack-bar-component.html

@ -1,7 +1,8 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<div class="flex flex-row items-center justify-start"
@ -15,7 +16,7 @@
[class.info-toast]="notification.type === 'info'">
@if (!notification.modern) {
<div class="toast-text" [innerHTML]="notification.message | safe: 'html'"></div>
<button #actionButton type="button" mat-button (click)="action($event)">{{ 'action.close' | translate }}</button>
<button #actionButton type="button" mat-button (click)="action($event)">{{ notification.actionLabel || ('action.close' | translate) }}</button>
} @else {
<div class="tb-modern-toast-panel"
[class.error-toast]="notification.type === 'error'"
@ -23,7 +24,11 @@
[class.success-toast]="notification.type === 'success'"
[class.info-toast]="notification.type === 'info'">
<div class="toast-text" [innerHTML]="notification.message | safe: 'html'"></div>
<button #actionButton class="tb-mat-20" mat-icon-button (click)="action($event)"><mat-icon>close</mat-icon></button>
@if (notification.actionLabel) {
<button #actionButton type="button" mat-button (click)="action($event)">{{ notification.actionLabel }}</button>
} @else {
<button #actionButton class="tb-mat-20" mat-icon-button (click)="action($event)"><mat-icon>close</mat-icon></button>
}
</div>
}
</div>

4
ui-ngx/src/app/shared/components/toast.directive.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import {
AfterViewInit, ChangeDetectorRef,
Component, ComponentRef,
@ -347,6 +348,7 @@ export class TbSnackBarComponent implements AfterViewInit, OnDestroy {
action(event: MouseEvent): void {
event.stopPropagation();
this.notification.onAction?.();
if (this.snackBarRef) {
this.snackBarRef.dismissWithAction();
} else {

Loading…
Cancel
Save