Skip to content

Commit e309e18

Browse files
committed
fix(DataMapper): Do not remove InstructionItem targeted field item
Fixes: #3149
1 parent 136a6b8 commit e309e18

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/ui/src/services/mapping.service.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ describe('MappingService', () => {
300300
consoleSpy.mockRestore();
301301
extractSpy.mockRestore();
302302
});
303+
304+
it("should not remove for-each targeted field when it doesn't have children", () => {
305+
const shipOrderItem = tree.children[0];
306+
const forEachItem = shipOrderItem.children[3];
307+
expect(forEachItem).toBeInstanceOf(ForEachItem);
308+
shipOrderItem.children = [forEachItem];
309+
const itemItem = forEachItem.children[0];
310+
itemItem.children = [];
311+
MappingService.removeAllMappingsForDocument(tree, DocumentType.PARAM, 'newParam');
312+
expect(forEachItem.children.length).toEqual(1);
313+
expect(forEachItem.children[0]).toBe(itemItem);
314+
});
303315
});
304316

305317
describe('renameParameterInMappings()', () => {

packages/ui/src/services/mapping.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export class MappingService {
102102
) {
103103
return acc;
104104
}
105-
if (child instanceof FieldItem && child.children.length === 0) return acc;
105+
if (!(child.parent instanceof InstructionItem) && child instanceof FieldItem && child.children.length === 0)
106+
return acc;
106107
acc.push(child);
107108
return acc;
108109
}, [] as MappingItem[]);

0 commit comments

Comments
 (0)