-
Notifications
You must be signed in to change notification settings - Fork 160
fix(query-builder): refactor expression tree change emission for consistency - master #17081
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
Changes from 7 commits
9bbaf62
51b5477
e18183c
58b16b7
6602fbf
ebbca6e
a2a5ff4
f487487
091d56b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,14 +327,35 @@ export class IgxQueryBuilderComponent implements OnDestroy { | |
| this.queryTree.setAddButtonFocus(); | ||
| } | ||
|
|
||
| private serializeExpressionTreeCallback(key: string, val: unknown): unknown { | ||
| if (key === 'externalObject') { | ||
| return undefined; | ||
| } | ||
| if (key === 'searchVal' && val instanceof Set) { | ||
| // Ensure Set-based search values (e.g. for "in" conditions) are serialized correctly | ||
| // JSON.stringify(new Set([...])) => '{}' by default, so convert to an array first | ||
| return Array.from(val); | ||
| } | ||
|
|
||
|
IMinchev64 marked this conversation as resolved.
|
||
| return val; | ||
| } | ||
|
|
||
| private getSerializableExpressionTree(tree: IExpressionTree): IExpressionTree { | ||
| if (!tree) { | ||
| return tree; | ||
| } | ||
|
|
||
| return JSON.parse(JSON.stringify(tree, this.serializeExpressionTreeCallback)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is introducing a behavior change. Let's say that any of the filtering operands is having custom logic as condition. The condition contains
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not tested this but what would happen if there are dates as |
||
| } | ||
|
|
||
| protected onExpressionTreeChange(tree: IExpressionTree) { | ||
| if (tree && this.entities && tree !== this._expressionTree) { | ||
| this._expressionTree = recreateTree(tree, this.entities); | ||
| } else { | ||
| this._expressionTree = tree; | ||
| } | ||
| if (this._shouldEmitTreeChange) { | ||
| this.expressionTreeChange.emit(tree); | ||
| this.expressionTreeChange.emit(this.getSerializableExpressionTree(this._expressionTree)); | ||
| } | ||
|
IMinchev64 marked this conversation as resolved.
|
||
| } | ||
|
|
||
|
|
@@ -389,4 +410,3 @@ export class IgxQueryBuilderComponent implements OnDestroy { | |
| }); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -191,7 +191,15 @@ export class QueryBuilderComponent implements OnInit { | |||||||||||||||||||||||||
| // this.expressionTree = tree; | ||||||||||||||||||||||||||
| // this.onChange(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return tree ? JSON.stringify(tree, null, 2) : 'Please add an expression!'; | ||||||||||||||||||||||||||
| return tree ? JSON.stringify(tree, this.serializeExpressionTreeCallback, 2) : 'Please add an expression!'; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // JSON.stringify serializes Set as {}, so convert Set-based searchVal to array to preserve values in the printed output. | ||||||||||||||||||||||||||
| private serializeExpressionTreeCallback(key: string, val: any) { | ||||||||||||||||||||||||||
| if (key === 'searchVal' && val instanceof Set) { | ||||||||||||||||||||||||||
| return Array.from(val); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return val; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+198
to
203
|
||||||||||||||||||||||||||
| private serializeExpressionTreeCallback(key: string, val: any) { | |
| if (key === 'searchVal' && val instanceof Set) { | |
| return Array.from(val); | |
| } | |
| return val; | |
| } | |
| private readonly serializeExpressionTreeCallback = (key: string, val: unknown) => { | |
| if (key === 'searchVal' && val instanceof Set) { | |
| return Array.from(val); | |
| } | |
| return val; | |
| }; |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this going into a separate method?