Skip to content

Commit 80f61cd

Browse files
committed
refactor(grid): add migrations, upd readme and deprecation warn
1 parent 745a26f commit 80f61cd

File tree

6 files changed

+114
-3
lines changed

6 files changed

+114
-3
lines changed

projects/igniteui-angular/migrations/migration-collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
"version": "13.0.0-alpha",
111111
"description": "Updates Ignite UI for Angular from v12.2.x to v13.0.0",
112112
"factory": "./update-13_0_0"
113+
},
114+
"migration-23": {
115+
"version": "13.1.0",
116+
"description": "Updates Ignite UI for Angular from v13.0.x to v13.1.0",
117+
"factory": "./update-13_1_0"
113118
}
114119
}
115120
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as path from 'path';
2+
3+
import { EmptyTree } from '@angular-devkit/schematics';
4+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
5+
6+
const version = '13.1.0';
7+
8+
describe(`Update to ${version}`, () => {
9+
let appTree: UnitTestTree;
10+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
11+
const configJson = {
12+
defaultProject: 'testProj',
13+
projects: {
14+
testProj: {
15+
sourceRoot: '/testSrc'
16+
}
17+
},
18+
schematics: {
19+
'@schematics/angular:component': {
20+
prefix: 'appPrefix'
21+
}
22+
}
23+
};
24+
25+
beforeEach(() => {
26+
appTree = new UnitTestTree(new EmptyTree());
27+
appTree.create('/angular.json', JSON.stringify(configJson));
28+
});
29+
30+
const migrationName = 'migration-23';
31+
const lineBreaksAndSpaceRegex = /\s/g;
32+
33+
34+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Element } from '@angular/compiler';
2+
import {
3+
Rule,
4+
SchematicContext,
5+
Tree
6+
} from '@angular-devkit/schematics';
7+
import { UpdateChanges } from '../common/UpdateChanges';
8+
import { nativeImport } from '../common/import-helper.js';
9+
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
10+
11+
const version = '13.1.0';
12+
13+
export default (): Rule => async (host: Tree, context: SchematicContext) => {
14+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
15+
const { HtmlParser } = await nativeImport('@angular/compiler') as typeof import('@angular/compiler');
16+
17+
const update = new UpdateChanges(__dirname, host, context);
18+
const GRID_TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid', 'igx-row-island'];
19+
const prop = ['[movable]'];
20+
const changes = new Map<string, FileChange[]>();
21+
22+
const gridsToMigrate = new Set<any>();
23+
24+
const applyChanges = () => {
25+
for (const [path, change] of changes.entries()) {
26+
let buffer = host.read(path).toString();
27+
28+
change.sort((c, c1) => c.position - c1.position)
29+
.reverse()
30+
.forEach(c => buffer = c.apply(buffer));
31+
32+
host.overwrite(path, buffer);
33+
}
34+
};
35+
36+
const addChange = (path: string, change: FileChange) => {
37+
if (changes.has(path)) {
38+
changes.get(path).push(change);
39+
} else {
40+
changes.set(path, [change]);
41+
}
42+
};
43+
44+
// migrate movable on column-level to moving on grid-level for grid, tree grid, hierarchical grid and row island
45+
for (const path of update.templateFiles) {
46+
const grids = findElementNodes(parseFile(new HtmlParser(), host, path), GRID_TAGS);
47+
grids.forEach(grid => {
48+
const grid_elem = grid as Element;
49+
const columns = grid_elem.children.filter(column => (column as Element).name === 'igx-column' && hasAttribute(column as Element, prop));
50+
columns.map(node => getSourceOffset(node as Element))
51+
.forEach(offset => {
52+
const { startTag, file, node } = offset;
53+
const { name, value } = getAttribute(node, prop)[0];
54+
if (value === 'true') {
55+
gridsToMigrate.add(grid_elem);
56+
}
57+
const repTxt = file.content.substring(startTag.start, startTag.end);
58+
const property = `${name}="${value}"`;
59+
const removePropTxt = repTxt.replace(property, '');
60+
addChange(file.url, new FileChange(startTag.start, removePropTxt, repTxt, 'replace'));
61+
});
62+
});
63+
64+
Array.from(gridsToMigrate).map(node => getSourceOffset(node as Element)).forEach(offset => {
65+
const { startTag, file } = offset;
66+
addChange(file.url, new FileChange(startTag.end - 1, ' [moving]="true"'));
67+
});
68+
}
69+
70+
applyChanges();
71+
changes.clear();
72+
};

projects/igniteui-angular/src/lib/grids/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Below is the list of all inputs that the developers may set to configure the gri
167167
|`resourceStrings`| IGridResourceStrings | Resource strings of the grid. |
168168
|`autoGenerate`|boolean|Autogenerate grid's columns, default value is _false_|
169169
|`batchEditing`|boolean|Toggles batch editing in the grid, default is _false_|
170+
|`moving`|boolean|Enables the columns moving feature. Defaults to _false_|
170171
|`paging`|boolean|Enables the paging feature. Defaults to _false_.|
171172
|`page`| number | The current page index.|
172173
|`perPage`|number|Visible items per page, default is 15|
@@ -333,7 +334,6 @@ Inputs available on the **IgxGridColumnComponent** to define columns:
333334
|`hasSummary`| boolean |Sets whether or not the specific column has summaries enabled.|
334335
|`summaries`| IgxSummaryOperand |Set custom summary for the specific column|
335336
|`hidden`|boolean|Visibility of the column|
336-
|`movable`|boolean|Set column to be movable|
337337
|`resizable`|boolean|Set column to be resizable|
338338
|`selectable`|boolean|Set column to be selectable|
339339
|`selected`|boolean|Set column to be selected|

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
425425
* Sets/gets whether the column is movable.
426426
* Default value is `false`.
427427
*
428-
* @deprecated
429-
* Use `IgxGridComponent.moving` instead.
428+
* @deprecated in version 13.1.0. Use `IgxGridComponent.moving` instead.
430429
*
431430
* ```typescript
432431
* let isMovable = this.column.movable;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export interface ColumnType {
142142
resizable: boolean;
143143
searchable: boolean;
144144
columnGroup: boolean;
145+
/** @deprecated in version 13.1.0. Use `IgxGridComponent.moving` instead.*/
145146
movable: boolean;
146147
groupable: boolean;
147148
sortable: boolean;

0 commit comments

Comments
 (0)