diff --git a/src/app/Shared/Services/NotificationChannel.service.tsx b/src/app/Shared/Services/NotificationChannel.service.tsx index 954c8ab29..5b99610de 100644 --- a/src/app/Shared/Services/NotificationChannel.service.tsx +++ b/src/app/Shared/Services/NotificationChannel.service.tsx @@ -43,6 +43,8 @@ import { webSocket, WebSocketSubject } from 'rxjs/webSocket'; import { AlertVariant } from '@patternfly/react-core'; import { concatMap, distinctUntilChanged, filter } from 'rxjs/operators'; import { AuthMethod, LoginService, SessionState } from './Login.service'; +import { Target } from './Target.service'; +import { TargetDiscoveryEvent } from './Targets.service'; export enum NotificationCategory { WsClientActivity = 'WsClientActivity', @@ -75,22 +77,31 @@ interface ReadyState { export const messageKeys = new Map([ [ - // explicitly configure this category with a null mapper. - // This is a special case because we do not want to display an alert, - // the Targets.service already handles this - NotificationCategory.TargetJvmDiscovery, { - variant: AlertVariant.info, - title: 'Target JVM Discovery', - }, - ], - [ - // explicitly configure this category with a null mapper. + // explicitly configure this category with a null message body mapper. // This is a special case because this is generated client-side, // not sent by the backend NotificationCategory.GrafanaConfiguration, { title: 'Grafana Configuration', }, ], + [ + NotificationCategory.TargetJvmDiscovery, { + variant: AlertVariant.info, + title: 'Target JVM Discovery', + body: v => { + const evt: TargetDiscoveryEvent = v.message.event; + const target: Target = evt.serviceRef; + switch (evt.kind) { + case 'FOUND': + return `Target "${target.alias}" appeared (${target.connectUrl})"`; + case 'LOST': + return `Target "${target.alias}" disappeared (${target.connectUrl})"`; + default: + return `Received a notification with category ${NotificationCategory.TargetJvmDiscovery} and unrecognized kind ${evt.kind}`; + } + } + } as NotificationMessageMapper, + ], [ NotificationCategory.WsClientActivity, { variant: AlertVariant.info, diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index e2d247466..552c44c22 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -56,7 +56,7 @@ export class TargetsService { constructor( private readonly api: ApiService, private readonly notifications: Notifications, - private readonly login: LoginService, + login: LoginService, notificationChannel: NotificationChannel, ) { login.getSessionState().pipe( @@ -68,18 +68,14 @@ export class TargetsService { notificationChannel.messages(NotificationCategory.TargetJvmDiscovery) .subscribe(v => { const evt: TargetDiscoveryEvent = v.message.event; - const target: Target = evt.serviceRef; switch (evt.kind) { case 'FOUND': this._targets$.next(_.unionBy(this._targets$.getValue(), [evt.serviceRef], t => t.connectUrl)); - notifications.info('Target Appeared', `Target "${target.alias}" appeared (${target.connectUrl})"`, NotificationCategory.TargetJvmDiscovery); break; case 'LOST': this._targets$.next(_.filter(this._targets$.getValue(), t => t.connectUrl !== evt.serviceRef.connectUrl)); - notifications.info('Target Disappeared', `Target "${target.alias}" disappeared (${target.connectUrl})"`, NotificationCategory.TargetJvmDiscovery); break; default: - notifications.danger(`Invalid Message Received`, `Received a notification with category ${NotificationCategory.TargetJvmDiscovery} and unrecognized kind ${evt.kind}`); break; } });