1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 10:43:35 +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:
Nick Krantz
2025-06-05 08:45:52 -05:00
committed by GitHub
parent 7f72396cb2
commit 729d5d3134
45 changed files with 404 additions and 248 deletions

View File

@@ -155,7 +155,7 @@ export class CustomFieldsComponent implements OnInit, AfterViewInit {
// Populate options for linked custom fields
this.linkedFieldOptions = optionsArray.map(([id, linkedFieldOption]) => ({
name: this.i18nService.t(linkedFieldOption.i18nKey),
value: id,
value: id as LinkedIdType,
}));
const prefillCipher = this.cipherFormContainer.getInitialCipherView();

View File

@@ -4,6 +4,7 @@ import { CommonModule } from "@angular/common";
import { Component, Inject } from "@angular/core";
import { CipherId, OrganizationId } from "@bitwarden/common/types/guid";
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
import {
ButtonModule,
DialogModule,
@@ -24,13 +25,13 @@ export interface AttachmentsDialogParams {
/**
* Enum representing the possible results of the attachment dialog.
*/
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum AttachmentDialogResult {
Uploaded = "uploaded",
Removed = "removed",
Closed = "closed",
}
export const AttachmentDialogResult = {
Uploaded: "uploaded",
Removed: "removed",
Closed: "closed",
} as const;
export type AttachmentDialogResult = UnionOfValues<typeof AttachmentDialogResult>;
export interface AttachmentDialogCloseResult {
action: AttachmentDialogResult;

View File

@@ -19,6 +19,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
import {
DIALOG_DATA,
DialogRef,
@@ -34,12 +35,12 @@ import {
} from "@bitwarden/components";
import { KeyService } from "@bitwarden/key-management";
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum AddEditFolderDialogResult {
Created = "created",
Deleted = "deleted",
}
export const AddEditFolderDialogResult = {
Created: "created",
Deleted: "deleted",
} as const;
export type AddEditFolderDialogResult = UnionOfValues<typeof AddEditFolderDialogResult>;
export type AddEditFolderDialogData = {
/** When provided, dialog will display edit folder variant */

View File

@@ -40,6 +40,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { CipherId, CollectionId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
import {
AsyncActionsModule,
BitSubmitDirective,
@@ -82,12 +83,12 @@ export interface CollectionAssignmentParams {
isSingleCipherAdmin?: boolean;
}
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum CollectionAssignmentResult {
Saved = "saved",
Canceled = "canceled",
}
export const CollectionAssignmentResult = {
Saved: "saved",
Canceled: "canceled",
} as const;
export type CollectionAssignmentResult = UnionOfValues<typeof CollectionAssignmentResult>;
const MY_VAULT_ID = "MyVault";