1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

Vault Refactor: Clean up some strict types (#12357)

* update cipher-view to account for strict type checking

* update view-identity-sections to account for strict type checking

* update read-only-cipher-card to account for strict type checking

* remove unused card import

* remove unused card import

* update additional-options to account for strict type checking
This commit is contained in:
Nick Krantz 2024-12-20 10:16:34 -06:00 committed by GitHub
parent b27a1a5337
commit 6ad35e0871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 26 deletions

View File

@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { Component, Input } from "@angular/core"; import { Component, Input } from "@angular/core";
@ -31,5 +29,5 @@ import {
], ],
}) })
export class AdditionalOptionsComponent { export class AdditionalOptionsComponent {
@Input() notes: string; @Input() notes: string = "";
} }

View File

@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { Component, Input, OnChanges, OnDestroy } from "@angular/core"; import { Component, Input, OnChanges, OnDestroy } from "@angular/core";
import { firstValueFrom, Observable, Subject, takeUntil } from "rxjs"; import { firstValueFrom, Observable, Subject, takeUntil } from "rxjs";
@ -48,19 +46,19 @@ import { ViewIdentitySectionsComponent } from "./view-identity-sections/view-ide
], ],
}) })
export class CipherViewComponent implements OnChanges, OnDestroy { export class CipherViewComponent implements OnChanges, OnDestroy {
@Input({ required: true }) cipher: CipherView; @Input({ required: true }) cipher: CipherView | null = null;
/** /**
* Optional list of collections the cipher is assigned to. If none are provided, they will be fetched using the * Optional list of collections the cipher is assigned to. If none are provided, they will be fetched using the
* `CipherService` and the `collectionIds` property of the cipher. * `CipherService` and the `collectionIds` property of the cipher.
*/ */
@Input() collections: CollectionView[]; @Input() collections?: CollectionView[];
/** Should be set to true when the component is used within the Admin Console */ /** Should be set to true when the component is used within the Admin Console */
@Input() isAdminConsole?: boolean = false; @Input() isAdminConsole?: boolean = false;
organization$: Observable<Organization>; organization$: Observable<Organization | undefined> | undefined;
folder$: Observable<FolderView>; folder$: Observable<FolderView | undefined> | undefined;
private destroyed$: Subject<void> = new Subject(); private destroyed$: Subject<void> = new Subject();
cardIsExpired: boolean = false; cardIsExpired: boolean = false;
@ -86,24 +84,38 @@ export class CipherViewComponent implements OnChanges, OnDestroy {
} }
get hasCard() { get hasCard() {
if (!this.cipher) {
return false;
}
const { cardholderName, code, expMonth, expYear, number } = this.cipher.card; const { cardholderName, code, expMonth, expYear, number } = this.cipher.card;
return cardholderName || code || expMonth || expYear || number; return cardholderName || code || expMonth || expYear || number;
} }
get hasLogin() { get hasLogin() {
if (!this.cipher) {
return false;
}
const { username, password, totp } = this.cipher.login; const { username, password, totp } = this.cipher.login;
return username || password || totp; return username || password || totp;
} }
get hasAutofill() { get hasAutofill() {
return this.cipher.login?.uris.length > 0; const uris = this.cipher?.login?.uris.length ?? 0;
return uris > 0;
} }
get hasSshKey() { get hasSshKey() {
return this.cipher.sshKey?.privateKey; return !!this.cipher?.sshKey?.privateKey;
} }
async loadCipherData() { async loadCipherData() {
if (!this.cipher) {
return;
}
// Load collections if not provided and the cipher has collectionIds // Load collections if not provided and the cipher has collectionIds
if ( if (
this.cipher.collectionIds && this.cipher.collectionIds &&

View File

@ -11,7 +11,6 @@ import { EventType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { import {
CardComponent,
FormFieldModule, FormFieldModule,
SectionComponent, SectionComponent,
SectionHeaderComponent, SectionHeaderComponent,
@ -37,7 +36,6 @@ type TotpCodeValues = {
imports: [ imports: [
CommonModule, CommonModule,
JslibModule, JslibModule,
CardComponent,
SectionComponent, SectionComponent,
SectionHeaderComponent, SectionHeaderComponent,
TypographyModule, TypographyModule,

View File

@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { AfterViewInit, Component, ContentChildren, QueryList } from "@angular/core"; import { AfterViewInit, Component, ContentChildren, QueryList } from "@angular/core";
import { CardComponent, BitFormFieldComponent } from "@bitwarden/components"; import { CardComponent, BitFormFieldComponent } from "@bitwarden/components";
@ -14,14 +12,16 @@ import { CardComponent, BitFormFieldComponent } from "@bitwarden/components";
* A thin wrapper around the `bit-card` component that disables the bottom border for the last form field. * A thin wrapper around the `bit-card` component that disables the bottom border for the last form field.
*/ */
export class ReadOnlyCipherCardComponent implements AfterViewInit { export class ReadOnlyCipherCardComponent implements AfterViewInit {
@ContentChildren(BitFormFieldComponent) formFields: QueryList<BitFormFieldComponent>; @ContentChildren(BitFormFieldComponent) formFields?: QueryList<BitFormFieldComponent>;
ngAfterViewInit(): void { ngAfterViewInit(): void {
// Disable the bottom border for the last form field // Disable the bottom border for the last form field
if (this.formFields.last) { if (this.formFields?.last) {
// Delay model update until next change detection cycle // Delay model update until next change detection cycle
setTimeout(() => { setTimeout(() => {
this.formFields.last.disableReadOnlyBorder = true; if (this.formFields) {
this.formFields.last.disableReadOnlyBorder = true;
}
}); });
} }
} }

View File

@ -1,12 +1,9 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { NgIf } from "@angular/common"; import { NgIf } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core"; import { Component, Input, OnInit } from "@angular/core";
import { JslibModule } from "@bitwarden/angular/jslib.module"; import { JslibModule } from "@bitwarden/angular/jslib.module";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { import {
CardComponent,
FormFieldModule, FormFieldModule,
IconButtonModule, IconButtonModule,
SectionComponent, SectionComponent,
@ -23,7 +20,6 @@ import { ReadOnlyCipherCardComponent } from "../read-only-cipher-card/read-only-
imports: [ imports: [
NgIf, NgIf,
JslibModule, JslibModule,
CardComponent,
SectionComponent, SectionComponent,
SectionHeaderComponent, SectionHeaderComponent,
TypographyModule, TypographyModule,
@ -33,11 +29,11 @@ import { ReadOnlyCipherCardComponent } from "../read-only-cipher-card/read-only-
], ],
}) })
export class ViewIdentitySectionsComponent implements OnInit { export class ViewIdentitySectionsComponent implements OnInit {
@Input() cipher: CipherView; @Input({ required: true }) cipher: CipherView | null = null;
showPersonalDetails: boolean; showPersonalDetails: boolean = false;
showIdentificationDetails: boolean; showIdentificationDetails: boolean = false;
showContactDetails: boolean; showContactDetails: boolean = false;
ngOnInit(): void { ngOnInit(): void {
this.showPersonalDetails = this.hasPersonalDetails(); this.showPersonalDetails = this.hasPersonalDetails();
@ -47,6 +43,10 @@ export class ViewIdentitySectionsComponent implements OnInit {
/** Returns all populated address fields */ /** Returns all populated address fields */
get addressFields(): string { get addressFields(): string {
if (!this.cipher) {
return "";
}
const { address1, address2, address3, fullAddressPart2, country } = this.cipher.identity; const { address1, address2, address3, fullAddressPart2, country } = this.cipher.identity;
return [address1, address2, address3, fullAddressPart2, country].filter(Boolean).join("\n"); return [address1, address2, address3, fullAddressPart2, country].filter(Boolean).join("\n");
} }
@ -58,18 +58,30 @@ export class ViewIdentitySectionsComponent implements OnInit {
/** Returns true when any of the "personal detail" attributes are populated */ /** Returns true when any of the "personal detail" attributes are populated */
private hasPersonalDetails(): boolean { private hasPersonalDetails(): boolean {
if (!this.cipher) {
return false;
}
const { username, company, fullName } = this.cipher.identity; const { username, company, fullName } = this.cipher.identity;
return Boolean(fullName || username || company); return Boolean(fullName || username || company);
} }
/** Returns true when any of the "identification detail" attributes are populated */ /** Returns true when any of the "identification detail" attributes are populated */
private hasIdentificationDetails(): boolean { private hasIdentificationDetails(): boolean {
if (!this.cipher) {
return false;
}
const { ssn, passportNumber, licenseNumber } = this.cipher.identity; const { ssn, passportNumber, licenseNumber } = this.cipher.identity;
return Boolean(ssn || passportNumber || licenseNumber); return Boolean(ssn || passportNumber || licenseNumber);
} }
/** Returns true when any of the "contact detail" attributes are populated */ /** Returns true when any of the "contact detail" attributes are populated */
private hasContactDetails(): boolean { private hasContactDetails(): boolean {
if (!this.cipher) {
return false;
}
const { email, phone } = this.cipher.identity; const { email, phone } = this.cipher.identity;
return Boolean(email || phone || this.addressFields); return Boolean(email || phone || this.addressFields);