mirror of
https://github.com/bitwarden/browser
synced 2024-12-26 18:04:07 +01: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:
parent
2db9e1ce0d
commit
99ff3feb53
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user