From 2ef6dc46e0e432159514250d3ec0c4a46fb289c7 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Thu, 17 Oct 2019 22:54:50 +0100 Subject: [PATCH] [ADF-4954] Notification history persist (#5154) * persist notification in storage * add max stack check * add max stack check * fix folder --- .../directives/create-folder-directive.e2e.ts | 1 - .../notification-history.component.ts | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/e2e/content-services/directives/create-folder-directive.e2e.ts b/e2e/content-services/directives/create-folder-directive.e2e.ts index 6871af3eb9..8f371a87dc 100644 --- a/e2e/content-services/directives/create-folder-directive.e2e.ts +++ b/e2e/content-services/directives/create-folder-directive.e2e.ts @@ -127,7 +127,6 @@ describe('Create folder directive', () => { }); it('[C260159] Should not be possible create a folder with banned character', async () => { - await browser.refresh(); await contentServicesPage.clickOnCreateNewFolder(); await createFolderDialog.addFolderName('*'); diff --git a/lib/core/notifications/components/notification-history.component.ts b/lib/core/notifications/components/notification-history.component.ts index a8ba17cacd..7b21821a9c 100644 --- a/lib/core/notifications/components/notification-history.component.ts +++ b/lib/core/notifications/components/notification-history.component.ts @@ -21,6 +21,7 @@ import { NotificationModel } from '../models/notification.model'; import { MatMenuTrigger } from '@angular/material'; import { takeUntil } from 'rxjs/operators'; import { Subject } from 'rxjs'; +import { StorageService } from '../../services/storage.service'; @Component({ selector: 'adf-notification-history', @@ -33,6 +34,8 @@ export class NotificationHistoryComponent implements OnDestroy { notifications: NotificationModel[] = []; + MAX_NOTIFICATION_STACK_LENGTH = 100; + @ViewChild(MatMenuTrigger) trigger: MatMenuTrigger; @@ -45,12 +48,19 @@ export class NotificationHistoryComponent implements OnDestroy { menuPositionY: string = 'below'; constructor( - private notificationService: NotificationService) { + private notificationService: NotificationService, public storageService: StorageService) { + this.notifications = JSON.parse(storageService.getItem('notifications')) || []; this.notificationService.notifications$ .pipe(takeUntil(this.onDestroy$)) .subscribe((message) => { - this.notifications.push(message); - }); + this.notifications.push(message); + + if (this.notifications.length > this.MAX_NOTIFICATION_STACK_LENGTH) { + this.notifications.shift(); + } + + storageService.setItem('notifications', JSON.stringify(this.notifications)); + }); } isEmptyNotification(): boolean { @@ -62,6 +72,7 @@ export class NotificationHistoryComponent implements OnDestroy { } markAsRead() { + this.storageService.setItem('notifications', ''); this.notifications = []; }