Skip to content

Commit f565d92

Browse files
authored
fix(adv-filter): commit edits via the context menu (#12721)
1 parent 20db2d2 commit f565d92

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
IgxStringFilteringOperand
1010
} from '../../data-operations/filtering-condition';
1111
import { GridFunctions } from '../../test-utils/grid-functions.spec';
12-
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
12+
import { FilteringExpressionsTree, IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
1313
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
1414
import {
1515
IgxGridAdvancedFilteringColumnGroupComponent,
@@ -2298,6 +2298,71 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
22982298
verifyOperatorLine(operatorLine, 'or');
22992299
}));
23002300

2301+
it('Should apply changes in the group\'s operator made via its context menu buttons.', fakeAsync(() => {
2302+
// Apply advanced filter through API.
2303+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
2304+
tree.filteringOperands.push({
2305+
fieldName: 'Downloads', searchVal: 100, condition: IgxNumberFilteringOperand.instance().condition('greaterThan')
2306+
});
2307+
const orTree = new FilteringExpressionsTree(FilteringLogic.Or);
2308+
orTree.filteringOperands.push({
2309+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
2310+
ignoreCase: true
2311+
});
2312+
orTree.filteringOperands.push({
2313+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
2314+
ignoreCase: true
2315+
});
2316+
tree.filteringOperands.push(orTree);
2317+
grid.advancedFilteringExpressionsTree = tree;
2318+
fix.detectChanges();
2319+
2320+
// Open Advanced Filtering dialog.
2321+
grid.openAdvancedFilteringDialog();
2322+
fix.detectChanges();
2323+
2324+
// Verify current operator of inner group.
2325+
let operatorLine = GridFunctions.getAdvancedFilteringTreeGroupOperatorLine(fix, [1]);
2326+
verifyOperatorLine(operatorLine, 'or');
2327+
2328+
// Verify the advancedFilteringExpressionsTree inner group's filteringOperand's operator
2329+
expect(grid.advancedFilteringExpressionsTree.filteringOperands.length).toEqual(2);
2330+
expect((grid.advancedFilteringExpressionsTree.filteringOperands[1] as IFilteringExpressionsTree).operator).toEqual(1);
2331+
2332+
// Click the innner group's operator line.
2333+
operatorLine.click();
2334+
tick(400);
2335+
fix.detectChanges();
2336+
2337+
// Click the 'and' button of the button group in the context menu.
2338+
const buttonGroup = GridFunctions.getAdvancedFilteringContextMenuButtonGroup(fix);
2339+
const andOperatorButton: any = Array.from(buttonGroup.querySelectorAll('.igx-button-group__item'))
2340+
.find((b: any) => b.textContent.toLowerCase() === 'and');
2341+
andOperatorButton.click();
2342+
fix.detectChanges();
2343+
2344+
// Verify new operator of inner group.
2345+
operatorLine = GridFunctions.getAdvancedFilteringTreeGroupOperatorLine(fix, [1]);
2346+
verifyOperatorLine(operatorLine, 'and');
2347+
2348+
// Apply new advanced filtering logic
2349+
GridFunctions.clickAdvancedFilteringApplyButton(fix);
2350+
tick(100);
2351+
fix.detectChanges();
2352+
2353+
// Open the advanced filtering dialog
2354+
grid.openAdvancedFilteringDialog();
2355+
fix.detectChanges();
2356+
2357+
// Verify the operator of inner group should persist as "And"
2358+
operatorLine = GridFunctions.getAdvancedFilteringTreeGroupOperatorLine(fix, [1]);
2359+
verifyOperatorLine(operatorLine, 'and');
2360+
2361+
// Verify the advancedFilteringExpressionsTree inner group's filteringOperand's operator
2362+
expect(grid.advancedFilteringExpressionsTree.filteringOperands.length).toEqual(2);
2363+
expect((grid.advancedFilteringExpressionsTree.filteringOperands[1] as IFilteringExpressionsTree).operator).toEqual(0);
2364+
}));
2365+
23012366
it('Should ungroup the group\'s children and append them to next parent group when click \'ungroup\' from context menu.',
23022367
fakeAsync(() => {
23032368
// Apply advanced filter through API.
@@ -2355,6 +2420,25 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
23552420
firstItem = GridFunctions.getAdvancedFilteringTreeItem(fix, [index]); // expression
23562421
expect(firstItem.classList.contains(ADVANCED_FILTERING_EXPRESSION_ITEM_CLASS)).toBe(true);
23572422
}
2423+
2424+
// Should apply this change to the advancedFilteringExpressionsTree
2425+
GridFunctions.clickAdvancedFilteringApplyButton(fix);
2426+
tick(100);
2427+
fix.detectChanges();
2428+
2429+
// Open the advanced filtering dialog
2430+
grid.openAdvancedFilteringDialog();
2431+
fix.detectChanges();
2432+
2433+
// Verify the layout after as above
2434+
rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix); // group
2435+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(3);
2436+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(3);
2437+
// Verify three expression in the root group are what remains, no inner groups
2438+
for (let index = 0; index < 3; index++) {
2439+
firstItem = GridFunctions.getAdvancedFilteringTreeItem(fix, [index]); // expression
2440+
expect(firstItem.classList.contains(ADVANCED_FILTERING_EXPRESSION_ITEM_CLASS)).toBe(true);
2441+
}
23582442
}));
23592443

23602444
it('Ungroup button of the root group\'s context menu should be disabled.',
@@ -2437,6 +2521,26 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
24372521

24382522
firstItem = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]); // expression
24392523
expect(firstItem.classList.contains(ADVANCED_FILTERING_EXPRESSION_ITEM_CLASS)).toBe(true);
2524+
2525+
// Should apply this change to the advancedFilteringExpressionsTree
2526+
GridFunctions.clickAdvancedFilteringApplyButton(fix);
2527+
tick(100);
2528+
fix.detectChanges();
2529+
2530+
// Open the advanced filtering dialog
2531+
grid.openAdvancedFilteringDialog();
2532+
fix.detectChanges();
2533+
2534+
// Verify the layout after as above
2535+
rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix); // group
2536+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(1);
2537+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(1);
2538+
2539+
firstItem = GridFunctions.getAdvancedFilteringTreeItem(fix, [0]); // expression
2540+
expect(firstItem.classList.contains(ADVANCED_FILTERING_EXPRESSION_ITEM_CLASS)).toBe(true);
2541+
2542+
// Verify the advancedFilteringExpressionsTree filteringOperands operator
2543+
expect(grid.advancedFilteringExpressionsTree.filteringOperands.length).toEqual(1);
24402544
}));
24412545

24422546
it('Should close the context menu when clicking its close button.' , fakeAsync(() => {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ export class IgxQueryBuilderComponent extends DisplayDensityBase implements Afte
806806
}
807807

808808
this.clearSelection();
809+
this.commitOperandEdit();
809810
}
810811

811812
/**
@@ -822,13 +823,15 @@ export class IgxQueryBuilderComponent extends DisplayDensityBase implements Afte
822823
}
823824

824825
this.clearSelection();
826+
this.commitOperandEdit();
825827
}
826828

827829
/**
828830
* @hidden @internal
829831
*/
830832
public selectFilteringLogic(event: IButtonGroupEventArgs) {
831833
this.contextualGroup.operator = event.index as FilteringLogic;
834+
this.commitOperandEdit();
832835
}
833836

834837
/**

0 commit comments

Comments
 (0)