feat(#5504): customizable browser notifications - #5584
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurability and richer UX to Spring Boot Admin UI browser notifications by exposing a server-side timeout setting to the frontend and using it when creating Notification instances, plus enabling click-through navigation to instance details when a status change can be attributed to a single instance.
Changes:
- Introduces
spring.boot.admin.ui.browser-notification-timeout(default 5000ms;0disables auto-dismiss) and wires it intoUiController.Settings. - Frontend: uses the configured timeout (instead of a hardcoded 5s) and adds logic to derive a single affected instance for click navigation.
- Adds Vitest coverage for URL/id selection helpers and a Spring MVC test asserting settings exposure.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java | Adds a test to ensure the browser notification timeout is present in uiSettings model. |
| spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java | Extends UiController.Settings with browserNotificationTimeout. |
| spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiProperties.java | Adds the new configuration property with default (5000ms) and Javadoc. |
| spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java | Maps the new property into UiController.Settings. |
| spring-boot-admin-server-ui/src/main/frontend/sba-config.ts | Adds browserNotificationTimeout to the default UI settings config. |
| spring-boot-admin-server-ui/src/main/frontend/notifications.ts | Uses configured timeout and adds click-to-open-instance-details behavior. |
| spring-boot-admin-server-ui/src/main/frontend/notifications.spec.ts | Adds unit tests for helper functions introduced in notifications.ts. |
| spring-boot-admin-server-ui/src/main/frontend/global.d.ts | Extends the UISettings type with browserNotificationTimeout. |
| import { HealthStatus } from './HealthStatus'; | ||
| import Application from './services/application'; | ||
| import sbaConfig from './sba-config'; | ||
|
|
||
| let granted = false; | ||
|
|
||
| type BrowserNotificationOptions = NotificationOptions & { | ||
| timeout?: number; | ||
| url?: string; | ||
| }; | ||
|
|
||
| export const buildInstanceDetailsUrl = (instanceId: string) => | ||
| `/instances/${instanceId}/details`; |
| it('builds instance details path', () => { | ||
| expect(buildInstanceDetailsUrl('abc123')).toBe('/instances/abc123/details'); | ||
| }); |
…eout property Define browser-notification-timeout as Duration in AdminServerUiProperties and convert to milliseconds when building UiController.Settings.
….MILLIS Address review feedback: pass milliseconds as long to the UI, annotate the property with @DurationUnit(MILLIS), and document that <= 0 disables auto-dismiss.
Use requireInteraction when timeout <= 0 so the browser does not auto-dismiss, and only schedule close when timeout > 0.
b3d9e3f to
77a040e
Compare
| const notification = new window.Notification(title, { | ||
| ...notificationOptions, | ||
| // Keep visible until the user dismisses when timeout is <= 0 | ||
| requireInteraction: !(timeout > 0), |
There was a problem hiding this comment.
| requireInteraction: !(timeout > 0), | |
| requireInteraction: timeout <= 0, |
| notification.onshow = () => | ||
| setTimeout(() => notification.close(), options.timeout); | ||
| } | ||
| notification.onshow = () => { |
There was a problem hiding this comment.
The previous code was actually more performant since it doesn't attach a listener if it's not needed.
I think I misread onshow with just show when I suggested to move the if inside. My bad.
| notification.onclick = () => { | ||
| window.focus(); | ||
| window.open(options.url, '_self'); | ||
| window.open(url, '_self'); |
There was a problem hiding this comment.
@SteKoe @ulischulte should we use https://developer.mozilla.org/en-US/docs/Web/API/Notification/navigate maybe?
Summary
spring.boot.admin.ui.browser-notification-timeout(default 5000ms;0disables auto-dismiss)Test plan
browser-notification-timeout: 0— notification stays until dismissedbrowser-notification-timeout: 10000— notification auto-dismisses after 10s/instances/{id}/detailsnpm test -- --run notifications.spec.tspasses