Skip to content

Commit

Permalink
refactor: Add separate provide functions for optional features (#386)
Browse files Browse the repository at this point in the history
* Teams, Audit, Admin and Help UI moved to seperate provide functions.
* This makes it easier to disable feature functionality if not needed by a downstream project.
  • Loading branch information
jrassa authored Jun 3, 2024
1 parent 5a6b1cd commit 473528f
Show file tree
Hide file tree
Showing 25 changed files with 259 additions and 160 deletions.
19 changes: 13 additions & 6 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { TooltipModule } from 'ngx-bootstrap/tooltip';

import { provideCdkDialog } from './common/dialog/provider';
import { provideAdminFeature } from './core/admin';
import { provideAuditFeature } from './core/audit';
import { authInterceptor } from './core/auth/auth.interceptor';
import { euaInterceptor } from './core/auth/eua.interceptor';
import { signinInterceptor } from './core/auth/signin.interceptor';
import { CORE_ROUTES } from './core/core-routes';
import { provideHelpFeature } from './core/help';
import { masqueradeInterceptor } from './core/masquerade/masquerade.interceptor';
import { PageTitleStrategy } from './core/page-title.strategy';
import {
provideAppConfig,
provideCoreRoutes,
provideNavigationService,
provideSession,
provideViewportScroller
} from './core/provider';
import { provideExampleRoutes } from './site/example/provider';
import { provideTeamsFeature } from './core/teams/provider';
import { provideExampleSiteFeature } from './site/example/provider';

export const appConfig: ApplicationConfig = {
providers: [
Expand All @@ -43,20 +47,23 @@ export const appConfig: ApplicationConfig = {
),
provideCdkDialog(),
provideRouter(
[],
CORE_ROUTES,
withHashLocation(),
withInMemoryScrolling({ scrollPositionRestoration: 'enabled' }),
withComponentInputBinding()
),
provideViewportScroller(),
provideCoreRoutes(),
provideExampleRoutes(),
provideAppConfig(),
provideNavigationService(),
provideSession(),
{
provide: TitleStrategy,
useClass: PageTitleStrategy
}
},
provideAuditFeature(),
provideTeamsFeature(),
provideAdminFeature(),
provideHelpFeature(),
provideExampleSiteFeature()
]
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { LoadingOverlayComponent } from './loading-overlay.component';

Expand Down
11 changes: 1 addition & 10 deletions src/app/common/table/column-chooser/column-chooser.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import {
moveItemInArray
} from '@angular/cdk/drag-drop';
import { TitleCasePipe } from '@angular/common';
import {
Component,
EventEmitter,
Input,
OnInit,
Output,
booleanAttribute,
input,
output
} from '@angular/core';
import { Component, Input, OnInit, booleanAttribute, input, output } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { LocalStorageService } from '../../storage/local-storage.service';
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/table/filter/asy-filter.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, Input, input } from '@angular/core';
import { Directive, input } from '@angular/core';

import isEmpty from 'lodash/isEmpty';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { A11yModule } from '@angular/cdk/a11y';
import { CdkConnectedOverlay, CdkOverlayOrigin, OverlayModule } from '@angular/cdk/overlay';
import { NgClass } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Inject,
Optional,
effect,
signal
} from '@angular/core';
import { ChangeDetectionStrategy, Component, Inject, Optional, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { NgSelectModule } from '@ng-select/ng-select';
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/admin/admin-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Routes } from '@angular/router';

import { EXAMPLE_ADMIN_ROUTES } from '../../site/example/admin/admin-routes';
import { authGuard } from '../auth';
import { AdminComponent } from './admin.component';
import { ADMIN_CACHE_ENTRIES_ROUTES } from './cache-entries/admin-cache-entries-routes';
Expand All @@ -26,7 +27,8 @@ export const ADMIN_ROUTES: Routes = [
...ADMIN_CACHE_ENTRIES_ROUTES,
...ADMIN_EUA_ROUTES,
...ADMIN_MESSAGES_ROUTES,
...ADMIN_FEEDBACK_ROUTES
...ADMIN_FEEDBACK_ROUTES,
...EXAMPLE_ADMIN_ROUTES
]
}
];
1 change: 1 addition & 0 deletions src/app/core/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
66 changes: 66 additions & 0 deletions src/app/core/admin/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { InjectionToken, inject, makeEnvironmentProviders } from '@angular/core';
import { ROUTES } from '@angular/router';

import { ADMIN_TOPICS } from './admin-topic.model';

export const APP_FEATURE_ADMIN = new InjectionToken<boolean>('APP_FEATURE_ADMIN');

export function injectAdminEnabled() {
return inject(APP_FEATURE_ADMIN, { optional: true }) ?? false;
}

export function provideAdminFeature() {
return makeEnvironmentProviders([
{
provide: APP_FEATURE_ADMIN,
useValue: true
},
{
provide: ADMIN_TOPICS,
multi: true,
useValue: [
{
id: 'users',
title: 'Users',
ordinal: 0,
path: 'users'
},

{
id: 'cache-entries',
title: 'Cache Entries',
ordinal: 1,
path: 'cacheEntries'
},
{
id: 'end-user-agreements',
title: 'EUAs',
ordinal: 2,
path: 'euas'
},
{
id: 'messages',
title: 'Messages',
ordinal: 3,
path: 'messages'
},
{
id: 'feedback',
title: 'Feedback',
ordinal: 4,
path: 'feedback'
}
]
},
{
provide: ROUTES,
multi: true,
useValue: [
{
path: 'admin',
loadChildren: () => import('./admin-routes').then((m) => m.ADMIN_ROUTES)
}
]
}
]);
}
1 change: 1 addition & 0 deletions src/app/core/admin/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './provider';
1 change: 1 addition & 0 deletions src/app/core/audit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
27 changes: 27 additions & 0 deletions src/app/core/audit/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { InjectionToken, inject, makeEnvironmentProviders } from '@angular/core';
import { ROUTES } from '@angular/router';

export const APP_FEATURE_AUDIT = new InjectionToken<boolean>('APP_FEATURE_AUDIT');

export function injectAuditEnabled() {
return inject(APP_FEATURE_AUDIT, { optional: true }) ?? false;
}

export function provideAuditFeature() {
return makeEnvironmentProviders([
{
provide: APP_FEATURE_AUDIT,
useValue: true
},
{
provide: ROUTES,
multi: true,
useValue: [
{
path: 'audit',
loadChildren: () => import('./audit-routes').then((m) => m.AUDIT_ROUTES)
}
]
}
]);
}
1 change: 1 addition & 0 deletions src/app/core/audit/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './provider';
16 changes: 0 additions & 16 deletions src/app/core/core-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,5 @@ export const CORE_ROUTES: Routes = [
{
path: 'masquerade',
component: MasqueradeComponent
},
{
path: 'team',
loadChildren: () => import('./teams/teams-routes').then((m) => m.TEAMS_ROUTES)
},
{
path: 'help',
loadChildren: () => import('./help/help-routes').then((m) => m.HELP_ROUTES)
},
{
path: 'admin',
loadChildren: () => import('./admin/admin-routes').then((m) => m.ADMIN_ROUTES)
},
{
path: 'audit',
loadChildren: () => import('./audit/audit-routes').then((m) => m.AUDIT_ROUTES)
}
];
5 changes: 0 additions & 5 deletions src/app/core/help/help.component.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
@use 'sass:map';
@import '../../../styles/shared';
@import '../../../styles/bootstrap/shared';

.help-content {
padding-top: $site-content-padding-y;
}

//=====================================
// Callouts
//=====================================
Expand Down
1 change: 1 addition & 0 deletions src/app/core/help/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
42 changes: 42 additions & 0 deletions src/app/core/help/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { InjectionToken, inject, makeEnvironmentProviders } from '@angular/core';
import { ROUTES } from '@angular/router';

import { GettingStartedHelpComponent } from './getting-started/getting-started-help.component';
import { HELP_TOPICS } from './help-topic.component';

export const APP_FEATURE_HELP = new InjectionToken<boolean>('APP_FEATURE_HELP');

export function injectHelpEnabled() {
return inject(APP_FEATURE_HELP, { optional: true }) ?? false;
}

export function provideHelpFeature() {
return makeEnvironmentProviders([
{
provide: APP_FEATURE_HELP,
useValue: true
},
{
provide: HELP_TOPICS,
multi: true,
useValue: [
{
id: 'getting-started',
title: 'Getting Started',
ordinal: 0,
component: GettingStartedHelpComponent
}
]
},
{
provide: ROUTES,
multi: true,
useValue: [
{
path: 'help',
loadChildren: () => import('./help-routes').then((m) => m.HELP_ROUTES)
}
]
}
]);
}
1 change: 1 addition & 0 deletions src/app/core/help/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './provider';
78 changes: 0 additions & 78 deletions src/app/core/provider.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,16 @@
import { ViewportScroller } from '@angular/common';
import { APP_INITIALIZER, Provider, makeEnvironmentProviders } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ROUTES } from '@angular/router';

import { firstValueFrom } from 'rxjs';
import { tap } from 'rxjs/operators';

import { ADMIN_TOPICS } from './admin/admin-topic.model';
import { SessionService } from './auth';
import { ConfigService } from './config.service';
import { CORE_ROUTES } from './core-routes';
import { CustomViewportScroller, SCROLL_ELEMENT } from './custom_viewport_scroller';
import { GettingStartedHelpComponent } from './help/getting-started/getting-started-help.component';
import { HELP_TOPICS } from './help/help-topic.component';
import { NavigationService } from './navigation.service';
import { TEAM_TOPICS } from './teams';
import { TeamsHelpComponent } from './teams/help/teams-help.component';
import { APP_CONFIG, APP_SESSION } from './tokens';

export function provideCoreRoutes() {
// Registering Topics here. Need to find better alternative for this.
return makeEnvironmentProviders([
{
provide: ADMIN_TOPICS,
multi: true,
useValue: [
{
id: 'users',
title: 'Users',
ordinal: 0,
path: 'users'
},

{
id: 'cache-entries',
title: 'Cache Entries',
ordinal: 1,
path: 'cacheEntries'
},
{
id: 'end-user-agreements',
title: 'EUAs',
ordinal: 2,
path: 'euas'
},
{
id: 'messages',
title: 'Messages',
ordinal: 3,
path: 'messages'
},
{
id: 'feedback',
title: 'Feedback',
ordinal: 4,
path: 'feedback'
}
]
},
{
provide: TEAM_TOPICS,
multi: true,
useValue: {
id: 'general',
title: 'General',
ordinal: 0,
path: 'general'
}
},
{
provide: HELP_TOPICS,
multi: true,
useValue: [
{
id: 'getting-started',
title: 'Getting Started',
ordinal: 0,
component: GettingStartedHelpComponent
},
{ id: 'teams', title: 'Teams', ordinal: 9, component: TeamsHelpComponent }
]
},
{
provide: ROUTES,
multi: true,
useValue: CORE_ROUTES
}
]);
}

export function provideAppConfig() {
return makeEnvironmentProviders([
{
Expand Down
Loading

0 comments on commit 473528f

Please sign in to comment.