Skip to content

Commit

Permalink
resolve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Jun 11, 2024
1 parent fdbd8f0 commit ffc8539
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
20 changes: 7 additions & 13 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,13 @@ export class ApiService {
private readonly login: LoginService,
) {
// show recording archives when recordings available
this.login
.getSessionState()
.pipe(
concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.doGet('recordings') : EMPTY)),
)
.subscribe({
next: () => {
this.archiveEnabled.next(true);
},
error: () => {
this.archiveEnabled.next(false);
},
});
this.doGet('recordings').pipe(
tap(() => this.archiveEnabled.next(true)),
catchError(() => {
this.archiveEnabled.next(false);
return EMPTY;
})
).subscribe();

const getDatasourceURL: Observable<GrafanaDatasourceUrlGetResponse> = fromFetch(
`${this.login.authority}/api/v1/grafana_datasource_url`,
Expand Down
4 changes: 2 additions & 2 deletions src/app/Shared/Services/Login.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import type { SettingsService } from './Settings.service';
export class LoginService {
private readonly logout = new ReplaySubject<void>(1);
private readonly username = new ReplaySubject<string>(1);
private readonly sessionState = new ReplaySubject<SessionState>(SessionState.CREATING_USER_SESSION);
private readonly sessionState = new ReplaySubject<SessionState>(1);
readonly authority: string;

constructor(private readonly settings: SettingsService) {
this.authority = process.env.CRYOSTAT_AUTHORITY || '.';
this.sessionState.next(SessionState.CREATING_USER_SESSION);

fromFetch(`${this.authority}/api/v2.1/auth`, {
credentials: 'include',
Expand All @@ -46,7 +47,6 @@ export class LoginService {
)
.subscribe((v) => {
this.username.next(v?.data?.result?.username ?? '');
this.sessionState.next(SessionState.USER_SESSION);
});
}

Expand Down
13 changes: 9 additions & 4 deletions src/app/Shared/Services/NotificationChannel.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ export class NotificationChannel {
});
});

combineLatest([this.login.getSessionState(), this._ready, timer(0, 5000)])
combineLatest([this.login.getSessionState(), timer(0, 5000)])
.pipe(distinctUntilChanged(_.isEqual))
.subscribe({
next: ([sessionState, readyState]) => {
if (sessionState === SessionState.NO_USER_SESSION || readyState.ready) {
next: (parts: string[]) => {
const sessionState = parseInt(parts[0]);

if (sessionState !== SessionState.CREATING_USER_SESSION) {
return;
}

Expand All @@ -84,7 +86,10 @@ export class NotificationChannel {
url: url.toString(),
protocol: '',
openObserver: {
next: () => this._ready.next({ ready: true }),
next: () => {
this._ready.next({ ready: true });
this.login.setSessionState(SessionState.USER_SESSION);
},
},
closeObserver: {
next: (evt) => {
Expand Down
9 changes: 3 additions & 6 deletions src/app/Shared/Services/Targets.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,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) {
Expand Down

0 comments on commit ffc8539

Please sign in to comment.