Skip to content

Commit 2f80517

Browse files
authored
refactor(columns): deprecate children and replace with childColumns (#14489)
1 parent 83af0f1 commit 2f80517

File tree

8 files changed

+103
-17
lines changed

8 files changed

+103
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ All notable changes for each version of this project will be documented in this
1010
- Keyboard navigation now can move in to row headers back and forth from any row dimension headers or column headers.
1111
- Added keyboard interactions for row dimension collapse using `Alt + Arrows` and row headers sorting using `Ctrl + Arrow Up/Down`.
1212

13+
### General
14+
- `ColumnType`, `IgxColumn`, `IgxColumnGroup`, `IgxColumnLayout`
15+
- The `children` query property has been deprecated and replaced by `childColumns` getter directly returning columns array.
16+
17+
1318
## 18.0.0
1419
### New Features
1520
- `IgxCombo`, `IgxSimpleCombo`:
@@ -173,7 +178,7 @@ All notable changes for each version of this project will be documented in this
173178
- `IgxCombo`,`IgxSimpleCombo`
174179
- **Breaking Change** The `displayValue` property now returns the display text as expected (instead of display values in array).
175180

176-
=======
181+
177182
## 16.1.5
178183
### General
179184
- `IgxButtonGroup`:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "../../common/schema/members-changes.schema.json",
3+
"changes": [
4+
{
5+
"member": "children.toArray()",
6+
"replaceWith": "childColumns",
7+
"definedIn": [
8+
"ColumnType",
9+
"IgxColumnComponent",
10+
"IgxColumnGroupComponent",
11+
"IgxColumnLayoutComponent"
12+
]
13+
}
14+
]
15+
}

projects/igniteui-angular/migrations/update-18_1_0/index.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,46 @@ describe(`Update to ${version}`, () => {
120120
);
121121
});
122122

123+
it('Should replace deprecated `children` property of Columns', async () => {
124+
pending('set up tests for migrations through lang service');
125+
appTree.create(
126+
'/testSrc/appPrefix/component/expansion-test.component.ts',
127+
`import { Component } from '@angular/core';
128+
import { IgxColumnGroupComponent, ColumnType } from 'igniteui-angular';
129+
130+
@Component({
131+
selector: 'app-columns-test',
132+
templateUrl: './columns-test.component.html',
133+
styleUrls: ['./columns-test.component.scss']
134+
})
135+
export class ColumnsTestComponent {
136+
public toggleColumnGroup(columnGroup: IgxColumnGroupComponent) {
137+
const columns = columnGroup.children.toArray();
138+
}
139+
public toggleColumnGroup2(columnGroup: ColumnType) {
140+
const columns = columnGroup.children.toArray();
141+
}
142+
}`
143+
);
144+
const tree = await schematicRunner.runSchematic(migrationName, { shouldInvokeLS: false }, appTree);
145+
const expectedContent = `import { Component } from '@angular/core';
146+
import { IgxColumnGroupComponent } from 'igniteui-angular';
147+
148+
@Component({
149+
selector: 'app-columns-test',
150+
templateUrl: './columns-test.component.html',
151+
styleUrls: ['./columns-test.component.scss']
152+
})
153+
export class ColumnsTestComponent {
154+
public toggleColumnGroup(columnGroup: IgxColumnGroupComponent) {
155+
const columns = columnGroup.childColumns;
156+
}
157+
public toggleColumnGroup2(columnGroup: ColumnType) {
158+
const columns = columnGroup.childColumns;
159+
}
160+
}`;
161+
expect(
162+
tree.readContent('/testSrc/appPrefix/component/expansion-test.component.ts')
163+
).toEqual(expectedContent);
164+
});
123165
});

projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { takeUntil } from 'rxjs/operators';
1313

1414
import { IgxColumnComponent } from './column.component';
1515
import { flatten } from '../../core/utils';
16-
import { CellType, IgxColumnTemplateContext } from '../common/grid.interface';
16+
import { CellType, ColumnType, IgxColumnTemplateContext } from '../common/grid.interface';
1717

1818

1919
@Component({
@@ -25,7 +25,10 @@ import { CellType, IgxColumnTemplateContext } from '../common/grid.interface';
2525
})
2626
export class IgxColumnGroupComponent extends IgxColumnComponent implements AfterContentInit {
2727

28-
@ContentChildren(IgxColumnComponent, { read: IgxColumnComponent })
28+
/**
29+
* @deprecated in version 18.1.0. Use the `childColumns` property instead.
30+
*/
31+
@ContentChildren(IgxColumnComponent, { read: IgxColumnComponent, })
2932
public override children = new QueryList<IgxColumnComponent>();
3033

3134
/**
@@ -311,6 +314,14 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
311314

312315
}
313316

317+
/**
318+
* A list containing all the child columns under this column (if any).
319+
* Empty without children or if this column is not Group or Layout.
320+
*/
321+
public override get childColumns(): ColumnType[] {
322+
return this.children.toArray();
323+
}
324+
314325
/** @hidden @internal **/
315326
public override get allChildren(): IgxColumnComponent[] {
316327
return flatten(this.children.toArray());

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,14 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
14591459
return this.parent && this.parent.columnLayout;
14601460
}
14611461

1462+
/**
1463+
* A list containing all the child columns under this column (if any).
1464+
* Empty without children or if this column is not Group or Layout.
1465+
*/
1466+
public get childColumns(): ColumnType[] {
1467+
return [];
1468+
}
1469+
14621470
/** @hidden @internal **/
14631471
public get allChildren(): IgxColumnComponent[] {
14641472
return [];
@@ -1638,11 +1646,8 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
16381646
* ```typescript
16391647
* let columnChildren = this.column.children;
16401648
* ```
1641-
* ```typescript
1642-
* this.column.children = childrenColumns;
1643-
* ```
16441649
*
1645-
* @memberof IgxColumnComponent
1650+
* @deprecated in version 18.1.0. Use the `childColumns` property instead.
16461651
*/
16471652
public children: QueryList<IgxColumnComponent>;
16481653
/**

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,17 @@ export interface FieldType {
299299
export interface ColumnType extends FieldType {
300300
/** Represents the instance of the parent `GridType` that contains this column. */
301301
grid: GridType;
302-
/** A list, containing all the child columns under this column (if any). */
302+
/**
303+
* A list containing all the child columns under this column (if any).
304+
* @deprecated in version 18.1.0. Use the `childColumns` property instead.
305+
*/
303306
children: QueryList<ColumnType>;
304-
/** An array, containing all the child columns, including nested children. */
307+
/**
308+
* A list containing all the child columns under this column (if any).
309+
* Empty without children or if this column is not Group or Layout.
310+
*/
311+
get childColumns(): ColumnType[];
312+
/** @hidden @internal */
305313
allChildren: ColumnType[];
306314
/**
307315
* The header group component associated with this column.

projects/igniteui-angular/src/lib/grids/grid/column-group.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,12 @@ describe('IgxGrid - multi-column headers #grid', () => {
765765
it('column hiding - child level', () => {
766766
const addressGroup = fixture.componentInstance.addrInfoColGroup;
767767

768-
addressGroup.children.first.hidden = true;
768+
addressGroup.childColumns[0].hidden = true;
769769
fixture.detectChanges();
770770

771771
expect(GridFunctions.getColumnGroupHeaders(fixture).length).toEqual(5);
772-
expect(addressGroup.children.first.hidden).toBe(true);
773-
expect(addressGroup.children.first.children.toArray().every(c => c.hidden === true)).toEqual(true);
772+
expect(addressGroup.childColumns[0].hidden).toBe(true);
773+
expect(addressGroup.childColumns[0].childColumns.every(c => c.hidden === true)).toEqual(true);
774774
});
775775

776776
it('column hiding - Verify column hiding of Individual column and Child column', () => {
@@ -935,17 +935,17 @@ describe('IgxGrid - multi-column headers #grid', () => {
935935
expect(grid.columnList.filter(col => col.columnGroup).length).toEqual(7);
936936

937937
// Get children of grouped column
938-
expect(getColGroup(grid, 'General Information').children.length).toEqual(2);
938+
expect(getColGroup(grid, 'General Information').childColumns.length).toEqual(2);
939939

940940
// Get children of hidden group
941-
expect(getColGroup(grid, 'Person Details').children.length).toEqual(2);
941+
expect(getColGroup(grid, 'Person Details').childColumns.length).toEqual(2);
942942

943943
// Get children of group with one column
944-
const postCodeGroupedColumnAllChildren = getColGroup(grid, 'Postal Code').children;
944+
const postCodeGroupedColumnAllChildren = getColGroup(grid, 'Postal Code').childColumns;
945945
expect(postCodeGroupedColumnAllChildren.length).toEqual(1);
946946

947947
// Get children of group with more levels
948-
const addressGroupedColumnAllChildren = getColGroup(grid, 'Address Information').children;
948+
const addressGroupedColumnAllChildren = getColGroup(grid, 'Address Information').childColumns;
949949
expect(addressGroupedColumnAllChildren.length).toEqual(3);
950950
});
951951

src/app/grid-column-groups/grid-column-groups.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class GridColumnGroupsSampleComponent {
9696
}
9797

9898
public toggleColumnGroup(columnGroup: IgxColumnGroupComponent) {
99-
const columns = columnGroup.children.toArray();
99+
const columns = columnGroup.childColumns;
100100

101101
if (columnGroup.header === 'General Information') {
102102
const col = columns[1];

0 commit comments

Comments
 (0)