Skip to content

Commit 9733474

Browse files
committed
fix(query-builder): drop ghost for group root now in proper place for keyboard
1 parent cc4b799 commit 9733474

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
534534
* Disables the select entity dropdown at the root level after the initial selection.
535535
*/
536536
public get disableEntityChange(): boolean {
537-
537+
538538
return !this.parentExpression && this.selectedEntity ? this.queryBuilder.disableEntityChange : false;
539539
}
540-
540+
541541
public get level(): number {
542542
let parent = this.elRef.nativeElement.parentElement;
543543
let _level = 0;
@@ -1159,11 +1159,11 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
11591159

11601160
public onChipDropped() {
11611161
if (!this.sourceElement || !this.sourceExpressionItem || !this.targetElement) return;
1162-
1162+
11631163
//console.log('Move: [', this.sourceElement.children[0].textContent.trim(), (this.dropUnder ? '] under: [' : '] over:'), this.targetExpressionItem)
11641164
this.moveDraggedChipToNewLocation(this.targetExpressionItem)
11651165
this.resetDragAndDrop(true);
1166-
1166+
11671167
this.exitEditAddMode();
11681168
}
11691169

@@ -1196,10 +1196,10 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
11961196
public onAddConditionEnter(addConditionElement: HTMLElement, rootGroup: ExpressionGroupItem) {
11971197
//console.log('onAddConditionEnter', addConditionElement);
11981198
if (!this.sourceElement || !this.sourceExpressionItem) return;
1199-
1199+
12001200
const lastElement = addConditionElement.parentElement.previousElementSibling.lastElementChild;
12011201
if (lastElement == this.dropGhostChipNode) return;
1202-
1202+
12031203
//simulate entering in the lower part of the last chip/group
12041204
this.onChipEnter(lastElement as HTMLElement,
12051205
rootGroup.children[rootGroup.children.length - 1],
@@ -1271,7 +1271,7 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
12711271
(this.dropGhostChipNode as HTMLElement)?.remove();
12721272
this.dropGhostChipNode = dragCopy;
12731273
this.dropUnder = true;
1274-
appendToElement.parentNode.insertBefore(this.dropGhostChipNode, appendToElement.nextSibling);
1274+
appendToElement.parentNode.insertBefore(this.dropGhostChipNode, appendToElement.nextElementSibling);
12751275
}
12761276

12771277
this.dropUnder = overrideDropUnder == null ? this.dropUnder : overrideDropUnder;
@@ -1428,6 +1428,13 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14281428
const before = this.getPreviousChip(this.dropGhostElement);
14291429
const after = this.getNextChip(this.dropGhostElement);
14301430

1431+
//If should drop under group root => drop over first chip in that group
1432+
if (this.targetElement.className.indexOf("igx-filter-tree__expression-context-menu") !== -1 && under) {
1433+
this.targetElement = this.targetElement.nextElementSibling.firstElementChild as HTMLElement;
1434+
if (this.targetElement === this.dropGhostChipNode) this.targetElement = this.targetElement.nextElementSibling as HTMLElement;
1435+
under = false;
1436+
}
1437+
14311438
this.renderDropGhostChip(this.targetElement, under, true, overrideDropUnder);
14321439

14331440
//If it's the first arrow hit OR drop ghost is not displayed OR hasn't actually moved => move one more step in the same direction
@@ -1439,8 +1446,10 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14391446
}
14401447
} else {
14411448
//Dropping on '+ Condition button' => drop as last condition in the root group
1442-
let lastElement = this.getPreviousChip(this.dropZonesList[this.dropZonesList.length - 1].parentElement);
1443-
lastElement = lastElement === this.dropGhostChipNode ? this.getPreviousChip(lastElement as HTMLElement) : lastElement;
1449+
let lastElement = this.dropZonesList[this.dropZonesList.length - 1].parentElement.previousElementSibling
1450+
if (lastElement.className.indexOf("igx-filter-tree__expression-section") !== -1) lastElement = lastElement.lastElementChild;
1451+
if (lastElement.className.indexOf("igx-filter-tree__subquery") !== -1) lastElement = lastElement.previousElementSibling
1452+
if (lastElement === this.dropGhostChipNode) lastElement = lastElement.previousElementSibling;
14441453

14451454
const getParentExpression = (expression: ExpressionItem) => {
14461455
return expression.parent ? getParentExpression(expression.parent) : expression
@@ -1494,27 +1503,26 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14941503

14951504
//Gets all chip elements owned by this tree (discard child trees), AND/OR group roots and '+condition' button, flatten out as a list of HTML elements
14961505
private getListedDropZones(): HTMLElement[] {
1497-
const viableDropAreaSelector = `.igx-filter-tree__expression-item:not([style*="display:none"]):not(.${this.dropGhostClass}),
1498-
.igx-filter-tree__inputs:not(.igx-query-builder__main > .igx-filter-tree__inputs),
1499-
.igx-filter-tree__buttons > .igx-button:first-of-type,
1500-
.igx-filter-tree__group-expression-menu`;
1506+
const viableDropAreaSelector = `.igx-filter-tree__expression-item[igxDrop]:not(.${this.dropGhostClass}),` + /*Condition chip*/ //TODO :not(.${this.dropGhostClass}) might be redundant now
1507+
`.igx-filter-tree__subquery:has([igxDrop]),` + /*Chip in edit*/
1508+
`.igx-filter-tree__buttons > .igx-button[igxDrop]:first-of-type,` + /*Add Condition Button*/
1509+
`.igx-filter-tree__expression-context-menu[igxDrop]`; /*AND/OR group root*/
15011510

15021511
const expressionElementList = (this.el.nativeElement as HTMLElement).querySelectorAll(viableDropAreaSelector);
15031512
const ownChipElements = [];
15041513

1505-
expressionElementList.forEach(element => {
1506-
if (isNotFromThisTree(this.el.nativeElement, element))
1507-
return;
1508-
ownChipElements.push(element);
1509-
});
1510-
1511-
function isNotFromThisTree(qb, parent) {
1514+
const isNotFromThisTree = (qb, parent) => {
15121515
if (parent == qb) return false;
15131516
else if (parent?.style?.display === "none" || parent.classList.contains('igx-query-builder-tree')) return true;
15141517
else if (parent.parentElement) return isNotFromThisTree(qb, parent.parentElement);
15151518
else return false;
15161519
}
15171520

1521+
expressionElementList.forEach(element => {
1522+
if (!isNotFromThisTree(this.el.nativeElement, element) && getComputedStyle(element).display !== 'none')
1523+
ownChipElements.push(element);
1524+
});
1525+
15181526
return ownChipElements;
15191527
}
15201528

@@ -1728,10 +1736,10 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
17281736
// }
17291737

17301738
const operator = expressionItem ?
1731-
expressionItem.operator :
1732-
this.expressionTree ?
1733-
this.expressionTree.operator :
1734-
this.initialOperator;
1739+
expressionItem.operator :
1740+
this.expressionTree ?
1741+
this.expressionTree.operator :
1742+
this.initialOperator;
17351743
return operator;
17361744
}
17371745

0 commit comments

Comments
 (0)