-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depricated find and findIndex from IFilteringExpressionsTree, added F…
…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
1 parent
7774f3d
commit 4fc69a9
Showing
7 changed files
with
84 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
projects/igniteui-angular/src/lib/data-operations/expressions-tree-util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters