From ef9d957320c98b5f59f78d7a10dd0e18c5f9bb55 Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Fri, 9 Sep 2022 08:29:17 -0700 Subject: [PATCH] [EC-526] Default to Event Logs page for Reporting Tab (#3470) * [EC-526] Default to the Events Logs page when navigating to the Reporting tab * [EC-526] Undo default routing redirect when the child path is missing. Avoids defaulting to "/events" in case a user/org doesn't have access to event logs. --- .../organization-layout.component.html | 2 +- .../layouts/organization-layout.component.ts | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/web/src/app/organizations/layouts/organization-layout.component.html b/apps/web/src/app/organizations/layouts/organization-layout.component.html index 8716e12740d..2546f39bd32 100644 --- a/apps/web/src/app/organizations/layouts/organization-layout.component.html +++ b/apps/web/src/app/organizations/layouts/organization-layout.component.html @@ -14,7 +14,7 @@ {{ "groups" | i18n }} - {{ + {{ reportTabLabel | i18n }} {{ diff --git a/apps/web/src/app/organizations/layouts/organization-layout.component.ts b/apps/web/src/app/organizations/layouts/organization-layout.component.ts index 48fde0d2b9d..e0ceb0ad0e7 100644 --- a/apps/web/src/app/organizations/layouts/organization-layout.component.ts +++ b/apps/web/src/app/organizations/layouts/organization-layout.component.ts @@ -1,5 +1,6 @@ import { Component, NgZone, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; +import { concatMap, Subject, takeUntil } from "rxjs"; import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; @@ -20,9 +21,10 @@ const BroadcasterSubscriptionId = "OrganizationLayoutComponent"; templateUrl: "organization-layout.component.html", }) export class OrganizationLayoutComponent implements OnInit, OnDestroy { - organization: Organization; - businessTokenPromise: Promise; private organizationId: string; + private destroy$ = new Subject(); + + organization: Organization; constructor( private route: ActivatedRoute, @@ -33,11 +35,16 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { ngOnInit() { document.body.classList.remove("layout_frontend"); - // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe - this.route.params.subscribe(async (params: any) => { - this.organizationId = params.organizationId; - await this.load(); - }); + this.route.params + .pipe( + concatMap(async (params: any) => { + this.organizationId = params.organizationId; + await this.load(); + }), + takeUntil(this.destroy$) + ) + .subscribe(); + this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => { this.ngZone.run(async () => { switch (message.command) { @@ -51,6 +58,8 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { ngOnDestroy() { this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + this.destroy$.next(); + this.destroy$.complete(); } async load() { @@ -80,4 +89,8 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { get reportTabLabel(): string { return this.organization.useEvents ? "reporting" : "reports"; } + + get reportRoute(): string { + return this.organization.useEvents ? "reporting/events" : "reporting/reports"; + } }