Skip to content

Commit b11cc08

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add custom migration logic for DropPosition.None.
1 parent d624513 commit b11cc08

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
"version": "9.1.0",
7676
"description": "Updates Ignite UI for Angular from v9.0.x to v9.1.0",
7777
"factory": "./update-9_1_0"
78+
},
79+
"migration-16": {
80+
"version": "10.1.0",
81+
"description": "Updates Ignite UI for Angular from v9.1.x to v10.1.0",
82+
"factory": "./update-10_1_0"
7883
}
7984
}
8085
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as path from 'path';
2+
3+
// tslint:disable:no-implicit-dependencies
4+
import { virtualFs } from '@angular-devkit/core';
5+
import { EmptyTree } from '@angular-devkit/schematics';
6+
// tslint:disable-next-line:no-submodule-imports
7+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
8+
9+
describe('Update 10.1.0', () => {
10+
let appTree: UnitTestTree;
11+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
12+
const configJson = {
13+
defaultProject: 'testProj',
14+
projects: {
15+
testProj: {
16+
sourceRoot: '/testSrc'
17+
}
18+
},
19+
schematics: {
20+
'@schematics/angular:component': {
21+
prefix: 'appPrefix'
22+
}
23+
}
24+
};
25+
26+
beforeEach(() => {
27+
appTree = new UnitTestTree(new EmptyTree());
28+
appTree.create('/angular.json', JSON.stringify(configJson));
29+
});
30+
31+
it('should update DropPosition.None', done => {
32+
const origFileContent =
33+
`import { Component, Injectable, ViewChild } from "@angular/core";` +
34+
`import { IgxGridComponent, DropPosition } from "igniteui-angular";` +
35+
`import { IgxColumnComponent } from "igniteui-angular";\r\n` +
36+
`@Component({` +
37+
` providers: [RemoteService]` +
38+
`})` +
39+
`export class GridSampleComponent {` +
40+
` @ViewChild("grid1", { read: IgxGridComponent }) public grid1: IgxGridComponent;` +
41+
` public move() {` +
42+
` const column: IgxColumnComponent = this.grid1.columns[0];` +
43+
` const column2: IgxColumnComponent = this.grid1.columns[1];` +
44+
` this.grid1.moveColumn(col1, col2, DropPosition.None);` +
45+
` }` +
46+
`}`;
47+
const expectedFileContent =
48+
`import { Component, Injectable, ViewChild } from "@angular/core";` +
49+
`import { IgxGridComponent, DropPosition } from "igniteui-angular";` +
50+
`import { IgxColumnComponent } from "igniteui-angular";\r\n` +
51+
`@Component({` +
52+
` providers: [RemoteService]` +
53+
`})` +
54+
`export class GridSampleComponent {` +
55+
` @ViewChild("grid1", { read: IgxGridComponent }) public grid1: IgxGridComponent;` +
56+
` public move() {` +
57+
` const column: IgxColumnComponent = this.grid1.columns[0];` +
58+
` const column2: IgxColumnComponent = this.grid1.columns[1];` +
59+
` this.grid1.moveColumn(col1, col2, DropPosition.AfterDropTarget);` +
60+
` }` +
61+
`}`;
62+
appTree.create(
63+
'/testSrc/appPrefix/component/drop.component.ts',
64+
origFileContent);
65+
66+
const tree = schematicRunner.runSchematic('migration-16', {}, appTree);
67+
expect(tree.readContent('/testSrc/appPrefix/component/drop.component.ts'))
68+
.toEqual(expectedFileContent);
69+
done();
70+
});
71+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
Rule,
3+
SchematicContext,
4+
Tree
5+
} from '@angular-devkit/schematics';
6+
import { UpdateChanges } from '../common/UpdateChanges';
7+
import { getIdentifierPositions } from '../common/tsUtils';
8+
import * as ts from 'typescript';
9+
10+
const version = '10.1.0';
11+
12+
export default function(): Rule {
13+
return (host: Tree, context: SchematicContext) => {
14+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
15+
16+
const update = new UpdateChanges(__dirname, host, context);
17+
// update.applyChanges();
18+
19+
// replace DropPosition.None with DropPosition.AfterDropTarget
20+
for (const entryPath of update.tsFiles) {
21+
let content = host.read(entryPath).toString();
22+
if (content.indexOf('DropPosition.None') !== -1) {
23+
const pos = getIdentifierPositions(content, 'DropPosition');
24+
for (let i = pos.length; i--;) {
25+
const end = pos[i].end + 5;
26+
const isMatch = content.slice(pos[i].start, end) === 'DropPosition.None';
27+
if (isMatch) {
28+
content = content.slice(0, pos[i].start) + 'DropPosition.AfterDropTarget' + content.slice(end);
29+
}
30+
}
31+
host.overwrite(entryPath, content);
32+
}
33+
}
34+
};
35+
}

projects/igniteui-angular/src/lib/grids/moving/moving.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22
import { IgxColumnComponent } from '../columns/column.component';
33

44
/**
5-
* This enumeration is used to configure whether the pinning position is set before or after
5+
* This enumeration is used to configure whether the drop position is set before or after
66
* the target.
77
*/
88
export enum DropPosition {

0 commit comments

Comments
 (0)