Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3.x] fix(console): Left menu unclickable after redirection from tasks #10666

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions gravitee-apim-console-webui/src/management/environment.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivateFn, CanDeactivateFn, Router, RouterStateSnapshot } from '@angular/router';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, tap } from 'rxjs/operators';
import { of } from 'rxjs';
import { GioMenuSearchService } from '@gravitee/ui-particles-angular';
import { get } from 'lodash';

Expand All @@ -40,15 +41,17 @@ export const EnvironmentGuard: {
const gioMenuSearchService = inject(GioMenuSearchService);
const settingsNavigationService = inject(SettingsNavigationService);

const paramEnv = route.params.envHrid;
const paramEnv = route.params.envHrid.toLowerCase();
let currentEnvironment = null;

return environmentService.list().pipe(
map((environments) => {
switchMap((environments) => {
if (!environments || environments.length === 0) {
throw new Error('No environment found!');
}

const currentEnvironment = environments.find((e) => e.id === paramEnv || e.hrids?.includes(paramEnv));
currentEnvironment = environments.find((e) => e.id.toLowerCase() === paramEnv || e.hrids?.includes(paramEnv));

// Redirect to first environment if no environment is found
if (!currentEnvironment) {
const hrid = get(environments[0], 'hrids[0]');
Expand All @@ -58,20 +61,28 @@ export const EnvironmentGuard: {
constants.org.environments = environments;
constants.org.currentEnv = currentEnvironment;

if (paramEnv === currentEnvironment.id && currentEnvironment.hrids?.length > 0) {
// Replace environment ID by hrid but keep url path
router.navigateByUrl(state.url.replace(currentEnvironment.id, currentEnvironment.hrids[0]));
}
return of(currentEnvironment.id);
}),
// Load permissions
switchMap(() => gioPermissionService.loadEnvironmentPermissions(paramEnv)),
switchMap((envId) => {
return gioPermissionService.loadEnvironmentPermissions(envId);
}),
// Load env settings
switchMap(() => environmentSettingsService.load()),
// Load search items in menu
map(() => {
gioMenuSearchService.addMenuSearchItems(settingsNavigationService.getSettingsNavigationSearchItems(route.params.envHrid));
return true;
}),
tap(() => {
if (paramEnv === currentEnvironment.id.toLowerCase() && currentEnvironment.hrids?.length > 0) {
// Replace environment ID by hrid but keep url path and navigate
const target = state.url.replace(new RegExp(currentEnvironment.id, 'i'), currentEnvironment.hrids[0]);
if (target !== state.url) {
router.navigateByUrl(target);
}
}
}),
);
},

Expand Down