Skip to content

Commit

Permalink
feat: added config option to enable/disable the dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilczaja committed Nov 26, 2024
1 parent a8ecec3 commit 57fb67b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions authority-portal-frontend/.env.local-dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ AUTHORITY_PORTAL_FRONTEND_SUPPORT_URL=https://support-url
AUTHORITY_PORTAL_FRONTEND_ACTIVE_PROFILE=sovity-open-source
AUTHORITY_PORTAL_FRONTEND_DATASPACE_SHORT_NAME=sovity Dataspace
AUTHORITY_PORTAL_FRONTEND_PORTAL_DISPLAY_NAME=Authority Portal
AUTHORITY_PORTAL_FRONTEND_ENABLE_DASHBOARD=true
1 change: 1 addition & 0 deletions authority-portal-frontend/.env.local-e2e-dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ AUTHORITY_PORTAL_FRONTEND_SUPPORT_URL=https://support.mobility-dataspace.eu
AUTHORITY_PORTAL_FRONTEND_ACTIVE_PROFILE=sovity-open-source
AUTHORITY_PORTAL_FRONTEND_BRAND_SHORT_NAME=sovity
AUTHORITY_PORTAL_FRONTEND_PORTAL_DISPLAY_NAME=Authority Portal
AUTHORITY_PORTAL_FRONTEND_ENABLE_DASHBOARD=true
19 changes: 11 additions & 8 deletions authority-portal-frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ export const HOME_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({
pathMatch: 'full',
}));

export const FEATURE_DASHBOARD_ROUTE: Routes = [
{
path: 'dashboard',
component: DashboardPageComponent,
data: {
requiresRole: ['USER'] satisfies UserRoleDto[],
},
canActivate: [requiresRole],
},
];

export const AUTHORITY_PORTAL_ROUTES: Routes = [
// participant own connector registration
{
Expand Down Expand Up @@ -149,14 +160,6 @@ export const AUTHORITY_PORTAL_ROUTES: Routes = [
path: '',
component: PortalLayoutComponent,
children: [
{
path: 'dashboard',
component: DashboardPageComponent,
data: {
requiresRole: ['USER'] satisfies UserRoleDto[],
},
canActivate: [requiresRole],
},
{
path: 'catalog',
component: CatalogPageComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Fetched} from 'src/app/core/utils/fetched';
import {
AUTHORITY_PORTAL_ROUTES,
CATALOG_REDIRECTS,
FEATURE_DASHBOARD_ROUTE,
FEATURE_HOME_ROUTE,
HOME_REDIRECTS,
LOADING_ROUTES,
Expand Down Expand Up @@ -86,11 +87,18 @@ export class RouteConfigService {

if (nextPageSet === 'AUTHORITY_PORTAL') {
const apRouteChildren = routes.find((r) => r.path === '')?.children;

// Add home route depending on feature set
if (this.activeFeatureSet.isHomePageEnabled()) {
apRouteChildren?.push(...HOME_REDIRECTS, ...FEATURE_HOME_ROUTE);
} else {
apRouteChildren?.push(...CATALOG_REDIRECTS);
}

// Add additional routes depending on feature set & configuration
if (this.activeFeatureSet.isDashboardEnabled()) {
apRouteChildren?.push(...FEATURE_DASHBOARD_ROUTE);
}
}

this.router.resetConfig(routes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class ActiveFeatureSet {
return this.has('enable-home');
}

// This is configurable via environment variable, not via theme
isDashboardEnabled(): boolean {
return this.config.enableDashboard;
}

has(feature: UiFeature): boolean {
return this.config.features.has(feature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {UiLogo} from './profiles/ui-logo';
import {UiProfile} from './profiles/ui-profile';

export const APP_CONFIG = new InjectionToken<AppConfig>('APP_CONFIG');

/**
* App Config
*
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface AppConfig {
useLocalBackend: boolean;
brandDataspaceName: string;
portalName: string;
enableDashboard: boolean;
}

/**
Expand All @@ -78,6 +80,7 @@ export interface AppConfigEnv {
AUTHORITY_PORTAL_FRONTEND_ACTIVE_PROFILE: string;
AUTHORITY_PORTAL_FRONTEND_DATASPACE_SHORT_NAME: string;
AUTHORITY_PORTAL_FRONTEND_PORTAL_DISPLAY_NAME: string;
AUTHORITY_PORTAL_FRONTEND_ENABLE_DASHBOARD: string;
}

/**
Expand Down Expand Up @@ -109,5 +112,7 @@ export function buildAppConfig(envVars: AppConfigEnv): AppConfig {
supportUrl: envVars.AUTHORITY_PORTAL_FRONTEND_SUPPORT_URL,
brandDataspaceName: envVars.AUTHORITY_PORTAL_FRONTEND_DATASPACE_SHORT_NAME,
portalName: envVars.AUTHORITY_PORTAL_FRONTEND_PORTAL_DISPLAY_NAME,
enableDashboard:
envVars.AUTHORITY_PORTAL_FRONTEND_ENABLE_DASHBOARD === 'true',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class SidebarComponent implements OnInit, OnDestroy {
title: 'Dashboard',
icon: 'dashboard',
rLink: '/dashboard',
isDisabled: !this.activeFeatureSet.isDashboardEnabled(),
},
],
},
Expand Down

0 comments on commit 57fb67b

Please sign in to comment.