From 5ece98b175ca94458e78f6b56ace708523bcef3c Mon Sep 17 00:00:00 2001 From: hudson-newey Date: Fri, 20 Oct 2023 09:52:51 +1000 Subject: [PATCH] PR review changes --- src/app/app.menus.ts | 16 ++++++++++++---- src/app/directives/url/url-active.directive.ts | 4 ++-- src/app/guards/input/input.guard.spec.ts | 16 ++++++++++++++++ src/app/guards/input/input.guard.ts | 4 ++-- 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/app/guards/input/input.guard.spec.ts diff --git a/src/app/app.menus.ts b/src/app/app.menus.ts index 0577268ce..e1114b1d8 100644 --- a/src/app/app.menus.ts +++ b/src/app/app.menus.ts @@ -1,4 +1,6 @@ import { IconProp } from "@fortawesome/fontawesome-svg-core"; +import { Inject } from "@angular/core"; +import { ConfigService } from "@services/config/config.service"; import { IPageInfo } from "@helpers/page/pageInfo"; import { Project } from "./models/Project"; import { User } from "./models/User"; @@ -49,9 +51,15 @@ export const isAdminPredicate = (user: User): boolean => isLoggedInPredicate(user) && user.isAdmin; /** - * Returns true only if the user is an admin and can see work in progress items - * This predicate differs from the `isAdminPredicate` for semantic reasons - * + * Returns true only if the user is an admin and is not in a production environment + * This predicate exists so that we can implement work in progress menu items + * * @param user User session data. This will be used to check if the user is an admin */ -export const isWorkInProgressPredicate = isAdminPredicate; +export const isWorkInProgressPredicate = (user: User): boolean => { + const config = Inject(ConfigService); + + const isProduction: boolean = config.environment.production; + + return isProduction && isAdminPredicate(user); +}; diff --git a/src/app/directives/url/url-active.directive.ts b/src/app/directives/url/url-active.directive.ts index 4a1db2c8c..56010967a 100644 --- a/src/app/directives/url/url-active.directive.ts +++ b/src/app/directives/url/url-active.directive.ts @@ -35,8 +35,8 @@ export class UrlActiveDirective extends RouterLinkActive { _element: ElementRef, _renderer: Renderer2, _cdr: ChangeDetectorRef, - @Optional() _linkWithHref?: UrlDirective + @Optional() _link?: UrlDirective ) { - super(_router, _element, _renderer, _cdr, _linkWithHref); + super(_router, _element, _renderer, _cdr, _link); } } diff --git a/src/app/guards/input/input.guard.spec.ts b/src/app/guards/input/input.guard.spec.ts new file mode 100644 index 000000000..c451bc8cc --- /dev/null +++ b/src/app/guards/input/input.guard.spec.ts @@ -0,0 +1,16 @@ + +describe("UnsavedInputGuard", () => { + function setup(): void { + } + + beforeEach(() => setup()); + + it("should create", () => { + }); + + it("should show a confirmation if the user tries to navigate away from the page with unsaved changes", () => { + }); + + it("should not show a confirmation if the user tries to navigate away from the page witout unsaved changes", () => { + }); +}); diff --git a/src/app/guards/input/input.guard.ts b/src/app/guards/input/input.guard.ts index eaf595c68..0ed4044cd 100644 --- a/src/app/guards/input/input.guard.ts +++ b/src/app/guards/input/input.guard.ts @@ -1,5 +1,5 @@ import { Injectable } from "@angular/core"; - +import { CanDeactivate } from "@angular/router"; export interface UnsavedInputCheckingComponent { hasUnsavedChanges: boolean; @@ -12,7 +12,7 @@ export interface UnsavedInputCheckingComponent { */ @Injectable() export class UnsavedInputGuard - + implements CanDeactivate { public canDeactivate(component: UnsavedInputCheckingComponent): boolean { // canDeactivate guards can be called with null components: https://github.com/angular/angular/issues/40545