1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

[EC-8] Cleanup org reporting component redundancy

This commit is contained in:
Shane Melton 2022-07-29 17:17:10 -07:00
parent a355b35511
commit eca337e89b
10 changed files with 59 additions and 90 deletions

View File

@ -11,27 +11,29 @@ import { InactiveTwoFactorReportComponent } from "../../../organizations/tools/i
import { ReusedPasswordsReportComponent } from "../../../organizations/tools/reused-passwords-report.component"; import { ReusedPasswordsReportComponent } from "../../../organizations/tools/reused-passwords-report.component";
import { UnsecuredWebsitesReportComponent } from "../../../organizations/tools/unsecured-websites-report.component"; import { UnsecuredWebsitesReportComponent } from "../../../organizations/tools/unsecured-websites-report.component";
import { WeakPasswordsReportComponent } from "../../../organizations/tools/weak-passwords-report.component"; import { WeakPasswordsReportComponent } from "../../../organizations/tools/weak-passwords-report.component";
import { ReportListComponent } from "../../../reports/report-list.component";
import { ReportListComponent } from "./report-list.component"; import { ReportsComponent } from "./../../../reports/reports.component";
import { ReportingComponent } from "./reporting.component"; import { ReportingTabComponent } from "./reporting-tab.component";
const routes: Routes = [ const routes: Routes = [
{ {
path: "", path: "",
component: ReportingComponent, component: ReportingTabComponent,
canActivate: [PermissionsGuard], canActivate: [PermissionsGuard],
data: { permissions: NavigationPermissionsService.getPermissions("reporting") }, data: { permissions: NavigationPermissionsService.getPermissions("reporting") },
children: [ children: [
{ path: "", pathMatch: "full", redirectTo: "reports" }, { path: "", pathMatch: "full", redirectTo: "reports" },
{ {
path: "reports", path: "reports",
component: ReportListComponent, component: ReportsComponent,
canActivate: [PermissionsGuard], canActivate: [PermissionsGuard],
data: { data: {
titleId: "reports", titleId: "reports",
permissions: [Permissions.AccessReports], permissions: [Permissions.AccessReports],
}, },
children: [ children: [
{ path: "", pathMatch: "full", component: ReportListComponent },
{ {
path: "exposed-passwords-report", path: "exposed-passwords-report",
component: ExposedPasswordsReportComponent, component: ExposedPasswordsReportComponent,

View File

@ -4,11 +4,10 @@ import { LooseComponentsModule } from "../../loose-components.module";
import { SharedModule } from "../../shared.module"; import { SharedModule } from "../../shared.module";
import { OrganizationReportingRoutingModule } from "./organization-reporting-routing.module"; import { OrganizationReportingRoutingModule } from "./organization-reporting-routing.module";
import { ReportListComponent } from "./report-list.component"; import { ReportingTabComponent } from "./reporting-tab.component";
import { ReportingComponent } from "./reporting.component";
@NgModule({ @NgModule({
imports: [SharedModule, LooseComponentsModule, OrganizationReportingRoutingModule], imports: [SharedModule, LooseComponentsModule, OrganizationReportingRoutingModule],
declarations: [ReportListComponent, ReportingComponent], declarations: [ReportingTabComponent],
}) })
export class OrganizationReportingModule {} export class OrganizationReportingModule {}

View File

@ -1,24 +0,0 @@
<ng-container *ngIf="homepage">
<div class="page-header">
<h1>{{ "reports" | i18n }}</h1>
</div>
<p>{{ "orgsReportsDesc" | i18n }}</p>
<div class="tw-inline-grid tw-grid-cols-3 tw-gap-4">
<div *ngFor="let report of reports">
<app-report-card [type]="report"></app-report-card>
</div>
</div>
</ng-container>
<router-outlet></router-outlet>
<div class="row mt-4">
<div class="col">
<a bitButton routerLink="./" *ngIf="!homepage">
<i class="bwi bwi-angle-left" aria-hidden="true"></i>
{{ "backToReports" | i18n }}
</a>
</div>
</div>

View File

@ -1,34 +0,0 @@
import { Component } from "@angular/core";
import { NavigationEnd, Router } from "@angular/router";
import { filter, Subscription } from "rxjs";
import { ReportTypes } from "../../../reports/report-card.component";
@Component({
selector: "app-org-report-list",
templateUrl: "report-list.component.html",
})
export class ReportListComponent {
reports = [
ReportTypes.exposedPasswords,
ReportTypes.reusedPasswords,
ReportTypes.weakPasswords,
ReportTypes.unsecuredWebsites,
ReportTypes.inactive2fa,
];
homepage = true;
subscription: Subscription;
constructor(router: Router) {
this.subscription = router.events
.pipe(filter((event) => event instanceof NavigationEnd))
.subscribe((event) => {
this.homepage = (event as NavigationEnd).urlAfterRedirects.endsWith("/reports");
});
}
ngOnDestroy(): void {
this.subscription?.unsubscribe();
}
}

View File

@ -6,9 +6,9 @@ import { Organization } from "@bitwarden/common/models/domain/organization";
@Component({ @Component({
selector: "app-org-reporting", selector: "app-org-reporting",
templateUrl: "reporting.component.html", templateUrl: "reporting-tab.component.html",
}) })
export class ReportingComponent implements OnInit { export class ReportingTabComponent implements OnInit {
organization: Organization; organization: Organization;
accessEvents = false; accessEvents = false;
showLeftNav = true; showLeftNav = true;

View File

@ -2,10 +2,10 @@
<h1>{{ "reports" | i18n }}</h1> <h1>{{ "reports" | i18n }}</h1>
</div> </div>
<p>{{ "reportsDesc" | i18n }}</p> <p>{{ reportDescKey | i18n }}</p>
<div class="tw-inline-grid tw-grid-cols-3 tw-gap-4"> <div class="tw-inline-grid tw-grid-cols-3 tw-gap-4">
<div *ngFor="let report of reports"> <div *ngFor="let report of reportTypes">
<app-report-card [type]="report"></app-report-card> <app-report-card [type]="report"></app-report-card>
</div> </div>
</div> </div>

View File

@ -1,4 +1,5 @@
import { Component } from "@angular/core"; import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { ReportTypes } from "./report-card.component"; import { ReportTypes } from "./report-card.component";
@ -7,12 +8,25 @@ import { ReportTypes } from "./report-card.component";
templateUrl: "report-list.component.html", templateUrl: "report-list.component.html",
}) })
export class ReportListComponent { export class ReportListComponent {
reports = [ forOrganization = false;
ReportTypes.exposedPasswords,
ReportTypes.reusedPasswords, constructor(private route: ActivatedRoute) {
ReportTypes.weakPasswords, this.route.params.subscribe((params) => {
ReportTypes.unsecuredWebsites, this.forOrganization = params.organizationId != null;
ReportTypes.inactive2fa, });
ReportTypes.dataBreach, }
];
get reportDescKey() {
return this.forOrganization ? "orgsReportsDesc" : "reportsDesc";
}
get reportTypes() {
return [
ReportTypes.exposedPasswords,
ReportTypes.reusedPasswords,
ReportTypes.weakPasswords,
ReportTypes.unsecuredWebsites,
ReportTypes.inactive2fa,
].concat(this.forOrganization ? [] : [ReportTypes.dataBreach]);
}
} }

View File

@ -1,12 +1,10 @@
<div class="container page-content"> <router-outlet></router-outlet>
<router-outlet></router-outlet>
<div class="row mt-4"> <div class="row mt-4">
<div class="col"> <div class="col">
<a bitButton routerLink="./" *ngIf="!homepage"> <a bitButton routerLink="./" *ngIf="!homepage">
<i class="bwi bwi-angle-left" aria-hidden="true"></i> <i class="bwi bwi-angle-left" aria-hidden="true"></i>
{{ "backToReports" | i18n }} {{ "backToReports" | i18n }}
</a> </a>
</div>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import { Component, OnDestroy } from "@angular/core"; import { Component, HostBinding, OnDestroy } from "@angular/core";
import { NavigationEnd, Router } from "@angular/router"; import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
import { Subscription } from "rxjs"; import { Subscription } from "rxjs";
import { filter } from "rxjs/operators"; import { filter } from "rxjs/operators";
@ -10,15 +10,29 @@ import { filter } from "rxjs/operators";
export class ReportsComponent implements OnDestroy { export class ReportsComponent implements OnDestroy {
homepage = true; homepage = true;
subscription: Subscription; subscription: Subscription;
forOrganization: boolean;
@HostBinding("class")
get classList() {
return this.forOrganization ? [] : ["container", "page-content", "d-block"];
}
constructor(router: Router, route: ActivatedRoute) {
route.params.subscribe((params) => {
this.forOrganization = params.organizationId != null;
});
constructor(router: Router) {
this.subscription = router.events this.subscription = router.events
.pipe(filter((event) => event instanceof NavigationEnd)) .pipe(filter((event) => event instanceof NavigationEnd))
.subscribe((event) => { .subscribe((event) => {
this.homepage = (event as NavigationEnd).url == "/reports"; this.homepage = (event as NavigationEnd).urlAfterRedirects.endsWith("/reports");
}); });
} }
get containerClasses() {
return this.forOrganization ? [] : ["container", "page-content"];
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.subscription?.unsubscribe(); this.subscription?.unsubscribe();
} }