Skip to content

Commit

Permalink
Merge branch 'development' into e2e-bring-back-skipped-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Obadha committed Sep 16, 2024
2 parents 9a2238a + 556b903 commit 47ed3f5
Show file tree
Hide file tree
Showing 37 changed files with 17,662 additions and 3,607 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { CanActivate, Router, UrlTree } from '@angular/router';
import { SessionService } from '@services';
import { filter, Observable, switchMap, take } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class DeploymentFoundGuard implements CanActivate {
constructor(private router: Router, private service: SessionService) {}

canActivate() {
const siteFound: boolean = this.service.siteFound;
if (siteFound) {
return true;
}
return this.router.parseUrl('/notfound');
canActivate(): Observable<boolean | UrlTree> {
return this.service.configLoaded$.pipe(
filter((configLoaded) => configLoaded !== undefined),
take(1),
switchMap((configLoaded) => {
const siteFound: boolean = this.service.siteFound;
if (configLoaded && siteFound) {
return [true];
}
return [this.router.parseUrl('/notfound')];
}),
);
}
}
6 changes: 4 additions & 2 deletions apps/web-mzima-client/src/app/core/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export class ConfigService {
});
return data.result;
},
error: () => {
setTimeout(() => this.getConfig(), 5000);
error: (error) => {
if (error.status === 404 && error.error.errors[0].message === 'Deployment not found')
this.sessionService.configLoaded = false;
else setTimeout(() => this.getConfig(), 5000);
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export class SessionService {
private readonly _isFiltersVisible = new BehaviorSubject<boolean>(false);
private readonly _isMainFiltersHidden = new BehaviorSubject<boolean>(false);
private readonly _deploymentInfo = new BehaviorSubject<any>(false);
private readonly _configLoaded = new BehaviorSubject<boolean>(false);

readonly currentUserData$: Observable<UserInterface> = this._currentUserData$.asObservable();
readonly isFiltersVisible$ = this._isFiltersVisible.asObservable();
readonly isMainFiltersHidden$ = this._isMainFiltersHidden.asObservable();
readonly deploymentInfo$ = this._deploymentInfo.asObservable();
readonly configLoaded$ = this._configLoaded.asObservable();

private currentSessionData: SessionTokenInterface = {
accessToken: '',
Expand Down Expand Up @@ -102,6 +104,7 @@ export class SessionService {
private: this.currentConfig['site']?.private ?? false,
email: this.currentConfig['site']?.email ?? '',
});
this.configLoaded = true;
}

loadSessionDataFromLocalStorage() {
Expand Down Expand Up @@ -144,6 +147,10 @@ export class SessionService {
);
}

set configLoaded(configLoaded: boolean) {
this._configLoaded.next(configLoaded);
}

get currentAuthTokenType() {
return this.currentSessionData.tokenType;
}
Expand Down
Loading

0 comments on commit 47ed3f5

Please sign in to comment.