Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filtering): fix empty expr error #11152

Merged
merged 6 commits into from
Mar 4, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,6 @@ export class IgxFilteringService implements OnDestroy {
}

const fieldFilterIndex = filteringTree.findIndex(fieldName);
if (fieldFilterIndex > -1) {
filteringTree.filteringOperands.splice(fieldFilterIndex, 1);
}
this.prepare_filtering_expression(filteringTree, fieldName, term, conditionOrExpressionsTree, ignoreCase, fieldFilterIndex);
grid.filteringExpressionsTree = filteringTree;
}
Expand All @@ -537,27 +534,30 @@ export class IgxFilteringService implements OnDestroy {
insertAtIndex = -1,
createNewTree = false): FilteringExpressionsTree {

const expressionsTree = conditionOrExpressionsTree instanceof FilteringExpressionsTree ?
let expressionsTree = conditionOrExpressionsTree instanceof FilteringExpressionsTree ?
conditionOrExpressionsTree as IFilteringExpressionsTree : null;
const condition = conditionOrExpressionsTree instanceof FilteringExpressionsTree ?
null : conditionOrExpressionsTree as IFilteringOperation;
const newExpression: IFilteringExpression = { fieldName, searchVal, condition, ignoreCase };

const newExpressionsTree: FilteringExpressionsTree = createNewTree ?
new FilteringExpressionsTree(filteringState.operator, filteringState.fieldName) : filteringState as FilteringExpressionsTree;
let newExpressionsTree = filteringState as FilteringExpressionsTree;

if (createNewTree) {
newExpressionsTree = new FilteringExpressionsTree(filteringState.operator, filteringState.fieldName);
newExpressionsTree.filteringOperands = [...filteringState.filteringOperands];
}

if (condition) {
const newExpression: IFilteringExpression = { fieldName, searchVal, condition, ignoreCase };
expressionsTree = new FilteringExpressionsTree(filteringState.operator, fieldName);
expressionsTree.filteringOperands.push(newExpression);
}

// no expressions tree found for this field
if (expressionsTree) {
if (insertAtIndex > -1) {
newExpressionsTree.filteringOperands[insertAtIndex] = expressionsTree;
} else {
newExpressionsTree.filteringOperands.push(expressionsTree);
}
} else if (condition) {
// create expressions tree for this field and add the new expression to it
const newExprTree: FilteringExpressionsTree = new FilteringExpressionsTree(filteringState.operator, fieldName);
newExprTree.filteringOperands.push(newExpression);
newExpressionsTree.filteringOperands.push(newExprTree);
}

return newExpressionsTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3772,7 +3772,7 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
fix.detectChanges();
}));

it('display dansity is properly applied on the column selection container', fakeAsync(() => {
it('display density is properly applied on the column selection container', fakeAsync(() => {
grid.columnSelection = GridSelectionMode.multiple;
fix.detectChanges();

Expand Down Expand Up @@ -4375,6 +4375,94 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
[true, true, true]);
}));

it('Should correctly modify existing filters.', fakeAsync(() => {
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '(Blanks)', 'Ignite UI for Angular', 'Ignite UI for JavaScript',
'NetAdvantage', 'Some other item with Script'],
[true, true, true, true, true, true]);
toggleExcelStyleFilteringItems(fix, true, 1, 5);
expect(grid.rowList.length).toBe(3);

GridFunctions.clickExcelFilterIcon(fix, 'Downloads');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '20', '127', '254'],
[true, true, true, true]);
toggleExcelStyleFilteringItems(fix, true, 2);
expect(grid.rowList.length).toBe(2);

GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', 'Ignite UI for Angular', 'Ignite UI for JavaScript'],
[true, true, true]);

GridFunctions.clickExcelFilterIcon(fix, 'Downloads');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '20', '127', '254'],
[null, true, false, true]);
toggleExcelStyleFilteringItems(fix, true, 1, 2, 3);
expect(grid.rowList.length).toBe(1);

GridFunctions.clickExcelFilterIcon(fix, 'Downloads');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '20', '127', '254'],
[null, false, true, false]);
}));

it('Should correctly modify the first one of the existing filters.', fakeAsync(() => {
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '(Blanks)', 'Ignite UI for Angular', 'Ignite UI for JavaScript',
'NetAdvantage', 'Some other item with Script'],
[true, true, true, true, true, true]);
toggleExcelStyleFilteringItems(fix, true, 1, 5);
expect(grid.rowList.length).toBe(3);

GridFunctions.clickExcelFilterIcon(fix, 'Downloads');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '20', '127', '254'],
[true, true, true, true]);
toggleExcelStyleFilteringItems(fix, true, 2);
expect(grid.rowList.length).toBe(2);

GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', 'Ignite UI for Angular', 'Ignite UI for JavaScript'],
[true, true, true]);
toggleExcelStyleFilteringItems(fix, true, 1);
expect(grid.rowList.length).toBe(1);

GridFunctions.clickExcelFilterIcon(fix, 'Downloads');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', '254'],
[true, true]);

GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
tick(100);
fix.detectChanges();
verifyExcelStyleFilterAvailableOptions(fix,
['Select All', 'Ignite UI for Angular', 'Ignite UI for JavaScript'],
[null, false, true]);
}));

it('Should display the ESF based on the filterIcon within the grid', async () => {
// Test prerequisites
grid.width = '800px';
Expand Down Expand Up @@ -6585,8 +6673,6 @@ const verifyExcelStyleFilterAvailableOptions = (fix, labels: string[], checked:
const checkboxElements: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu));

expect(labelElements.length).toBe(labels.length, 'incorrect rendered list items count');
expect(labelElements.length).toBeGreaterThan(2);
expect(checkboxElements.length).toBeGreaterThan(2);
labels.forEach((l, index) => {
expect(l).toEqual(labelElements[index].innerText);
});
Expand Down