]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix notification re-navigation when already on page
authorAfreen Misbah <afreen@ibm.com>
Wed, 22 Jul 2026 12:04:39 +0000 (17:34 +0530)
committerAfreen Misbah <afreen@ibm.com>
Wed, 22 Jul 2026 12:04:39 +0000 (17:34 +0530)
When a notification is clicked in the panel while the user is already
on the notifications page, the selected notification now updates
correctly by bypassing the preselect guard for query param changes.

Signed-off-by: Afreen Misbah <afreen@ibm.com>
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.ts

index 1a5f450bca508d126b6e3f63d594bc6f4c45888a..f65a1cb41bfe8ac145895af006792930fd4c5de6 100644 (file)
@@ -347,6 +347,17 @@ describe('NotificationsPageComponent', () => {
       expect(component.selectedNotificationID()).toBe('1');
     });
 
+    it('should re-select when query params change while a notification is already selected', () => {
+      queryParamsSubject.next({ id: '1' });
+      fixture.detectChanges();
+      expect(component.selectedNotificationID()).toBe('1');
+
+      queryParamsSubject.next({ id: '2' });
+      fixture.detectChanges();
+      expect(component.selectedNotificationID()).toBe('2');
+      expect(notificationService.markAsRead).toHaveBeenCalledWith('2');
+    });
+
     it('should pre-select when navigating from toast view more link', () => {
       dataSourceSubject.next(mockNotifications);
       fixture.detectChanges();
index 6d79b123d0686798dd87b60f60dff40392365a65..89401784a2a394c007898f60b96e60555994f09e 100644 (file)
@@ -88,7 +88,7 @@ export class NotificationsPageComponent implements OnInit, OnDestroy {
     this.sub.add(
       this.route.queryParams.subscribe((params) => {
         this._pendingId = params['id'] || null;
-        this._tryPreselect(this.notificationService.getNotificationsSnapshot());
+        this._tryPreselect(this.notificationService.getNotificationsSnapshot(), true);
       })
     );
   }
@@ -133,8 +133,8 @@ export class NotificationsPageComponent implements OnInit, OnDestroy {
     }
   }
 
-  private _tryPreselect(notifications: CdNotification[]): void {
-    if (!this._pendingId || this.selectedNotificationID()) return;
+  private _tryPreselect(notifications: CdNotification[], force = false): void {
+    if (!this._pendingId || (!force && this.selectedNotificationID())) return;
     const match = notifications.find((n) => n.id === this._pendingId);
     if (match) {
       this.selectedNotificationID.set(this._pendingId);