diff --git a/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.spec.ts b/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.spec.ts index 3ecb04cdc5..f63a974d48 100644 --- a/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.spec.ts +++ b/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.spec.ts @@ -2,7 +2,7 @@ import { DIALOG_DATA } from "@angular/cdk/dialog"; import { ComponentFixture, TestBed } from "@angular/core/testing"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { FieldType } from "@bitwarden/common/vault/enums"; +import { CipherType, FieldType } from "@bitwarden/common/vault/enums"; import { AddEditCustomFieldDialogComponent, @@ -20,6 +20,7 @@ describe("AddEditCustomFieldDialogComponent", () => { addField, updateLabel, removeField, + cipherType: CipherType.Login, } as AddEditCustomFieldDialogData; beforeEach(async () => { @@ -69,4 +70,15 @@ describe("AddEditCustomFieldDialogComponent", () => { expect(removeField).toHaveBeenCalledWith(2); }); + + it('filters out "Linked" field type for SecureNote cipher type', () => { + dialogData.cipherType = CipherType.SecureNote; + + fixture = TestBed.createComponent(AddEditCustomFieldDialogComponent); + component = fixture.componentInstance; + + expect(component.fieldTypeOptions).not.toContainEqual( + expect.objectContaining({ value: FieldType.Linked }), + ); + }); }); diff --git a/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.ts b/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.ts index f08d0ca40e..7da6fe4e60 100644 --- a/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.ts +++ b/libs/vault/src/cipher-form/components/custom-fields/add-edit-custom-field-dialog/add-edit-custom-field-dialog.component.ts @@ -5,7 +5,7 @@ import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { FieldType } from "@bitwarden/common/vault/enums"; +import { CipherType, FieldType } from "@bitwarden/common/vault/enums"; import { AsyncActionsModule, ButtonModule, @@ -19,6 +19,8 @@ export type AddEditCustomFieldDialogData = { addField: (type: FieldType, label: string) => void; updateLabel: (index: number, label: string) => void; removeField: (index: number) => void; + /** Type of cipher */ + cipherType: CipherType; /** When provided, dialog will display edit label variants */ editLabelConfig?: { index: number; label: string }; }; @@ -63,6 +65,15 @@ export class AddEditCustomFieldDialogComponent { ) { this.variant = data.editLabelConfig ? "edit" : "add"; + this.fieldTypeOptions = this.fieldTypeOptions.filter((option) => { + // Filter out the Linked field type for Secure Notes + if (this.data.cipherType === CipherType.SecureNote) { + return option.value !== FieldType.Linked; + } + + return true; + }); + if (this.variant === "edit") { this.customFieldForm.controls.label.setValue(data.editLabelConfig.label); this.customFieldForm.controls.type.disable(); diff --git a/libs/vault/src/cipher-form/components/custom-fields/custom-fields.component.ts b/libs/vault/src/cipher-form/components/custom-fields/custom-fields.component.ts index 0233e1c1b1..ace8ce7987 100644 --- a/libs/vault/src/cipher-form/components/custom-fields/custom-fields.component.ts +++ b/libs/vault/src/cipher-form/components/custom-fields/custom-fields.component.ts @@ -201,6 +201,7 @@ export class CustomFieldsComponent implements OnInit, AfterViewInit { addField: this.addField.bind(this), updateLabel: this.updateLabel.bind(this), removeField: this.removeField.bind(this), + cipherType: this.cipherFormContainer.config.cipherType, editLabelConfig, }, },