Skip to content

Commit e33df44

Browse files
committed
fix(query-builder): drop proper targetExpression in nested groups
1 parent c99ff17 commit e33df44

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

projects/igniteui-angular/src/lib/query-builder/query-builder-tree.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,9 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
13861386
} else if (key.code == 'ArrowDown') {
13871387
//increase index offset capped at bottom of tree
13881388
newKeyIndexOffset = this.keyDragOffsetIndex + 1 <= (this.dropZonesList.length - 2 - index) * 2 + 2 ? this.keyDragOffsetIndex + 1 : this.keyDragOffsetIndex;
1389+
} else {
1390+
console.error('wrong key');
1391+
return;
13891392
}
13901393

13911394
//if up/down limits not reached
@@ -1406,13 +1409,13 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14061409
this.targetExpressionItem = this.expressionsList[index + indexOffset - groupsTillCurrent];
14071410
} else {
14081411
//if the current drop zone is a group root (AND/OR)
1409-
if ((index + indexOffset === 0)) {
1412+
if (index + indexOffset === 0) {
14101413
//If the root group's AND/OR
14111414
this.targetElement = this.dropZonesList[0]
14121415
this.targetExpressionItem = this.rootGroup.children[0];
14131416
under = true;
14141417
overrideDropUnder = false;
1415-
} else if (under || (index + indexOffset === 0)) {
1418+
} else if (under) {
14161419
//If under AND/OR
14171420
this.targetElement = this.dropZonesList[index + indexOffset]
14181421
this.targetExpressionItem = this.expressionsList[index + indexOffset - groupsTillCurrent];
@@ -1424,6 +1427,23 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14241427
this.targetExpressionItem = targetEx.parent ? targetEx.parent : targetEx;
14251428
}
14261429

1430+
//Calculation of proper targetExpression in case of multiple nested groups
1431+
if (index + indexOffset !== 0) {
1432+
let parentCount = 0;
1433+
let item = this.targetExpressionItem;
1434+
do {
1435+
parentCount++;
1436+
item = item.parent;
1437+
}
1438+
while (item.parent);
1439+
1440+
if (key.code == 'ArrowDown') parentCount--;
1441+
1442+
for (let index = 0; index < parentCount - groupsTillCurrent; index++) {
1443+
if (this.targetExpressionItem.parent) this.targetExpressionItem = this.targetExpressionItem.parent;
1444+
}
1445+
}
1446+
14271447
//If should drop under AND/OR => drop over first chip in that AND/OR's group
14281448
if (under) {
14291449
this.targetElement = this.targetElement.nextElementSibling.firstElementChild as HTMLElement;
@@ -1432,7 +1452,6 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14321452
}
14331453
}
14341454

1435-
14361455
const before = this.getPreviousChip(this.dropGhostElement);
14371456
const after = this.getNextChip(this.dropGhostElement);
14381457

0 commit comments

Comments
 (0)