Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes for each version of this project will be documented in this file.

## 21.2.29

### Bug Fixes

- `IgxQueryBuilderComponent`
- Dropping a condition dragged with the mouse on another condition no longer leaves a timer running, so the application becomes stable again (`ApplicationRef.isStable`, `fixture.whenStable()`). Destroying the query builder while a condition is dragged no longer throws `Cannot read properties of null (reading 'getBoundingClientRect')` (#17804).

## 21.2.28

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed, ComponentFixture, waitForAsync, fakeAsync, tick } from '@angular/core/testing';
import { Component, DebugElement, provideZonelessChangeDetection, ViewChild } from '@angular/core';
import { Component, provideZonelessChangeDetection, ViewChild } from '@angular/core';
import { IgxTreeGridComponent } from './tree-grid.component';
import {
IgxTreeGridSimpleComponent, IgxTreeGridPrimaryForeignKeyComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { filter, fromEvent, sampleTime, Subscription } from 'rxjs';
import { IgxQueryBuilderTreeComponent } from './query-builder-tree.component';
import { ElementRef, Injectable } from '@angular/core';
import { ElementRef, Injectable, OnDestroy } from '@angular/core';
import { ExpressionGroupItem, ExpressionItem, ExpressionOperandItem, QueryBuilderSelectors } from './query-builder.common';
import { IgxChipComponent } from 'igniteui-angular/chips';

Expand All @@ -9,7 +9,7 @@ const Z_INDEX_TO_SET = 10010; //overlay z-index is 10005

/** @hidden @internal */
@Injectable()
export class IgxQueryBuilderDragService {
export class IgxQueryBuilderDragService implements OnDestroy {

/** The ExpressionItem that's actually the drop ghost's content */
public dropGhostExpression: ExpressionItem;
Expand Down Expand Up @@ -50,6 +50,12 @@ export class IgxQueryBuilderDragService {
this._queryBuilderTreeComponentElRef = el;
}

/** Stops listening to a drag in progress when the query builder tree is destroyed */
public ngOnDestroy(): void {
this.unsubscribeFromDragEvents();
clearTimeout(this._timeoutId);
}

/** When chip is picked up for dragging
*
* @param sourceDragElement The HTML element of the chip that's been dragged
Expand Down Expand Up @@ -84,9 +90,6 @@ export class IgxQueryBuilderDragService {
} else {
this.resetDragAndDrop(true);
}

this._ghostChipMousemoveSubscription$?.unsubscribe();
this._keyboardSubscription$?.unsubscribe();
}

/** When mouse drag enters a chip's area
Expand Down Expand Up @@ -249,7 +252,6 @@ export class IgxQueryBuilderDragService {
public onChipDragIndicatorFocusOut() {
if (this._sourceElement?.style?.display !== 'none') {
this.resetDragAndDrop(true);
this._keyboardSubscription$?.unsubscribe();
}
}

Expand All @@ -260,15 +262,14 @@ export class IgxQueryBuilderDragService {
setTimeout(() => {
if (document.activeElement.className.indexOf(QueryBuilderSelectors.DRAG_INDICATOR) === -1) {
this.resetDragAndDrop(true);
this._keyboardSubscription$?.unsubscribe();
}
}, 0);
}
}

/** Checks if the dragged ghost is horizontally on the same line with the drop ghost*/
private dragGhostIsOnDropGhostRow() {
const dragGhostBounds = this.getDragGhostElement.getBoundingClientRect();
const dragGhostBounds = this.getDragGhostElement?.getBoundingClientRect();

const dropGhostBounds = this.getDropGhostElement?.nativeElement?.parentElement.getBoundingClientRect();

Expand Down Expand Up @@ -371,9 +372,17 @@ export class IgxQueryBuilderDragService {
this._queryBuilderTreeComponent._expressionTreeCopy = null;
this._sourceExpressionItem = null;
this._sourceElement = null;
//The drag is over, however it ended (moveEnd, a drop on a chip or a keyboard drop)
this.unsubscribeFromDragEvents();
}
}

/** Stops listening to the dragged ghost's mouse moves and to the drag and drop specific keys */
private unsubscribeFromDragEvents() {
this._ghostChipMousemoveSubscription$?.unsubscribe();
this._keyboardSubscription$?.unsubscribe();
}

/** Start listening for drag and drop specific keys */
private listenToKeyboard() {
this._keyboardSubscription$?.unsubscribe();
Expand All @@ -399,7 +408,6 @@ export class IgxQueryBuilderDragService {
} else if (e.key === 'Enter' || e.key === 'Space') {
//this.platform.isActivationKey(eventArgs) Maybe use this rather that Enter/Space?
this.onChipDropped();
this._keyboardSubscription$.unsubscribe();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitForAsync, TestBed, ComponentFixture, fakeAsync, tick, flush } from '@angular/core/testing';
import { waitForAsync, TestBed, ComponentFixture, fakeAsync, tick, flush, discardPeriodicTasks } from '@angular/core/testing';
import { FilteringExpressionsTree, FilteringLogic, IExpressionTree, IgxDateFilteringOperand, IgxNumberFilteringOperand, QueryBuilderResourceStringsEN, changei18n } from 'igniteui-angular/core';
import { IgxChipComponent } from 'igniteui-angular/chips';
import { IgxComboComponent } from 'igniteui-angular/combo';
Expand Down Expand Up @@ -3289,6 +3289,157 @@ describe('IgxQueryBuilder', () => {
expect(QueryBuilderFunctions.getChipContent(chipComponents[3].nativeElement)).toBe("OrderDate Today");
}));

describe('Drag subscriptions', () => {
// Post-drop chip focus timeout (DEFAULT_CHIP_FOCUS_DELAY in query-builder-tree.component.ts)
const CHIP_FOCUS_DELAY = 50;

// Mouse drags a condition over another condition's chip, keeping the pointer down
const dragOverChip = (draggedChip: IgxChipComponent, targetChip: IgxChipComponent) => {
const dragDir = draggedChip.dragDirective;
const draggedChipCenter = QueryBuilderFunctions.getElementCenter(draggedChip.chipArea.nativeElement);
dragDir.onPointerDown({ pointerId: 1, pageX: draggedChipCenter.X, pageY: draggedChipCenter.Y } as PointerEvent);
QueryBuilderFunctions.dragMove(dragDir, draggedChipCenter.X + 10, draggedChipCenter.Y + 10);
fix.detectChanges();

// The dragged condition collapses and the drop ghost is rendered, so the target is measured after each move
for (let i = 0; i < 2; i++) {
const targetChipCenter = QueryBuilderFunctions.getElementCenter(targetChip.chipArea.nativeElement);
QueryBuilderFunctions.dragMove(dragDir, targetChipCenter.X, targetChipCenter.Y);
fix.detectChanges();
}
};

// Releases the pointer over the target chip, so the drop is executed by the target chip (dragDrop)
// before the dragged chip ends its move (moveEnd)
const releaseOverChip = (draggedChip: IgxChipComponent, targetChip: IgxChipComponent) => {
const targetChipCenter = QueryBuilderFunctions.getElementCenter(targetChip.chipArea.nativeElement);
draggedChip.dragDirective.onPointerUp({ pointerId: 1, pageX: targetChipCenter.X, pageY: targetChipCenter.Y } as PointerEvent);
fix.detectChanges();
};

it('Should stop listening to the drag ghost and the keyboard when a condition is dropped on another condition.', fakeAsync(() => {
const dragService = queryBuilder.queryTree.dragService;
const draggedChip = chipComponents[0].componentInstance; // "OrderName Equals foo" chip
const targetChip = chipComponents[1].componentInstance; // "OrderId In Products / OrderId" chip
const targetChipDropSpy = spyOn(targetChip.dragDrop, 'emit').and.callThrough();
const moveEnd = draggedChip.moveEnd;
const moveEndEmit = moveEnd.emit.bind(moveEnd);
let dropsBeforeMoveEnd = -1;
spyOn(moveEnd, 'emit').and.callFake(args => {
dropsBeforeMoveEnd = targetChipDropSpy.calls.count();
moveEndEmit(args);
});

dragOverChip(draggedChip, targetChip);
expect(QueryBuilderFunctions.getDropGhost(fix)).not.toBeNull();
const ghostMousemoveSubscription = (dragService as any)._ghostChipMousemoveSubscription$;
const keyboardSubscription = (dragService as any)._keyboardSubscription$;
expect(ghostMousemoveSubscription.closed).toBeFalse();
expect(keyboardSubscription.closed).toBeFalse();

releaseOverChip(draggedChip, targetChip);
tick(CHIP_FOCUS_DELAY);
fix.detectChanges();

expect(targetChipDropSpy).toHaveBeenCalledTimes(1);
expect(dropsBeforeMoveEnd).toBe(1);
expect((queryBuilder.expressionTree.filteringOperands[0] as any).fieldName).toBe('OrderId');
expect((queryBuilder.expressionTree.filteringOperands[1] as any).fieldName).toBe('OrderName');
expect(ghostMousemoveSubscription.closed).toBeTrue();
expect(keyboardSubscription.closed).toBeTrue();
}));

it('Should let the application become stable after a condition is dropped on another condition.', async () => {
const draggedChip = chipComponents[0].componentInstance; // "OrderName Equals foo" chip
const targetChip = chipComponents[1].componentInstance; // "OrderId In Products / OrderId" chip
const targetChipDropSpy = spyOn(targetChip.dragDrop, 'emit').and.callThrough();

dragOverChip(draggedChip, targetChip);
releaseOverChip(draggedChip, targetChip);
expect(targetChipDropSpy).toHaveBeenCalledTimes(1);

// Only the post-drop chip focus timeout is left, the sampled drag ghost mousemove timer is gone (real timers)
let stable = fix.isStable();
for (let waited = 0; !stable && waited < 1000; waited += 20) {
await new Promise(resolve => setTimeout(resolve, 20));
stable = fix.isStable();
}
expect(stable).toBeTrue();
expect((queryBuilder.expressionTree.filteringOperands[0] as any).fieldName).toBe('OrderId');
});

it('Should listen to the drag ghost of a mouse drag that follows a drop on another condition.', fakeAsync(() => {
const dragService = queryBuilder.queryTree.dragService;
const firstChip = chipComponents[0].componentInstance; // "OrderName Equals foo" chip
const secondChip = chipComponents[1].componentInstance; // "OrderId In Products / OrderId" chip
const secondChipDropSpy = spyOn(secondChip.dragDrop, 'emit').and.callThrough();

// Drop the first condition on the second one
dragOverChip(firstChip, secondChip);
releaseOverChip(firstChip, secondChip);
tick(CHIP_FOCUS_DELAY);
fix.detectChanges();
expect(secondChipDropSpy).toHaveBeenCalledTimes(1);
const previousGhostMousemoveSubscription = (dragService as any)._ghostChipMousemoveSubscription$;

// Drag the condition that is first now (the "OrderId" one) over the next one
const draggedChip = QueryBuilderFunctions.getVisibleChips(fix)[0].componentInstance as IgxChipComponent;
UIInteractions.moveDragDirective(fix, draggedChip.dragDirective, 0, draggedChip.nativeElement.offsetHeight, false);
expect(QueryBuilderFunctions.getDropGhost(fix)).not.toBeNull();

const ghostMousemoveSubscription = (dragService as any)._ghostChipMousemoveSubscription$;
expect(ghostMousemoveSubscription).not.toBe(previousGhostMousemoveSubscription);
expect(ghostMousemoveSubscription.closed).toBeFalse();

// A mouse move over the new drag ghost is sampled and checked against the drop ghost
const chipLeaveSpy = spyOn(dragService, 'onChipLeave').and.callThrough();
draggedChip.dragDirective.ghostElement.dispatchEvent(new MouseEvent('mousemove'));
tick(100);
fix.detectChanges();
expect(chipLeaveSpy).toHaveBeenCalled();

// The second drag stays in progress
discardPeriodicTasks();
}));

it('Should stop listening to the drag ghost and the keyboard when destroyed during a mouse drag.', fakeAsync(() => {
const dragService = queryBuilder.queryTree.dragService;
const draggedChip = chipComponents[0].componentInstance; // "OrderName Equals foo" chip

UIInteractions.moveDragDirective(fix, draggedChip.dragDirective, 0, draggedChip.nativeElement.offsetHeight, false);
expect(QueryBuilderFunctions.getDropGhost(fix)).not.toBeNull();
const ghostMousemoveSubscription = (dragService as any)._ghostChipMousemoveSubscription$;
const keyboardSubscription = (dragService as any)._keyboardSubscription$;
const chipLeaveSpy = spyOn(dragService, 'onChipLeave').and.callThrough();

// A mouse move over the drag ghost that is still to be sampled when the query builder is destroyed
draggedChip.dragDirective.ghostElement.dispatchEvent(new MouseEvent('mousemove'));
fix.destroy();
tick(200);

expect(ghostMousemoveSubscription.closed).toBeTrue();
expect(keyboardSubscription.closed).toBeTrue();
expect(chipLeaveSpy).not.toHaveBeenCalled();
}));

it('Should remove the drop ghost when leaving a condition after the drag ghost is gone.', fakeAsync(() => {
const dragService = queryBuilder.queryTree.dragService;
const draggedChip = chipComponents[0].componentInstance; // "OrderName Equals foo" chip

UIInteractions.moveDragDirective(fix, draggedChip.dragDirective, 0, draggedChip.nativeElement.offsetHeight, false);
expect(QueryBuilderFunctions.getDropGhost(fix)).not.toBeNull();

draggedChip.dragDirective.ghostElement.remove();
expect(() => dragService.onChipLeave()).not.toThrow();
fix.detectChanges();

expect(QueryBuilderFunctions.getDropGhost(fix)).toBeNull();
expect(dragService.dropGhostExpression).toBeFalsy();

// The drag stays in progress
discardPeriodicTasks();
}));
});
});

describe('Resource Strings', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/hierarchical-grid/hierarchical-grid.sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ <h4 class="sample-title">Sample two</h4>
<igx-grid-toolbar-exporter></igx-grid-toolbar-exporter>
</igx-grid-toolbar-actions>
</igx-grid-toolbar>
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true"
[allowFiltering]="true">
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true"
[allowFiltering]="true"></igx-row-island>
</igx-row-island>
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData2'" [autoGenerate]="true" [allowFiltering]="true"></igx-row-island>
Expand Down
Loading