Skip to content

Commit b3d2efc

Browse files
committed
fix(query-builder): test all passing now
1 parent b641658 commit b3d2efc

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

projects/igniteui-angular/src/lib/query-builder/query-builder-drag.service.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class IgxQueryBuilderDragService {
101101
}
102102

103103
//If entering the one that's been picked up don't do any thing
104-
if (targetExpressionItem == this.dropGhostExpression) {
104+
if (targetExpressionItem === this.dropGhostExpression) {
105105
return;
106106
}
107107

@@ -164,7 +164,7 @@ export class IgxQueryBuilderDragService {
164164
* @param targetExpressionItem The expressionItem of the drop area chip that's been dragged to
165165
*/
166166
public onDivDropped(targetExpressionItem: ExpressionItem) {
167-
if (targetExpressionItem != this._sourceExpressionItem) {
167+
if (targetExpressionItem !== this._sourceExpressionItem) {
168168
this.onChipDropped();
169169
}
170170
}
@@ -293,7 +293,7 @@ export class IgxQueryBuilderDragService {
293293

294294
/** Make a copy of the _sourceExpressionItem's chip and paste it in the tree north or south of the _targetExpressionItem's chip */
295295
private renderDropGhostChip(appendUnder: boolean): void {
296-
if (appendUnder != this._dropUnder || this.isKeyboardDrag) {
296+
if (appendUnder !== this._dropUnder || this.isKeyboardDrag) {
297297
this.clearDropGhost();
298298

299299
//Copy dragged chip
@@ -321,8 +321,12 @@ export class IgxQueryBuilderDragService {
321321
if (!this.isKeyboardDrag && this.getDragGhostElement && (!this._ghostChipMousemoveSubscription$ || this._ghostChipMousemoveSubscription$?.closed === true)) {
322322
const mouseMoves = fromEvent<MouseEvent>(this.getDragGhostElement, 'mousemove');
323323

324+
//When mouse moves and there is a drop ghost => trigger onChipLeave to check if the drop ghost has to be removed
325+
//effectively solving the case when mouse leaves the QB and a drop ghost is still in place
324326
this._ghostChipMousemoveSubscription$ = mouseMoves.pipe(sampleTime(100)).subscribe(() => {
325-
this.onChipLeave();
327+
if (this.getDropGhostElement) {
328+
this.onChipLeave();
329+
}
326330
});
327331
}
328332

@@ -385,16 +389,16 @@ export class IgxQueryBuilderDragService {
385389
// }))
386390
.pipe(filter(event => !event.repeat))
387391
.subscribe(e => {
388-
if (e.key == 'Escape') {
392+
if (e.key === 'Escape') {
389393
//TODO cancel mouse drag once it's implemented in igx-chip draggable
390394
this.resetDragAndDrop(false);
391395
//Regain focus on the drag icon after keyboard drag cancel
392396
if (this.isKeyboardDrag) {
393397
(this._sourceElement.firstElementChild.firstElementChild.firstElementChild.firstElementChild as HTMLElement).focus();
394398
}
395-
} else if (e.key == 'ArrowUp' || e.key == 'ArrowDown') {
399+
} else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
396400
this.arrowDrag(e.key);
397-
} else if (e.key == 'Enter' || e.key == 'Space') {
401+
} else if (e.key === 'Enter' || e.key === 'Space') {
398402
//this.platform.isActivationKey(eventArgs) Maybe use this rather that Enter/Space?
399403
this.onChipDropped();
400404
this._keyboardSubscription$.unsubscribe();
@@ -421,10 +425,10 @@ export class IgxQueryBuilderDragService {
421425
}
422426

423427
let newKeyIndexOffset = this._keyDragCurrentIndex;
424-
if (key == 'ArrowUp') {
428+
if (key === 'ArrowUp') {
425429
//decrease index capped at top of tree
426430
newKeyIndexOffset && newKeyIndexOffset--;
427-
} else if (key == 'ArrowDown') {
431+
} else if (key === 'ArrowDown') {
428432
//increase index capped at bottom of tree
429433
newKeyIndexOffset < this._possibleDropLocations.length - 1 && newKeyIndexOffset++;
430434
} else {
@@ -433,7 +437,7 @@ export class IgxQueryBuilderDragService {
433437
}
434438

435439
//if drop location has no change
436-
if (newKeyIndexOffset != this._keyDragCurrentIndex || this._isKeyDragsFirstMove) {
440+
if (newKeyIndexOffset !== this._keyDragCurrentIndex || this._isKeyDragsFirstMove) {
437441
this._keyDragCurrentIndex = newKeyIndexOffset;
438442

439443
const newDropTarget = this._possibleDropLocations[this._keyDragCurrentIndex];

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@ describe('IgxQueryBuilder', () => {
24302430
expect(dropGhost).toBeDefined();
24312431
expect(dropGhost.innerText).toBe('My Drop here to insert');
24322432
}));
2433-
});
2433+
});
24342434

24352435
describe('Drag and drop', () => {
24362436
const ROW_HEIGHT = 40;
@@ -2657,8 +2657,12 @@ describe('IgxQueryBuilder', () => {
26572657
dragDir.onPointerDown({ pointerId: 1, pageX: draggedChipCenter.X, pageY: draggedChipCenter.Y });
26582658
fix.detectChanges();
26592659

2660+
//trigger ghost
2661+
QueryBuilderFunctions.dragMove(dragDir, draggedChipCenter.X + 50, draggedChipCenter.Y - 50);
2662+
fix.detectChanges();
2663+
26602664
//drag
2661-
QueryBuilderFunctions.dragMove(dragDir, draggedChipCenter.X, draggedChipCenter.Y - 2 * ROW_HEIGHT, true);
2665+
QueryBuilderFunctions.dragMove(dragDir, draggedChipCenter.X + 50, draggedChipCenter.Y - 50, true);
26622666
fix.detectChanges();
26632667

26642668
chipComponents = QueryBuilderFunctions.getVisibleChips(fix);
@@ -2742,6 +2746,7 @@ describe('IgxQueryBuilder', () => {
27422746

27432747
//move over +Condition
27442748
QueryBuilderFunctions.dragMove(dragDir, addConditionButtonCenter.X, addConditionButtonCenter.Y);
2749+
fix.detectChanges();
27452750

27462751
const dropGhost = QueryBuilderFunctions.getDropGhost(fix) as HTMLElement;
27472752
chipComponents = QueryBuilderFunctions.getVisibleChips(fix);

0 commit comments

Comments
 (0)