Skip to content

Commit

Permalink
editor: fix data loss for repeatable fields
Browse files Browse the repository at this point in the history
* Closes rero/rero-ils#1003.
* Cleans the initialization sequence for the editor.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Jul 30, 2020
1 parent a6e5351 commit afa4ee9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions projects/rero/ng-core/src/lib/record/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
* @param changes: the changed properties
*/
ngOnChanges(changes: SimpleChanges): void {
if (changes.model) { // Model has changed
if (changes.model && !changes.model.isFirstChange) { // Model has changed
this._setModel(changes.model.currentValue);
}
}
Expand All @@ -124,6 +124,11 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
* Component initialisation
*/
ngOnInit() {
this._subscribers.push(
this._editorService.hiddenFields$.subscribe(() =>
this.getTocFields()
)
);
combineLatest([this._route.params, this._route.queryParams]).subscribe(
([params, queryParams]) => {
// uncomment for debug
Expand All @@ -140,11 +145,6 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
);
if (this._resourceConfig.editorLongMode === true) {
this.longMode = true;
this._subscribers.push(
this._editorService.hiddenFields$.subscribe(() =>
this.getTocFields()
)
);
}
this.pid = params.pid;

Expand Down Expand Up @@ -212,7 +212,7 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
}
// preprocess the model before sending to formly
this.model = this.preprocessRecord(model);
this.modelChange.emit(this.model);
this.modelChanged(this.model);
}
}

Expand Down Expand Up @@ -549,13 +549,13 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
}
const keysToKeep = formOptions.validation.validators.uniqueValueKeysInObject.keys;
const uniqueItems = Array.from(
new Set(control.value.map((v: any) => {
const keys = keysToKeep.reduce((acc, elt) => {
acc[elt] = v[elt];
return acc;
}, {});
return JSON.stringify(keys);
})),
new Set(control.value.map((v: any) => {
const keys = keysToKeep.reduce((acc, elt) => {
acc[elt] = v[elt];
return acc;
}, {});
return JSON.stringify(keys);
})),
);
return uniqueItems.length === control.value.length;
}
Expand Down

0 comments on commit afa4ee9

Please sign in to comment.