1- // FIXME: Update this file to be type safe and remove this and next line
2- // @ts -strict-ignore
3- import { Component , OnInit } from "@angular/core" ;
1+ import { ChangeDetectorRef , Component , OnInit , ChangeDetectionStrategy } from "@angular/core" ;
42import { ActivatedRoute } from "@angular/router" ;
5- import { firstValueFrom , map } from "rxjs" ;
3+ import { firstValueFrom , map , takeUntil } from "rxjs" ;
64
7- import {
8- getOrganizationById ,
9- OrganizationService ,
10- } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction" ;
5+ import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction" ;
116import { AccountService } from "@bitwarden/common/auth/abstractions/account.service" ;
127import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service" ;
138import { LogService } from "@bitwarden/common/platform/abstractions/log.service" ;
9+ import { getById } from "@bitwarden/common/platform/misc" ;
1410import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service" ;
1511import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction" ;
1612import { Cipher } from "@bitwarden/common/vault/models/domain/cipher" ;
@@ -23,9 +19,8 @@ import { RoutedVaultFilterService } from "../../../../vault/individual-vault/vau
2319import { AdminConsoleCipherFormConfigService } from "../../../../vault/org-vault/services/admin-console-cipher-form-config.service" ;
2420import { InactiveTwoFactorReportComponent as BaseInactiveTwoFactorReportComponent } from "../inactive-two-factor-report.component" ;
2521
26- // FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
27- // eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
2822@Component ( {
23+ changeDetection : ChangeDetectionStrategy . OnPush ,
2924 selector : "app-inactive-two-factor-report" ,
3025 templateUrl : "../inactive-two-factor-report.component.html" ,
3126 providers : [
@@ -44,7 +39,7 @@ export class InactiveTwoFactorReportComponent
4439 implements OnInit
4540{
4641 // Contains a list of ciphers, the user running the report, can manage
47- private manageableCiphers : Cipher [ ] ;
42+ private manageableCiphers : Cipher [ ] = [ ] ;
4843
4944 constructor (
5045 cipherService : CipherService ,
@@ -58,6 +53,7 @@ export class InactiveTwoFactorReportComponent
5853 syncService : SyncService ,
5954 cipherFormConfigService : CipherFormConfigService ,
6055 adminConsoleCipherFormConfigService : AdminConsoleCipherFormConfigService ,
56+ protected changeDetectorRef : ChangeDetectorRef ,
6157 ) {
6258 super (
6359 cipherService ,
@@ -70,28 +66,37 @@ export class InactiveTwoFactorReportComponent
7066 syncService ,
7167 cipherFormConfigService ,
7268 adminConsoleCipherFormConfigService ,
69+ changeDetectorRef ,
7370 ) ;
7471 }
7572
7673 async ngOnInit ( ) {
7774 this . isAdminConsoleActive = true ;
78- // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
79- this . route . parent . parent . params . subscribe ( async ( params ) => {
80- const userId = await firstValueFrom (
81- this . accountService . activeAccount$ . pipe ( map ( ( a ) => a ?. id ) ) ,
82- ) ;
83- this . organization = await firstValueFrom (
84- this . organizationService
85- . organizations$ ( userId )
86- . pipe ( getOrganizationById ( params . organizationId ) ) ,
87- ) ;
88- this . manageableCiphers = await this . cipherService . getAll ( userId ) ;
89- await super . ngOnInit ( ) ;
90- } ) ;
75+
76+ this . route . parent ?. parent ?. params
77+ ?. pipe ( takeUntil ( this . destroyed$ ) )
78+ // eslint-disable-next-line rxjs/no-async-subscribe
79+ . subscribe ( async ( params ) => {
80+ const userId = await firstValueFrom (
81+ this . accountService . activeAccount$ . pipe ( map ( ( a ) => a ?. id ) ) ,
82+ ) ;
83+
84+ if ( userId ) {
85+ this . organization = await firstValueFrom (
86+ this . organizationService . organizations$ ( userId ) . pipe ( getById ( params . organizationId ) ) ,
87+ ) ;
88+ this . manageableCiphers = await this . cipherService . getAll ( userId ) ;
89+ await super . ngOnInit ( ) ;
90+ }
91+ this . changeDetectorRef . markForCheck ( ) ;
92+ } ) ;
9193 }
9294
93- getAllCiphers ( ) : Promise < CipherView [ ] > {
94- return this . cipherService . getAllFromApiForOrganization ( this . organization . id ) ;
95+ async getAllCiphers ( ) : Promise < CipherView [ ] > {
96+ if ( this . organization ) {
97+ return await this . cipherService . getAllFromApiForOrganization ( this . organization . id , true ) ;
98+ }
99+ return [ ] ;
95100 }
96101
97102 protected canManageCipher ( c : CipherView ) : boolean {
0 commit comments