From: Afreen Misbah Date: Wed, 22 Jul 2026 12:04:39 +0000 (+0530) Subject: mgr/dashboard: fix notification re-navigation when already on page X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a1a70d06f4eade9b0ec0e939df418875ca425092;p=ceph.git mgr/dashboard: fix notification re-navigation when already on page 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 --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.spec.ts index 1a5f450bca50..f65a1cb41bfe 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.spec.ts @@ -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(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.ts index 6d79b123d068..89401784a2a3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/notification-panel/notifications-page/notifications-page.component.ts @@ -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);