1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-14 02:08:50 +02:00

[Linked fields] Fix change detection on cipherType (#536)

* Fix bug that clears linkedId values when editing

* Add null check

* Fix linting
This commit is contained in:
Thomas Rittson 2021-11-09 21:57:33 +10:00 committed by GitHub
parent 2db9e1ce0d
commit 99ff3feb53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,10 @@ export class AddEditCustomFieldsComponent implements OnChanges {
ngOnChanges(changes: SimpleChanges) {
if (changes.thisCipherType != null) {
this.setLinkedFieldOptions();
if (!changes.thisCipherType.firstChange) {
this.resetCipherLinkedFields();
}
}
}
@ -92,9 +96,7 @@ export class AddEditCustomFieldsComponent implements OnChanges {
}
private setLinkedFieldOptions() {
// Delete any Linked custom fields if the item type does not support them
if (this.cipher.linkedFieldOptions == null) {
this.cipher.fields = this.cipher.fields.filter(f => f.type !== FieldType.Linked);
return;
}
@ -102,11 +104,21 @@ export class AddEditCustomFieldsComponent implements OnChanges {
this.cipher.linkedFieldOptions.forEach((linkedFieldOption, id) =>
options.push({ name: this.i18nService.t(linkedFieldOption.i18nKey), value: id }));
this.linkedFieldOptions = options.sort(Utils.getSortFunction(this.i18nService, 'name'));
}
if (!this.editMode) {
this.cipher.fields
.filter(f => f.type = FieldType.Linked)
.forEach(f => f.linkedId = this.linkedFieldOptions[0].value);
private resetCipherLinkedFields() {
if (this.cipher.fields == null || this.cipher.fields.length === 0) {
return;
}
// Delete any Linked custom fields if the item type does not support them
if (this.cipher.linkedFieldOptions == null) {
this.cipher.fields = this.cipher.fields.filter(f => f.type !== FieldType.Linked);
return;
}
this.cipher.fields
.filter(f => f.type = FieldType.Linked)
.forEach(f => f.linkedId = this.linkedFieldOptions[0].value);
}
}