mirror of
https://github.com/bitwarden/browser
synced 2025-12-24 04:04:24 +00:00
[PM-21546] Migrate from enum to constant object (#14975)
* add generic `union-of-values` helper * migrate `GeneratorDialogAction` to a constant * migrate `VaultState` to a constant * migrate `AtRiskCarouselDialogResult` to a constant * migrate `CredentialGeneratorDialogAction` to a constant * migrate `FolderAddEditDialogResult` to a constant * migrate `ViewCipherDialogResult` to a constant * migrate `VisibleVaultBanner` to a constant * migrate `VaultFilterLabel` to a constant * migrate `WebVaultGeneratorDialogResult` to a constant * migrate `BulkDeleteDialogResult` to a constant * migrate `BulkMoveDialogResult` to a constant * migrate `AddEditCipherDialogResult` to a constant * migrate `VaultItemDialogResult` to a constant * migrate `BrowserPromptState` to a constant * migrate `NudgeType` to a constant * migrate `SecurityTaskStatus` to a constant * migrate `CipherRepromptType` to a constant * migrate `SecureNoteType` to a constant * migrate `FieldType` to a constant * migrate `LinkedIdType` to a constant * migrate `CollectionAssignmentResult` to a constant * migrate `AddEditFolderDialogResult` to a constant * migrate `AttachmentDialogResult` to a constant * fix CipherType in delete organization dialog * fix `in` statement in VaultFilter * Fix build errors across enum updates * fix two more CipherType castings * update CipherResponse `CipherType` * define type for `fieldType` parameter * refine how `cipherTypeNames` is generated and add utility function for grabbing cipher type name * use `CipherType` rather than `number` * add stricter typing for `FieldType` * add fixme for `CipherType` to be ADR-0025 compliant * remove error throw for `toCipherTypeName` and instead update typing to have `| undefined` * add helpers for CipherType conversions * prefer `undefined`
This commit is contained in:
@@ -459,7 +459,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
||||
const cipherView = cipherViews[cipherIndex];
|
||||
if (
|
||||
!this.cardAndIdentityCiphers.has(cipherView) &&
|
||||
[CipherType.Card, CipherType.Identity].includes(cipherView.type)
|
||||
([CipherType.Card, CipherType.Identity] as CipherType[]).includes(cipherView.type)
|
||||
) {
|
||||
this.cardAndIdentityCiphers.add(cipherView);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,9 @@ export class CipherContextMenuHandler {
|
||||
private async updateForCipher(cipher: CipherView) {
|
||||
if (
|
||||
cipher == null ||
|
||||
!new Set([CipherType.Login, CipherType.Card, CipherType.Identity]).has(cipher.type)
|
||||
!new Set([CipherType.Login, CipherType.Card, CipherType.Identity] as CipherType[]).has(
|
||||
cipher.type,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,4 +54,7 @@ export type FormFieldElement = FillableFormFieldElement | HTMLSpanElement;
|
||||
|
||||
export type FormElementWithAttribute = FormFieldElement & Record<string, string | null | undefined>;
|
||||
|
||||
export type AutofillCipherTypeId = CipherType.Login | CipherType.Card | CipherType.Identity;
|
||||
export type AutofillCipherTypeId =
|
||||
| typeof CipherType.Login
|
||||
| typeof CipherType.Card
|
||||
| typeof CipherType.Identity;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component, inject, signal } from "@angular/core";
|
||||
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DialogRef,
|
||||
ButtonModule,
|
||||
@@ -10,11 +11,11 @@ import {
|
||||
import { I18nPipe } from "@bitwarden/ui-common";
|
||||
import { DarkImageSourceDirective, VaultCarouselModule } from "@bitwarden/vault";
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum AtRiskCarouselDialogResult {
|
||||
Dismissed = "dismissed",
|
||||
}
|
||||
export const AtRiskCarouselDialogResult = {
|
||||
Dismissed: "dismissed",
|
||||
} as const;
|
||||
|
||||
type AtRiskCarouselDialogResult = UnionOfValues<typeof AtRiskCarouselDialogResult>;
|
||||
|
||||
@Component({
|
||||
selector: "vault-at-risk-carousel-dialog",
|
||||
|
||||
@@ -17,7 +17,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { CipherId, CollectionId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherType, toCipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
|
||||
import { AddEditCipherInfo } from "@bitwarden/common/vault/types/add-edit-cipher-info";
|
||||
@@ -64,7 +64,7 @@ import { OpenAttachmentsComponent } from "../attachments/open-attachments/open-a
|
||||
class QueryParams {
|
||||
constructor(params: Params) {
|
||||
this.cipherId = params.cipherId;
|
||||
this.type = params.type != undefined ? parseInt(params.type, null) : undefined;
|
||||
this.type = toCipherType(params.type);
|
||||
this.clone = params.clone === "true";
|
||||
this.folderId = params.folderId;
|
||||
this.organizationId = params.organizationId;
|
||||
|
||||
@@ -103,7 +103,9 @@ export class ItemMoreOptionsComponent implements OnInit {
|
||||
* Determines if the cipher can be autofilled.
|
||||
*/
|
||||
get canAutofill() {
|
||||
return [CipherType.Login, CipherType.Card, CipherType.Identity].includes(this.cipher.type);
|
||||
return ([CipherType.Login, CipherType.Card, CipherType.Identity] as CipherType[]).includes(
|
||||
this.cipher.type,
|
||||
);
|
||||
}
|
||||
|
||||
get isLogin() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { CommonModule } from "@angular/common";
|
||||
import { Component, Inject } from "@angular/core";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogConfig,
|
||||
@@ -30,12 +31,12 @@ export interface GeneratorDialogResult {
|
||||
generatedValue?: string;
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum GeneratorDialogAction {
|
||||
Selected = "selected",
|
||||
Canceled = "canceled",
|
||||
}
|
||||
export const GeneratorDialogAction = {
|
||||
Selected: "selected",
|
||||
Canceled: "canceled",
|
||||
} as const;
|
||||
|
||||
type GeneratorDialogAction = UnionOfValues<typeof GeneratorDialogAction>;
|
||||
|
||||
@Component({
|
||||
selector: "app-vault-generator-dialog",
|
||||
|
||||
@@ -24,6 +24,7 @@ import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { CipherId, CollectionId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
ButtonModule,
|
||||
DialogService,
|
||||
@@ -55,13 +56,13 @@ import { VaultHeaderV2Component } from "./vault-header/vault-header-v2.component
|
||||
|
||||
import { AutofillVaultListItemsComponent, VaultListItemsContainerComponent } from ".";
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
enum VaultState {
|
||||
Empty,
|
||||
NoResults,
|
||||
DeactivatedOrg,
|
||||
}
|
||||
const VaultState = {
|
||||
Empty: 0,
|
||||
NoResults: 1,
|
||||
DeactivatedOrg: 2,
|
||||
} as const;
|
||||
|
||||
type VaultState = UnionOfValues<typeof VaultState>;
|
||||
|
||||
@Component({
|
||||
selector: "app-vault",
|
||||
|
||||
@@ -319,13 +319,13 @@ export class VaultPopupItemsService {
|
||||
* @private
|
||||
*/
|
||||
private sortCiphersForAutofill(a: CipherView, b: CipherView): number {
|
||||
const typeOrder: Record<CipherType, number> = {
|
||||
const typeOrder = {
|
||||
[CipherType.Login]: 1,
|
||||
[CipherType.Card]: 2,
|
||||
[CipherType.Identity]: 3,
|
||||
[CipherType.SecureNote]: 4,
|
||||
[CipherType.SshKey]: 5,
|
||||
};
|
||||
} as Record<CipherType, number>;
|
||||
|
||||
// Compare types first
|
||||
if (typeOrder[a.type] < typeOrder[b.type]) {
|
||||
|
||||
Reference in New Issue
Block a user