Skip to content

Commit 04e5711

Browse files
committed
feat(h-grid): revert creating fields for each child entity
1 parent 9e6e421 commit 04e5711

File tree

7 files changed

+21
-58
lines changed

7 files changed

+21
-58
lines changed

projects/igniteui-angular/src/lib/data-operations/filtering-condition.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ export class IgxFilteringOperand {
5151
return this.operations.filter(f => !f.hidden && !f.isNestedQuery).map((element) => element.name);
5252
}
5353

54-
/**
55-
* Returns "In" and "Not In" conditions
56-
*/
57-
public nestedConditionList(): string[] {
58-
return this.operations.filter(f => !f.hidden && f.isNestedQuery).map((element) => element.name);
59-
}
60-
6154
/**
6255
* Returns an array of names of the conditions which are visible in the UI, including "In" and "Not In", allowing the creation of sub-queries.
6356
* @hidden @internal

projects/igniteui-angular/src/lib/query-builder/query-builder-tree.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</ng-template>
88

99
<ng-template #selectFromTemplate>
10-
<div class="igx-filter-tree__inputs" [style.display]="(isInEditMode() && (!this.isAdvancedFiltering() && !this.isHierarchicalGridNestedQuery())) ? 'flex' : 'none'">
10+
<div class="igx-filter-tree__inputs" [style.display]="(isInEditMode() && (!this.isAdvancedFiltering() || this.isHierarchicalGridNestedQuery())) ? 'flex' : 'none'">
1111
<div class="igx-filter-tree__inputs-field">
1212
<span class="igx-query-builder__label">From</span>
1313
<igx-select #entitySelect
@@ -466,7 +466,7 @@
466466
<ng-container>
467467
<igx-query-builder-tree
468468
[style.display]="expressionItem.inEditMode || expressionItem.expanded ? 'block' : 'none'"
469-
[entities]="determineEntities()"
469+
[entities]="(this.selectedEntity ? this.selectedEntity.childEntities : entities[0].childEntities) ?? entities"
470470
[queryBuilder]="this.queryBuilder"
471471
[parentExpression]="expressionItem"
472472
[expressionTree]="expressionItem.inEditMode ? (innerQueryNewExpressionTree ?? getExpressionTreeCopy(expressionItem.expression.searchTree, true)) : expressionItem.expression.searchTree"

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
556556
this.addExpressionDropDownOverlaySettings.outlet = this.overlayOutlet;
557557
this.groupContextMenuDropDownOverlaySettings.outlet = this.overlayOutlet;
558558

559-
console.log('ngAfterViewInit', this._expressionTree);
560559
if (this.isAdvancedFiltering() && this.entities?.length === 1) {
561560
this._selectedEntity = this.entities[0];
562561
}
@@ -577,7 +576,6 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
577576
* @hidden @internal
578577
*/
579578
public set selectedEntity(value: string) {
580-
console.log('selectedEntity', value);
581579
this._selectedEntity = this.entities?.find(el => el.name === value);
582580
}
583581

@@ -1379,12 +1377,9 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
13791377
this.selectedField.filters = this.getFilters(this.selectedField);
13801378
}
13811379

1382-
if (this.isAdvancedFiltering()) {
1383-
if (!this.selectedField.dataType) { // field was generated for child entity
1384-
return this.selectedField.filters.nestedConditionList();
1385-
} else {
1386-
return this.selectedField.filters.conditionList();
1387-
}
1380+
if ((this.isAdvancedFiltering() && !this.entities[0].childEntities) ||
1381+
(this.isHierarchicalGridNestedQuery() && this.selectedEntity.name && !this.selectedEntity.childEntities)) {
1382+
return this.selectedField.filters.conditionList();
13881383
}
13891384

13901385
return this.selectedField.filters.extendedConditionList();
@@ -1450,16 +1445,6 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14501445
}
14511446
}
14521447

1453-
public determineEntities(): EntityType[] {
1454-
// TODO: FIX, not working correctly for every scenario
1455-
1456-
if (this.entities.length === 1 && this.entities[0].childEntities && this.selectedField) {
1457-
return this.entities[0].childEntities.filter(e => e.name === this.selectedField.field);
1458-
}
1459-
1460-
return (this.selectedEntity ? this.selectedEntity.childEntities : this.entities[0].childEntities) ?? this.entities;
1461-
}
1462-
14631448
public getExpressionTreeCopy(expressionTree: IExpressionTree, shouldAssignInnerQueryExprTree?: boolean): IExpressionTree {
14641449
if (!expressionTree) {
14651450
return null;
@@ -1536,12 +1521,8 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
15361521
}
15371522

15381523
private selectDefaultCondition() {
1539-
if (this.selectedField) {
1540-
if (!this.selectedField.dataType) {
1541-
this.selectedCondition = 'inQuery';
1542-
} else {
1543-
this.selectedCondition = this.selectedField.filters.conditionList().indexOf('equals') >= 0 ? 'equals' : this.selectedField.filters.conditionList()[0];
1544-
}
1524+
if (this.selectedField && this.selectedField.filters) {
1525+
this.selectedCondition = this.selectedField.filters.conditionList().indexOf('equals') >= 0 ? 'equals' : this.selectedField.filters.conditionList()[0];
15451526
}
15461527
}
15471528

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ export class IgxQueryBuilderComponent implements OnDestroy {
6464
*/
6565
@Input()
6666
public set entities(entities: EntityType[]) {
67-
if (entities) {
68-
this.updateEntities(entities) // add field for every child entity recursively
69-
}
70-
7167
if (entities !== this._entities) {
7268
if (entities && this.expressionTree) {
7369
this._expressionTree = recreateTree(this._expressionTree, entities);
@@ -274,20 +270,6 @@ export class IgxQueryBuilderComponent implements OnDestroy {
274270
}
275271
}
276272

277-
private updateEntities(entities: EntityType[]) {
278-
entities.forEach((entity) => {
279-
if (entity.childEntities) {
280-
entity.childEntities.forEach((childEntity) => {
281-
if (entity.fields.find((f) => f.field === childEntity.name)) {
282-
return;
283-
}
284-
entity.fields.push({ field: childEntity.name, dataType: null });
285-
});
286-
this.updateEntities(entity.childEntities);
287-
}
288-
});
289-
}
290-
291273
private registerSVGIcons(): void {
292274
const editorIcons = editor as any[];
293275

src/app/hierarchical-grid-advanced-filtering/hierarchical-grid-advanced-filtering.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class HierarchicalGridAdvancedFilteringSampleComponent implements AfterVi
3636
});
3737
const tree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Artists', ['*']);
3838
tree.filteringOperands.push({
39-
fieldName: 'Albums',
39+
fieldName: 'Artist',
4040
condition: IgxStringFilteringOperand.instance().condition('inQuery'),
4141
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
4242
searchTree: innerTree

src/app/hierarchical-grid-remote/hierarchical-grid-remote.sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<igx-column field="orderId"></igx-column>
2323
<igx-column field="customerId"></igx-column>
2424
<igx-column field="shipVia"></igx-column>
25+
<igx-column field="freight"></igx-column>
2526
<igx-row-island #rowIsland2 [key]="'Details'" [primaryKey]="'orderId'" [autoGenerate]="false" (gridCreated)="gridCreated($event, rowIsland2)">
2627
<igx-grid-toolbar *igxGridToolbar>
2728
<igx-grid-toolbar-title>Order Details</igx-grid-toolbar-title>

src/app/hierarchical-grid-remote/hierarchical-grid-remote.sample.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
IGX_HIERARCHICAL_GRID_DIRECTIVES,
77
FilteringExpressionsTree,
88
IgxStringFilteringOperand,
9-
EntityType
9+
EntityType,
10+
IgxNumberFilteringOperand
1011
} from 'igniteui-angular';
1112
import { HttpClient } from '@angular/common/http';
1213

@@ -45,7 +46,8 @@ export class HierarchicalGridRemoteSampleComponent implements OnInit, AfterViewI
4546
{ field: 'customerId', dataType: 'string' }, // first field will be treated as foreign key
4647
{ field: 'orderId', dataType: 'number' },
4748
{ field: 'employeeId', dataType: 'number' },
48-
{ field: 'shipVia', dataType: 'string' }
49+
{ field: 'shipVia', dataType: 'string' },
50+
{ field: 'freight', dataType: 'number' }
4951
],
5052
childEntities: [
5153
{
@@ -69,16 +71,18 @@ export class HierarchicalGridRemoteSampleComponent implements OnInit, AfterViewI
6971
public ngOnInit() {
7072
const ordersTree = new FilteringExpressionsTree(0, undefined, 'Orders', ['customerId']);
7173
ordersTree.filteringOperands.push({
72-
fieldName: 'shipVia',
74+
fieldName: 'freight',
7375
ignoreCase: false,
74-
conditionName: IgxStringFilteringOperand.instance().condition('equals').name,
75-
searchVal: 'AirCargo'
76+
condition: IgxNumberFilteringOperand.instance().condition('greaterThanOrEqualTo'),
77+
conditionName: IgxNumberFilteringOperand.instance().condition('greaterThanOrEqualTo').name,
78+
searchVal: '500'
7679
});
7780

7881
const customersTree = new FilteringExpressionsTree(0, undefined, 'Customers', ['customerId', 'companyName', 'contactName', 'contactTitle']);
7982
customersTree.filteringOperands.push({
8083
fieldName: 'customerId',
81-
conditionName: IgxStringFilteringOperand.instance().condition('notInQuery').name,
84+
condition: IgxStringFilteringOperand.instance().condition('inQuery'),
85+
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
8286
ignoreCase: false,
8387
searchTree: ordersTree
8488
});
@@ -101,6 +105,8 @@ export class HierarchicalGridRemoteSampleComponent implements OnInit, AfterViewI
101105
tree = new FilteringExpressionsTree(0, undefined, this.remoteEntities[0].name, this.remoteEntities[0].fields.map(f => f.field));
102106
}
103107

108+
console.log(tree);
109+
104110
this.hGrid.isLoading = true;
105111
this.http.post(`${API_ENDPOINT}/QueryBuilder/ExecuteQuery`, tree).subscribe(data =>{
106112
console.log('data', data);

0 commit comments

Comments
 (0)