Skip to content

Commit

Permalink
Depricated find and findIndex from IFilteringExpressionsTree, added F…
Browse files Browse the repository at this point in the history
…ilteringUtil (#14815)

* chore(query-builder): Depricated find and findIndex, added ExpressionsTreeUtil to public API
---------

Co-authored-by: Galina Edinakova <[email protected]>
Co-authored-by: Damyan Petev <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent 7774f3d commit 4fc69a9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes for each version of this project will be documented in this file.

## 18.2.0
### General
- `IFilteringExpressionsTree`, `FilteringExpressionsTree`
- **Deprecation** The `find` and `findIndex` methods have been deprecated and will be removed in a future version. A `ExpressionsTreeUtil` class has been added which provides the same functionality.
### New Features
- `IgxSimpleCombo`
- Introduced ability for Simple Combo to automatically select and retain valid input on "Tab" press enhancing user experience by streamlining data entry and reducing the need for manual selection improving form navigation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { IFilteringExpression } from './filtering-expression.interface';
import { IFilteringExpressionsTree } from './filtering-expressions-tree';

export class ExpressionsTreeUtil {
/**
* Returns the filtering expression for a column with the provided tree and fieldName.
* ```typescript
* let filteringExpression = ExpressionsTreeUtil.find(gridExpressionTree, 'Column Field');
* ```
*/
public static find(tree: IFilteringExpressionsTree, fieldName: string): IFilteringExpressionsTree | IFilteringExpression {
const index = this.findIndex(tree, fieldName);

if (index > -1) {
return tree.filteringOperands[index];
}

return null;
}

/**
* Returns the index of the filtering expression for a column with the provided tree and fieldName.
* ```typescript
* let filteringExpressionIndex = ExpressionsTreeUtil.findIndex(gridExpressionTree, 'Column Field');
* ```
*/
public static findIndex(tree: IFilteringExpressionsTree, fieldName: string): number {
for (let i = 0; i < tree.filteringOperands.length; i++) {
const expr = tree.filteringOperands[i];
if ((expr as IFilteringExpressionsTree).operator !== undefined) {
if (this.isFilteringExpressionsTreeForColumn(expr as IFilteringExpressionsTree, fieldName)) {
return i;
}
} else if ((expr as IFilteringExpression).fieldName === fieldName) {
return i;
}
}

return -1;
}

protected static isFilteringExpressionsTreeForColumn(expressionsTree: IFilteringExpressionsTree, fieldName: string): boolean {
if (expressionsTree.fieldName === fieldName) {
return true;
}

for (const expr of expressionsTree.filteringOperands) {
if ((expr as IFilteringExpressionsTree).operator !== undefined) {
return this.isFilteringExpressionsTreeForColumn(expr as IFilteringExpressionsTree, fieldName);
} else if ((expr as IFilteringExpression).fieldName === fieldName) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FilteringLogic, IFilteringExpression } from './filtering-expression.interface';
import { IBaseEventArgs } from '../core/utils';
import { ExpressionsTreeUtil } from './expressions-tree-util';

/* mustCoerceToInt */
export enum FilteringExpressionsTreeType {
Expand All @@ -19,7 +20,14 @@ export declare interface IFilteringExpressionsTree extends IBaseEventArgs, IExpr
/* alternateName: treeType */
type?: FilteringExpressionsTreeType;

/**
* @deprecated in version 18.2.0. Use `ExpressionsTreeUtil.find` instead.
*/
find(fieldName: string): IFilteringExpressionsTree | IFilteringExpression;

/**
* @deprecated in version 18.2.0. Use `ExpressionsTreeUtil.findIndex` instead.
*/
findIndex(fieldName: string): number;
}

Expand Down Expand Up @@ -111,15 +119,10 @@ export class FilteringExpressionsTree implements IFilteringExpressionsTree {
* ```
*
* @memberof FilteringExpressionsTree
* @deprecated in version 18.2.0. Use `ExpressionsTreeUtil.find` instead.
*/
public find(fieldName: string): IFilteringExpressionsTree | IFilteringExpression {
const index = this.findIndex(fieldName);

if (index > -1) {
return this.filteringOperands[index];
}

return null;
return ExpressionsTreeUtil.find(this, fieldName);
}

/**
Expand All @@ -129,37 +132,9 @@ export class FilteringExpressionsTree implements IFilteringExpressionsTree {
* ```
*
* @memberof FilteringExpressionsTree
* @deprecated in version 18.2.0. Use `ExpressionsTreeUtil.findIndex` instead.
*/
public findIndex(fieldName: string): number {
let expr;
for (let i = 0; i < this.filteringOperands.length; i++) {
expr = this.filteringOperands[i];
if (expr instanceof FilteringExpressionsTree) {
if (this.isFilteringExpressionsTreeForColumn(expr, fieldName)) {
return i;
}
} else {
if ((expr as IFilteringExpression).fieldName === fieldName) {
return i;
}
}
}

return -1;
}

protected isFilteringExpressionsTreeForColumn(expressionsTree: IFilteringExpressionsTree, fieldName: string): boolean {
if (expressionsTree.fieldName === fieldName) {
return true;
}

for (const expr of expressionsTree.filteringOperands) {
if ((expr instanceof FilteringExpressionsTree)) {
return this.isFilteringExpressionsTreeForColumn(expr, fieldName);
} else if ((expr as IFilteringExpression).fieldName === fieldName) {
return true;
}
}
return false;
return ExpressionsTreeUtil.findIndex(this, fieldName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { isConstructor, PlatformUtil } from '../../core/utils';
import { IgxGridCell } from '../grid-public-cell';
import { NG_VALIDATORS, Validator } from '@angular/forms';
import { Size } from '../common/enums';
import { ExpressionsTreeUtil } from '../../data-operations/expressions-tree-util';

const DEFAULT_DATE_FORMAT = 'mediumDate';
const DEFAULT_TIME_FORMAT = 'mediumTime';
Expand Down Expand Up @@ -1672,7 +1673,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
* @memberof IgxColumnComponent
*/
public get filteringExpressionsTree(): FilteringExpressionsTree {
return this.grid.filteringExpressionsTree.find(this.field) as FilteringExpressionsTree;
return ExpressionsTreeUtil.find(this.grid.filteringExpressionsTree, this.field) as FilteringExpressionsTree;
}

/* alternateName: parentColumn */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ColumnType, GridType } from '../common/grid.interface';
import { formatDate } from '../../core/utils';
import { ExcelStylePositionStrategy } from './excel-style/excel-style-position-strategy';
import { fadeIn } from 'igniteui-angular/animations';
import { ExpressionsTreeUtil } from '../../data-operations/expressions-tree-util';

/**
* @hidden
Expand Down Expand Up @@ -172,17 +173,17 @@ export class IgxFilteringService implements OnDestroy {
const filteringIgnoreCase = ignoreCase || (col ? col.filteringIgnoreCase : false);

const filteringTree = grid.filteringExpressionsTree;
const columnFilteringExpressionsTree = filteringTree.find(field) as IFilteringExpressionsTree;
const columnFilteringExpressionsTree = ExpressionsTreeUtil.find(filteringTree, field) as IFilteringExpressionsTree;
conditionOrExpressionTree = conditionOrExpressionTree ?? columnFilteringExpressionsTree;
const fieldFilterIndex = filteringTree.findIndex(field);
const fieldFilterIndex = ExpressionsTreeUtil.findIndex(filteringTree, field);

const newFilteringTree: FilteringExpressionsTree =
this.prepare_filtering_expression(filteringTree, field, value, conditionOrExpressionTree,
filteringIgnoreCase, fieldFilterIndex, true);

const eventArgs: IFilteringEventArgs = {
owner: grid,
filteringExpressions: newFilteringTree.find(field) as FilteringExpressionsTree, cancel: false
filteringExpressions: ExpressionsTreeUtil.find(newFilteringTree, field) as FilteringExpressionsTree, cancel: false
};
this.grid.filtering.emit(eventArgs);

Expand All @@ -193,7 +194,7 @@ export class IgxFilteringService implements OnDestroy {
if (conditionOrExpressionTree) {
this.filter_internal(field, value, conditionOrExpressionTree, filteringIgnoreCase);
} else {
const expressionsTreeForColumn = this.grid.filteringExpressionsTree.find(field);
const expressionsTreeForColumn = ExpressionsTreeUtil.find(this.grid.filteringExpressionsTree, field);
if (!expressionsTreeForColumn) {
throw new Error('Invalid condition or Expression Tree!');
} else if (expressionsTreeForColumn instanceof FilteringExpressionsTree) {
Expand All @@ -203,7 +204,7 @@ export class IgxFilteringService implements OnDestroy {
this.filter_internal(field, value, expressionForColumn.condition, filteringIgnoreCase);
}
}
const doneEventArgs = this.grid.filteringExpressionsTree.find(field) as FilteringExpressionsTree;
const doneEventArgs = ExpressionsTreeUtil.find(this.grid.filteringExpressionsTree, field) as FilteringExpressionsTree;
// Wait for the change detection to update filtered data through the pipes and then emit the event.
requestAnimationFrame(() => this.grid.filteringDone.emit(doneEventArgs));
}
Expand Down Expand Up @@ -273,7 +274,7 @@ export class IgxFilteringService implements OnDestroy {
const grid = this.grid;
grid.crudService.endEdit(false);
const filteringState = grid.filteringExpressionsTree;
const index = filteringState.findIndex(fieldName);
const index = ExpressionsTreeUtil.findIndex(filteringState, fieldName);

if (index > -1) {
filteringState.filteringOperands.splice(index, 1);
Expand Down Expand Up @@ -512,7 +513,7 @@ export class IgxFilteringService implements OnDestroy {
this.grid.crudService.endEdit(false);
this.grid.page = 0;

const fieldFilterIndex = filteringTree.findIndex(fieldName);
const fieldFilterIndex = ExpressionsTreeUtil.findIndex(filteringTree, fieldName);
this.prepare_filtering_expression(filteringTree, fieldName, term, conditionOrExpressionsTree, ignoreCase, fieldFilterIndex);
this.grid.filteringExpressionsTree = filteringTree;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SortingDirection } from '../../data-operations/sorting-strategy';
import { SortingIndexPipe } from './pipes';
import { NgTemplateOutlet, NgIf, NgClass } from '@angular/common';
import { IgxIconComponent } from '../../icon/icon.component';
import { ExpressionsTreeUtil } from '../../data-operations/expressions-tree-util';

/**
* @hidden
Expand Down Expand Up @@ -280,7 +281,7 @@ export class IgxGridHeaderComponent implements DoCheck, OnDestroy {
if(!this.grid.advancedFilteringExpressionsTree) {
return false;
}
return !!this.grid.advancedFilteringExpressionsTree.find(this.column.field);
return !!ExpressionsTreeUtil.find(this.grid.advancedFilteringExpressionsTree, this.column.field);
}

private triggerSort() {
Expand Down
1 change: 1 addition & 0 deletions projects/igniteui-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export * from './lib/data-operations/filtering-expressions-tree';
export * from './lib/data-operations/filtering-condition';
export * from './lib/data-operations/filtering-state.interface';
export * from './lib/data-operations/filtering-strategy';
export * from './lib/data-operations/expressions-tree-util';
export * from './lib/data-operations/groupby-expand-state.interface';
export * from './lib/data-operations/groupby-record.interface';
export * from './lib/data-operations/groupby-state.interface';
Expand Down

0 comments on commit 4fc69a9

Please sign in to comment.