From d143a8ba836004575ddb250918c65194145676e2 Mon Sep 17 00:00:00 2001 From: Atif Ali <56743004+aali309@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:14:14 -0400 Subject: [PATCH] fix(Targets): Target list fails to populate if WebSocket connection is not established (#1276) Co-authored-by: Andrew Azores --- src/app/Shared/Services/Api.service.tsx | 34 ++++++++++++--------- src/app/Shared/Services/Targets.service.tsx | 14 +++------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index d216b9745..c62f10c0d 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -17,7 +17,18 @@ import { LayoutTemplate, SerialLayoutTemplate } from '@app/Dashboard/types'; import { createBlobURL } from '@app/utils/utils'; import { ValidatedOptions } from '@patternfly/react-core'; -import { EMPTY, forkJoin, from, Observable, ObservableInput, of, ReplaySubject, shareReplay, throwError } from 'rxjs'; +import { + BehaviorSubject, + EMPTY, + forkJoin, + from, + Observable, + ObservableInput, + of, + ReplaySubject, + shareReplay, + throwError, +} from 'rxjs'; import { fromFetch } from 'rxjs/fetch'; import { catchError, concatMap, filter, first, map, mergeMap, tap } from 'rxjs/operators'; import { @@ -66,11 +77,10 @@ import { import { isHttpError, includesTarget, isHttpOk, isXMLHttpError } from './api.utils'; import { LoginService } from './Login.service'; import { NotificationService } from './Notifications.service'; -import { SessionState } from './service.types'; import { TargetService } from './Target.service'; export class ApiService { - private readonly archiveEnabled = new ReplaySubject(1); + private readonly archiveEnabled = new BehaviorSubject(true); private readonly cryostatVersionSubject = new ReplaySubject(1); private readonly grafanaDatasourceUrlSubject = new ReplaySubject(1); private readonly grafanaDashboardUrlSubject = new ReplaySubject(1); @@ -80,20 +90,14 @@ export class ApiService { private readonly notifications: NotificationService, private readonly login: LoginService, ) { - // show recording archives when recordings available - this.login - .getSessionState() + this.doGet('recordings') .pipe( - concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.doGet('recordings') : EMPTY)), - ) - .subscribe({ - next: () => { - this.archiveEnabled.next(true); - }, - error: () => { + catchError(() => { this.archiveEnabled.next(false); - }, - }); + return EMPTY; + }), + ) + .subscribe(); const getDatasourceURL: Observable = fromFetch( `${this.login.authority}/api/v1/grafana_datasource_url`, diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index e5134319d..516d2f99f 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -15,14 +15,13 @@ */ import _ from 'lodash'; -import { Observable, BehaviorSubject, of, EMPTY } from 'rxjs'; -import { catchError, concatMap, first, map, tap } from 'rxjs/operators'; +import { Observable, BehaviorSubject, of } from 'rxjs'; +import { catchError, first, map, tap } from 'rxjs/operators'; import { ApiService } from './Api.service'; import { Target, NotificationCategory, TargetDiscoveryEvent } from './api.types'; import { LoginService } from './Login.service'; import { NotificationChannel } from './NotificationChannel.service'; import { NotificationService } from './Notifications.service'; -import { SessionState } from './service.types'; export class TargetsService { private readonly _targets$: BehaviorSubject = new BehaviorSubject([]); @@ -33,12 +32,9 @@ export class TargetsService { login: LoginService, notificationChannel: NotificationChannel, ) { - login - .getSessionState() - .pipe(concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.queryForTargets() : EMPTY))) - .subscribe(() => { - // just trigger a startup query - }); + // just trigger a startup query + this.queryForTargets().subscribe(); + notificationChannel.messages(NotificationCategory.TargetJvmDiscovery).subscribe((v) => { const evt: TargetDiscoveryEvent = v.message.event; switch (evt.kind) {