Preserve the confidence value when loading the initial value of the model into the DsDynamicOneboxComponent. Previously, the accepted confidence value was always displayed if a valid vocabulary entry was retrieved, incorrectly displaying it for values without accepted authority.

This commit is contained in:
Toni Prieto
2024-02-23 11:05:26 +01:00
parent 7253a5917c
commit 1fc046249b
2 changed files with 9 additions and 3 deletions

View File

@@ -50,8 +50,9 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
/**
* Retrieves the init form value from model
* @param preserveConfidence if the original model confidence value should be used after retrieving the vocabulary's entry
*/
getInitValueFromModel(): Observable<FormFieldMetadataValueObject> {
getInitValueFromModel(preserveConfidence = false): Observable<FormFieldMetadataValueObject> {
let initValue$: Observable<FormFieldMetadataValueObject>;
if (isNotEmpty(this.model.value) && (this.model.value instanceof FormFieldMetadataValueObject) && !this.model.value.hasAuthorityToGenerate()) {
let initEntry$: Observable<VocabularyEntry>;
@@ -63,7 +64,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
initValue$ = initEntry$.pipe(map((initEntry: VocabularyEntry) => {
if (isNotEmpty(initEntry)) {
// Integrate FormFieldMetadataValueObject with retrieved information
return new FormFieldMetadataValueObject(
let formField = new FormFieldMetadataValueObject(
initEntry.value,
null,
initEntry.authority,
@@ -72,6 +73,11 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
null,
initEntry.otherInformation || null
);
// Preserve the original confidence
if (preserveConfidence) {
formField.confidence = (this.model.value as any).confidence;
}
return formField;
} else {
return this.model.value as any;
}

View File

@@ -273,7 +273,7 @@ export class DsDynamicOneboxComponent extends DsDynamicVocabularyComponent imple
let result: string;
if (init) {
this.changeLoadingInitialValueStatus(true);
this.getInitValueFromModel()
this.getInitValueFromModel(true)
.subscribe((formValue: FormFieldMetadataValueObject) => {
this.changeLoadingInitialValueStatus(false);
this.currentValue = formValue;