From 54e19d3fc9d894c55eb25a3bae015c2c05d6ba53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anderson=20Greg=C3=B3rio?= Date: Tue, 19 Nov 2024 09:41:39 -0300 Subject: [PATCH] fix(dynamic-form): corrige erro de visibilidade campos no container Corrige erro ao setar visibilidade nos campos quando dentro de um container fixes DTHFUI-10270 --- .../po-dynamic-form-fields.component.spec.ts | 3 +-- .../po-dynamic-form-fields.component.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts index 0e834fc45a..42bd36abc0 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts @@ -728,8 +728,7 @@ describe('PoDynamicFormFieldsComponent: ', () => { const updatedFields = component['updateFieldContainer'](changes, containerFields); expect(updatedFields[0][0].container).toBe('updatedContainer1'); - expect(updatedFields[1][0].container).toBe('container2'); - expect(updatedFields[2][0].container).toBe('updatedContainer3'); + expect(updatedFields[1][0].container).toBe('updatedContainer3'); }); it('diffObjectsArray: should return the complete object if it is new in the array', () => { diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts index 65d96e8f3b..ba8e370a84 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts @@ -206,7 +206,7 @@ export class PoDynamicFormFieldsComponent extends PoDynamicFormFieldsBaseCompone this.containerFields = this.updateFieldContainer(result, this.containerFields); } - private updateFieldContainer(changes, containerFields) { + private updateFieldContainer(changes: Array, containerFields: Array>) { const mapchanges = new Map(changes.map(obj => [obj.property, obj])); containerFields.forEach(subArray => { @@ -218,7 +218,14 @@ export class PoDynamicFormFieldsComponent extends PoDynamicFormFieldsBaseCompone }); }); - return containerFields; + // Garante que apenas os items de `changes` estejam em `containerFields` + return containerFields + .map(itemFields => + itemFields.filter(formFieldContainer => + changes.some(formFieldChanges => formFieldContainer.property === formFieldChanges.property) + ) + ) + .filter(subArray => subArray.length > 0); } private diffObjectsArray(oldArray, newArray) {