1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

filter out linked option for notes (#10162)

This commit is contained in:
Nick Krantz 2024-07-18 13:57:10 -05:00 committed by GitHub
parent f75c1ab02d
commit bf66cd1550
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View File

@ -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 }),
);
});
});

View File

@ -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();

View File

@ -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,
},
},