Skip to content

Commit 2b5cc7a

Browse files
wnvkoCopilotdamyanpetev
authored
fix(ESF): move custom dialog out of ESF markup (#17136)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Damyan Petev <damyanpetev@users.noreply.github.com>
1 parent 56e2713 commit 2b5cc7a

12 files changed

+77
-71
lines changed

projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-conditional-filter.component.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,4 @@
4343
}
4444
</div>
4545
</igx-drop-down>
46-
47-
<igx-excel-style-custom-dialog
48-
#customDialog
49-
[column]="esf.column"
50-
[filteringService]="esf.grid.filteringService"
51-
[overlayComponentId]="esf.overlayComponentId">
52-
</igx-excel-style-custom-dialog>
5346
}

projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-conditional-filter.component.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BaseFilteringComponent } from './base-filtering.component';
66
import { NgClass } from '@angular/common';
77
import { IgxDropDownComponent, IgxDropDownItemComponent, IgxDropDownItemNavigationDirective, ISelectionEventArgs } from 'igniteui-angular/drop-down';
88
import { IgxIconComponent } from 'igniteui-angular/icon';
9-
import { AbsoluteScrollStrategy, AutoPositionStrategy, GridColumnDataType, HorizontalAlignment, IFilteringExpression, IFilteringOperation, OverlaySettings, PlatformUtil, VerticalAlignment } from 'igniteui-angular/core';
9+
import { AbsoluteScrollStrategy, AutoPositionStrategy, GridColumnDataType, HorizontalAlignment, IFilteringExpression, IFilteringOperation, IgxOverlayService, OverlaySettings, PlatformUtil, PositionSettings, VerticalAlignment } from 'igniteui-angular/core';
1010

1111

1212
/**
@@ -15,17 +15,12 @@ import { AbsoluteScrollStrategy, AutoPositionStrategy, GridColumnDataType, Horiz
1515
@Component({
1616
selector: 'igx-excel-style-conditional-filter',
1717
templateUrl: './excel-style-conditional-filter.component.html',
18-
imports: [NgClass, IgxDropDownItemNavigationDirective, IgxIconComponent, IgxDropDownComponent, IgxDropDownItemComponent, IgxExcelStyleCustomDialogComponent]
18+
imports: [NgClass, IgxDropDownItemNavigationDirective, IgxIconComponent, IgxDropDownComponent, IgxDropDownItemComponent]
1919
})
2020
export class IgxExcelStyleConditionalFilterComponent implements OnDestroy {
2121
public esf = inject(BaseFilteringComponent);
2222
protected platform = inject(PlatformUtil);
23-
24-
/**
25-
* @hidden @internal
26-
*/
27-
@ViewChild('customDialog', { read: IgxExcelStyleCustomDialogComponent })
28-
public customDialog: IgxExcelStyleCustomDialogComponent;
23+
private _overlayService = inject<IgxOverlayService>(IgxOverlayService);
2924

3025
/**
3126
* @hidden @internal
@@ -133,20 +128,41 @@ export class IgxExcelStyleConditionalFilterComponent implements OnDestroy {
133128
* @hidden @internal
134129
*/
135130
public onSubMenuSelection(eventArgs: ISelectionEventArgs) {
131+
const positionSettings: PositionSettings = {
132+
horizontalDirection: HorizontalAlignment.Center,
133+
verticalDirection: VerticalAlignment.Middle,
134+
horizontalStartPoint: HorizontalAlignment.Center,
135+
verticalStartPoint: VerticalAlignment.Middle
136+
};
137+
const overlaySettings: OverlaySettings = {
138+
target: this.esf.grid.tbody.nativeElement,
139+
modal: false,
140+
closeOnOutsideClick: true,
141+
positionStrategy: new AutoPositionStrategy(positionSettings),
142+
scrollStrategy: new AbsoluteScrollStrategy(),
143+
};
144+
const overlayId = this._overlayService.attach(IgxExcelStyleCustomDialogComponent, this.esf.grid.bodyViewContainerRef, overlaySettings);
145+
const overlayInfo = this._overlayService.getOverlayById(overlayId);
146+
const customDialog = overlayInfo.componentRef!.instance as IgxExcelStyleCustomDialogComponent;
147+
148+
customDialog.esf = this.esf;
149+
customDialog.column = this.esf.column;
150+
customDialog.filteringService = this.esf.grid.filteringService;
151+
customDialog.overlayComponentId = overlayId;
136152
if (this.esf.expressionsList && this.esf.expressionsList.length &&
137-
this.esf.expressionsList[0].expression.condition.name !== 'in') {
138-
this.customDialog.expressionsList = this.esf.expressionsList;
153+
this.esf.expressionsList[0].expression.condition?.name !== 'in') {
154+
customDialog.expressionsList = this.esf.expressionsList;
139155
} else {
140-
this.customDialog.expressionsList = this.customDialog.expressionsList.filter(e => e.expression.fieldName === this.esf.column.field && e.expression.condition);
156+
customDialog.expressionsList = customDialog.expressionsList.filter(e => e.expression.fieldName === this.esf.column.field && e.expression.condition);
141157
}
158+
customDialog.selectedOperator = eventArgs.newSelection.value;
142159

143-
this.customDialog.selectedOperator = eventArgs.newSelection.value;
144160
eventArgs.cancel = true;
145161
if (this.esf.overlayComponentId) {
146162
this.esf.hide();
147163
}
148164
this.subMenu.close();
149-
this.customDialog.open(this.esf.mainDropdown.nativeElement);
165+
this._overlayService.show(overlayId);
150166
}
151167

152168
/**

projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-custom-dialog.component.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<article #toggle igxToggle
1+
<article
22
class="igx-excel-filter__secondary"
33
[ngClass]="{
44
'igx-excel-filter__secondary--cosy': grid.gridSize === '2',
55
'igx-excel-filter__secondary--compact': grid.gridSize === '1'
66
}"
7-
(keydown)="onKeyDown($event)"
8-
(opening)="onCustomDialogOpening()"
9-
(opened)="onCustomDialogOpened()">
7+
(keydown)="onKeyDown($event)">
108
<header class="igx-excel-filter__secondary-header">
119
<h4 class="ig-typography__h6">
1210
{{ grid.resourceStrings.igx_grid_excel_custom_dialog_header }}{{ column.header || column.field }}

projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-custom-dialog.component.ts

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
1-
import { Component, Input, ChangeDetectorRef, ViewChild, AfterViewInit, TemplateRef, ViewChildren, QueryList, ElementRef, inject } from '@angular/core';
2-
import { IgxFilteringService } from '../grid-filtering.service';
3-
import { ILogicOperatorChangedArgs, IgxExcelStyleDefaultExpressionComponent } from './excel-style-default-expression.component';
4-
import { IgxExcelStyleDateExpressionComponent } from './excel-style-date-expression.component';
5-
import { ExpressionUI } from './common';
61
import { NgClass } from '@angular/common';
7-
import { BaseFilteringComponent } from './base-filtering.component';
8-
import { IgxButtonDirective, IgxToggleDirective } from 'igniteui-angular/directives';
2+
import { ChangeDetectorRef, Component, ElementRef, Input, QueryList, TemplateRef, ViewChild, ViewChildren, inject } from '@angular/core';
3+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4+
import { ColumnType, FilteringLogic, GridColumnDataType, IgxBooleanFilteringOperand, IgxDateFilteringOperand, IgxDateTimeFilteringOperand, IgxNumberFilteringOperand, IgxOverlayService, IgxStringFilteringOperand, IgxTimeFilteringOperand, PlatformUtil } from 'igniteui-angular/core';
5+
import { IgxButtonDirective } from 'igniteui-angular/directives';
96
import { IgxIconComponent } from 'igniteui-angular/icon';
10-
import { AbsoluteScrollStrategy, AutoPositionStrategy, ColumnType, FilteringLogic, GridColumnDataType, HorizontalAlignment, IgxBooleanFilteringOperand, IgxDateFilteringOperand, IgxDateTimeFilteringOperand, IgxNumberFilteringOperand, IgxOverlayService, IgxStringFilteringOperand, IgxTimeFilteringOperand, OverlaySettings, PlatformUtil, PositionSettings, VerticalAlignment } from 'igniteui-angular/core';
7+
import { IgxFilteringService } from '../grid-filtering.service';
8+
import { BaseFilteringComponent } from './base-filtering.component';
9+
import { ExpressionUI } from './common';
10+
import { IgxExcelStyleDateExpressionComponent } from './excel-style-date-expression.component';
11+
import { ILogicOperatorChangedArgs, IgxExcelStyleDefaultExpressionComponent } from './excel-style-default-expression.component';
1112

1213
/**
1314
* @hidden
1415
*/
1516
@Component({
1617
selector: 'igx-excel-style-custom-dialog',
1718
templateUrl: './excel-style-custom-dialog.component.html',
18-
imports: [IgxToggleDirective, NgClass, IgxExcelStyleDateExpressionComponent, IgxExcelStyleDefaultExpressionComponent, IgxButtonDirective, IgxIconComponent]
19+
imports: [NgClass, IgxExcelStyleDateExpressionComponent, IgxExcelStyleDefaultExpressionComponent, IgxButtonDirective, IgxIconComponent]
1920
})
20-
export class IgxExcelStyleCustomDialogComponent implements AfterViewInit {
21+
export class IgxExcelStyleCustomDialogComponent {
2122
protected overlayService = inject(IgxOverlayService);
2223
private cdr = inject(ChangeDetectorRef);
2324
protected platform = inject(PlatformUtil);
24-
public esf = inject(BaseFilteringComponent);
25+
public esf?: BaseFilteringComponent;
26+
27+
constructor() {
28+
this.overlayService.opening.pipe(takeUntilDestroyed()).subscribe((args) => {
29+
if (args.id === this.overlayComponentId)
30+
this.onCustomDialogOpening();
31+
});
32+
this.overlayService.opened.pipe(takeUntilDestroyed()).subscribe((args) => {
33+
if (args.id === this.overlayComponentId)
34+
this.onCustomDialogOpened();
35+
});
36+
37+
this.overlayService.closed.pipe(takeUntilDestroyed()).subscribe((args) => {
38+
if (args.id === this.overlayComponentId) {
39+
this.overlayService.detach(this.overlayComponentId);
40+
this.overlayComponentId = null;
41+
}
42+
});
43+
}
2544

2645
@Input()
2746
public expressionsList = new Array<ExpressionUI>();
@@ -38,9 +57,6 @@ export class IgxExcelStyleCustomDialogComponent implements AfterViewInit {
3857
@Input()
3958
public overlayComponentId: string;
4059

41-
@ViewChild('toggle', { read: IgxToggleDirective, static: true })
42-
public toggle: IgxToggleDirective;
43-
4460
@ViewChild('defaultExpressionTemplate', { read: TemplateRef })
4561
protected defaultExpressionTemplate: TemplateRef<any>;
4662

@@ -56,24 +72,6 @@ export class IgxExcelStyleCustomDialogComponent implements AfterViewInit {
5672
@ViewChildren(IgxExcelStyleDateExpressionComponent)
5773
private expressionDateComponents: QueryList<IgxExcelStyleDateExpressionComponent>;
5874

59-
private _customDialogPositionSettings: PositionSettings = {
60-
verticalDirection: VerticalAlignment.Middle,
61-
horizontalDirection: HorizontalAlignment.Center,
62-
horizontalStartPoint: HorizontalAlignment.Center,
63-
verticalStartPoint: VerticalAlignment.Middle
64-
};
65-
66-
private _customDialogOverlaySettings: OverlaySettings = {
67-
closeOnOutsideClick: true,
68-
modal: false,
69-
positionStrategy: new AutoPositionStrategy(this._customDialogPositionSettings),
70-
scrollStrategy: new AbsoluteScrollStrategy()
71-
};
72-
73-
public ngAfterViewInit(): void {
74-
this._customDialogOverlaySettings.outlet = this.grid.outlet;
75-
}
76-
7775
public get template(): TemplateRef<any> {
7876
if (this.column.dataType === GridColumnDataType.Date) {
7977
return this.dateExpressionTemplate;
@@ -98,15 +96,6 @@ export class IgxExcelStyleCustomDialogComponent implements AfterViewInit {
9896
}
9997
}
10098

101-
public open(esf) {
102-
this._customDialogOverlaySettings.target =
103-
this.overlayComponentId ?
104-
this.grid.rootGrid ? this.grid.rootGrid.nativeElement : this.grid.nativeElement :
105-
esf;
106-
this.toggle.open(this._customDialogOverlaySettings);
107-
this.overlayComponentId = this.toggle.overlayId;
108-
}
109-
11099
public onClearButtonClick() {
111100
this.filteringService.clearFilter(this.column.field);
112101
this.selectedOperator = null;
@@ -117,14 +106,13 @@ export class IgxExcelStyleCustomDialogComponent implements AfterViewInit {
117106
public closeDialog() {
118107
if (this.overlayComponentId) {
119108
this.overlayService.hide(this.overlayComponentId);
109+
this.overlayService.detach(this.overlayComponentId);
120110
this.overlayComponentId = null;
121-
} else {
122-
this.toggle.close();
123111
}
124112
}
125113

126114
public cancelDialog() {
127-
this.esf.cancel();
115+
this.esf?.cancel();
128116
this.closeDialog();
129117
}
130118

projects/igniteui-angular/grids/core/src/filtering/excel-style/excel-style-default-expression.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export class IgxExcelStyleDefaultExpressionComponent implements AfterViewInit {
135135
this.expressionUI.expression.condition = this.getCondition(value);
136136
this.expressionUI.expression.conditionName = value;
137137

138-
this.focus();
138+
if (!this.expressionUI.expression.condition.isUnary) {
139+
this.focus();
140+
}
139141
}
140142

141143
public getCondition(value: string): IFilteringOperation {

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,10 @@ export abstract class IgxGridBaseDirective implements GridType,
13281328
@ViewChild('tbody', { static: true })
13291329
public tbody: ElementRef;
13301330

1331+
/** @hidden @internal */
1332+
@ViewChild("bodyViewContainerRef", { read: ViewContainerRef, static: true })
1333+
public bodyViewContainerRef?: ViewContainerRef;
1334+
13311335
@ViewChild(IgxGridBodyDirective, { static: true, read: ElementRef })
13321336
protected tbodyContainer: ElementRef;
13331337

projects/igniteui-angular/grids/grid/src/grid-filtering-ui.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4222,6 +4222,7 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
42224222
fix.detectChanges();
42234223

42244224
// Open excel style custom filtering dialog and verify its size
4225+
setElementSize(grid.nativeElement, ɵSize.Large);
42254226
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'ProductName');
42264227

42274228
GridFunctions.clickExcelFilterCascadeButton(fix);
@@ -7582,7 +7583,7 @@ const verifyExcelCustomFilterSize = (fix: ComponentFixture<any>, expectedSize:
75827583
const verifyGridSubmenuSize = (gridNativeElement: HTMLElement, expectedSize: ɵSize) => {
75837584
const outlet = gridNativeElement.querySelector('.igx-grid__outlet');
75847585
const dropdowns = Array.from(outlet.querySelectorAll('.igx-drop-down__list'));
7585-
const visibleDropdown: any = dropdowns.find((d) => !d.classList.contains('igx-toggle--hidden'));
7586+
const visibleDropdown: any = dropdowns[0];
75867587
const dropdownItems = visibleDropdown.querySelectorAll('igx-drop-down-item');
75877588

75887589
dropdownItems.forEach((dropdownItem) => {

projects/igniteui-angular/grids/grid/src/grid.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158

159159
<ng-container *ngTemplateOutlet="template; context: { $implicit: this }"></ng-container>
160160
<div class="igx-grid__row-editing-outlet" igxOverlayOutlet #igxRowEditingOverlayOutlet></div>
161+
<ng-container #bodyViewContainerRef></ng-container>
161162
<igc-trial-watermark></igc-trial-watermark>
162163
</div>
163164
<div igxToggle #loadingOverlay>

projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
id="right" class="igx-grid__scroll-on-drag-right"></span>
126126
}
127127
<div class="igx-grid__row-editing-outlet" igxOverlayOutlet #igxRowEditingOverlayOutlet></div>
128+
<ng-container #bodyViewContainerRef></ng-container>
128129
@if (!this.parent) {
129130
<igc-trial-watermark></igc-trial-watermark>
130131
}

projects/igniteui-angular/grids/pivot-grid/src/pivot-grid.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
</ng-template>
6161

6262
<ng-container *ngTemplateOutlet="template; context: { $implicit: this }"></ng-container>
63+
<ng-container #bodyViewContainerRef></ng-container>
6364
<igc-trial-watermark></igc-trial-watermark>
6465
</div>
6566
<div igxToggle #loadingOverlay>

0 commit comments

Comments
 (0)