]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Allow removal of single notification 31048/head
authorTiago Melo <tmelo@suse.com>
Fri, 4 Oct 2019 12:10:52 +0000 (12:10 +0000)
committerTiago Melo <tmelo@suse.com>
Tue, 29 Oct 2019 14:50:01 +0000 (13:50 -0100)
Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.scss
src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.ts
src/pybind/mgr/dashboard/frontend/src/styles.scss

index 6b4f2f3fa9ba46f9ca26bcad9ddfd14ebab787ad..6b2921230d271775fdd74cc62118fc308133489e 100644 (file)
@@ -54,7 +54,7 @@
 
     <hr>
 
-    <div *ngFor="let notification of notifications">
+    <div *ngFor="let notification of notifications; let i = index">
       <div class="card border-0 mb-3">
         <div class="row no-gutters">
           <div class="col-md-3 text-center">
           </div>
           <div class="col-md-9">
             <div class="card-body p-0">
+              <button class="btn btn-link float-right mt-0 pt-0"
+                      title="Remove notification"
+                      i18n-title
+                      (click)="remove(i); $event.stopPropagation()">
+                <i [ngClass]="[icons.trash]"></i>
+              </button>
+
               <h6 class="card-title bold">{{ notification.title }}</h6>
               <p class="card-text"
                  [innerHtml]="notification.message"></p>
index 5c28c20ad8cdc57b18b3e9f26115e310e2854360..d9660e0e1e491a78bc5fa286fbe2a47b0b1e89bf 100644 (file)
@@ -121,6 +121,10 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy {
     this.notificationService.removeAll();
   }
 
+  remove(index: number) {
+    this.notificationService.remove(index);
+  }
+
   closeSidebar() {
     this.notificationService.toggleSidebar(true);
   }
index 2c0c22a9c4aa3d8916cf26795c80041c5462485c..2767f3f69cf2d742c4bb1cc3a0f5217e8bd6d21a 100644 (file)
@@ -69,6 +69,13 @@ describe('NotificationService', () => {
       });
     };
 
+    const addNotifications = (quantity) => {
+      for (let index = 0; index < quantity; index++) {
+        service.show(NotificationType.info, `${index}`);
+        tick(510);
+      }
+    };
+
     beforeEach(() => {
       spyOn(service, 'show').and.callThrough();
       service.cancel(service['justShownTimeoutId']);
@@ -94,10 +101,7 @@ describe('NotificationService', () => {
     }));
 
     it('should never have more then 10 notifications', fakeAsync(() => {
-      for (let index = 0; index < 15; index++) {
-        service.show(NotificationType.info, 'Simple test');
-        tick(510);
-      }
+      addNotifications(15);
       expect(service['dataSource'].getValue().length).toBe(10);
     }));
 
@@ -156,6 +160,22 @@ describe('NotificationService', () => {
         message: '<ul><li>Error occurred in path a</li><li>Error occurred in path b</li></ul>'
       });
     }));
+
+    it('should remove a single notification', fakeAsync(() => {
+      addNotifications(5);
+      let messages = service['dataSource'].getValue().map((notification) => notification.title);
+      expect(messages).toEqual(['4', '3', '2', '1', '0']);
+      service.remove(2);
+      messages = service['dataSource'].getValue().map((notification) => notification.title);
+      expect(messages).toEqual(['4', '3', '1', '0']);
+    }));
+
+    it('should remove all notifications', fakeAsync(() => {
+      addNotifications(5);
+      expect(service['dataSource'].getValue().length).toBe(5);
+      service.removeAll();
+      expect(service['dataSource'].getValue().length).toBe(0);
+    }));
   });
 
   describe('notification queue', () => {
index 4a4356c83730e2e5d0f16b1aaaacb7d3bb126946..9f9c5e36bc819aaa6ac773eb7c7e742f33f59f92 100644 (file)
@@ -55,14 +55,25 @@ export class NotificationService {
     this.dataSource.next([]);
   }
 
+  /**
+   * Removes a single saved notifications
+   */
+  remove(index: number) {
+    const recent = this.dataSource.getValue();
+    recent.splice(index, 1);
+    this.dataSource.next(recent);
+    localStorage.setItem(this.KEY, JSON.stringify(recent));
+  }
+
   /**
    * Method used for saving a shown notification (check show() method).
    */
   save(notification: CdNotification) {
     const recent = this.dataSource.getValue();
     recent.push(notification);
+    recent.sort((a, b) => (a.timestamp > b.timestamp ? -1 : 1));
     while (recent.length > 10) {
-      recent.shift();
+      recent.pop();
     }
     this.dataSource.next(recent);
     localStorage.setItem(this.KEY, JSON.stringify(recent));
index 8bb8dd7a0c277e7531f60c928f76f63c5632f217..b5b4cec92599a7acc58a1995dc31d6f6a94caad5 100644 (file)
@@ -320,7 +320,7 @@ a {
 }
 .custom-icon {
   padding: 10px;
-  margin-right: 1em;
+  margin-right: 8px;
   background-clip: padding-box;
   background-size: contain;
   background-repeat: no-repeat;