Skip to content

Commit ad36d9e

Browse files
authored
fix(qb): update expr tree after new group is added (#12863)
1 parent ca71abe commit ad36d9e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,63 @@ describe('IgxGrid - Advanced Filtering #grid - ', () => {
21442144
expect(GridFunctions.getAdvancedFilteringTreeChildItems(secondItem, false).length).toBe(1);
21452145
}));
21462146

2147+
it('Should respect the changes of the groups applied from the context menu.',
2148+
fakeAsync(() => {
2149+
// Apply advanced filter through API.
2150+
const tree = new FilteringExpressionsTree(FilteringLogic.And);
2151+
tree.filteringOperands.push({
2152+
fieldName: 'ProductName', searchVal: 'angular', condition: IgxStringFilteringOperand.instance().condition('contains'),
2153+
ignoreCase: true
2154+
});
2155+
tree.filteringOperands.push({
2156+
fieldName: 'ProductName', searchVal: 'script', condition: IgxStringFilteringOperand.instance().condition('contains'),
2157+
ignoreCase: true
2158+
});
2159+
grid.advancedFilteringExpressionsTree = tree;
2160+
fix.detectChanges();
2161+
2162+
// Verify the filter changes are applied.
2163+
expect(grid.filteredData.length).toEqual(0);
2164+
2165+
// Open Advanced Filtering dialog.
2166+
grid.openAdvancedFilteringDialog();
2167+
fix.detectChanges();
2168+
2169+
// Verify tree layout before the group change through context menu.
2170+
let rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
2171+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(2);
2172+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(2);
2173+
2174+
// Select two chips.
2175+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [0]);
2176+
GridFunctions.clickAdvancedFilteringTreeExpressionChip(fix, [1]);
2177+
tick(200);
2178+
2179+
// Click "Create Or Group" in context menu.
2180+
const buttons = GridFunctions.getAdvancedFilteringContextMenuButtons(fix);
2181+
buttons[2].click();
2182+
tick(100);
2183+
fix.detectChanges();
2184+
2185+
// Close dialog through API.
2186+
grid.closeAdvancedFilteringDialog(true);
2187+
tick(100);
2188+
fix.detectChanges();
2189+
2190+
// Open Advanced Filtering dialog.
2191+
grid.openAdvancedFilteringDialog();
2192+
fix.detectChanges();
2193+
2194+
// Verify tree layout after the group change through context menu.
2195+
rootGroup = GridFunctions.getAdvancedFilteringTreeRootGroup(fix);
2196+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, true).length).toBe(1);
2197+
expect(GridFunctions.getAdvancedFilteringTreeChildItems(rootGroup, false).length).toBe(3);
2198+
2199+
// Verify the filter changes are applied.
2200+
expect(grid.filteredData.length).toEqual(3);
2201+
}));
2202+
2203+
21472204
it('Should delete all selected conditions when the \'delete filters\' option from context menu is clicked.',
21482205
fakeAsync(() => {
21492206
// Apply advanced filter through API.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ export class IgxQueryBuilderComponent extends DisplayDensityBase implements Afte
11641164
parent.children.splice(index, 0, groupItem);
11651165

11661166
for (const expr of this.selectedExpressions) {
1167-
this.deleteItem(expr);
11681167
groupItem.children.push(expr);
1168+
this.deleteItem(expr);
11691169
expr.parent = groupItem;
11701170
}
11711171

0 commit comments

Comments
 (0)