From 6d96a8a117319406336b992f488e5f4a73adaa76 Mon Sep 17 00:00:00 2001 From: Ritesh Dsouza Date: Tue, 26 Nov 2024 11:54:22 +0000 Subject: [PATCH] moved repeated code to function --- .../lib/shared/services/form/field-type-sanitiser.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/form/field-type-sanitiser.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/form/field-type-sanitiser.ts index c83ab4284..16ba7ef5d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/form/field-type-sanitiser.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/form/field-type-sanitiser.ts @@ -65,8 +65,7 @@ export class FieldTypeSanitiser { field.field_type.complex_fields.forEach((complexField) => { if (complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_COMPLEX) { this.checkNestedDynamicList(complexField, caseFieldData?.[complexField.id]); - } else if ( - FieldTypeSanitiser.DYNAMIC_LIST_TYPE.indexOf(complexField.field_type.type) !== -1 && + } else if (this.isDynamicList(complexField.field_type.type) && complexField.display_context !== 'HIDDEN' && field._value?.[complexField.id] ) { @@ -81,8 +80,7 @@ export class FieldTypeSanitiser { caseField.field_type.complex_fields.forEach((complexField) => { if (complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_COMPLEX) { this.checkNestedDynamicList(complexField, fieldData?.[complexField.id]); - } else if ( - FieldTypeSanitiser.DYNAMIC_LIST_TYPE.indexOf(complexField.field_type.type) !== -1 && + } else if (this.isDynamicList(complexField.field_type.type) && complexField.display_context !== 'HIDDEN' && fieldData?.[complexField.id] ) { @@ -91,6 +89,10 @@ export class FieldTypeSanitiser { }); } + private isDynamicList(fieldType: FieldTypeEnum): boolean { + return FieldTypeSanitiser.DYNAMIC_LIST_TYPE.indexOf(fieldType) !== -1; + } + private convertArrayToDynamicListOutput(field: CaseField, data: any): void { const values = data[field.id]; if (Array.isArray(values)) {