Skip to content

Commit

Permalink
test: refactored route-config-service
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Nov 26, 2024
1 parent bf3cb1e commit feb69fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
22 changes: 11 additions & 11 deletions authority-portal-frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,6 @@ export const LOADING_ROUTES: Routes = [
},
];

export const FEATURE_HOME_ROUTE: Routes = [
{
path: 'home',
component: HomePageComponent,
data: {
requiresRole: ['USER'] satisfies UserRoleDto[],
},
canActivate: [requiresRole],
},
];

const REDIRECT_TO_HOME: string[] = [
'',
'registration/pending',
Expand All @@ -110,6 +99,17 @@ export const HOME_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({
pathMatch: 'full',
}));

export const FEATURE_HOME_ROUTE: Routes = [
{
path: 'home',
component: HomePageComponent,
data: {
requiresRole: ['USER'] satisfies UserRoleDto[],
},
canActivate: [requiresRole],
},
];

export const AUTHORITY_PORTAL_ROUTES: Routes = [
// participant own connector registration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ export class RouteConfigService {
}

// Change routes
const routes = this.mapping[nextPageSet];
const routes = [...this.mapping[nextPageSet]];

if (nextPageSet === 'AUTHORITY_PORTAL') {
const apRouteChildren = routes.find((r) => r.path === '')?.children;
if (this.activeFeatureSet.isHomePageEnabled()) {
apRouteChildren?.push(...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE);
} else {
apRouteChildren?.push(...CATALOG_REDIRECTS);
const rootRouteIndex = routes.findIndex((r) => r.path === '');

if (rootRouteIndex !== -1) {
const rootRoute = routes[rootRouteIndex];
const existingChildren = rootRoute.children || [];
const newChildren = this.activeFeatureSet.isHomePageEnabled()
? [...existingChildren, ...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE]
: [...existingChildren, ...CATALOG_REDIRECTS];

routes[rootRouteIndex] = {
...rootRoute,
children: newChildren,
};
}
}

Expand Down

0 comments on commit feb69fa

Please sign in to comment.