Skip to content

Commit 04abde0

Browse files
dafoViktorSlavov
authored andcommitted
chore(grid): migrate deprecated rowSelectable property to rowSelection
1 parent d119a37 commit 04abde0

File tree

6 files changed

+60
-6
lines changed

6 files changed

+60
-6
lines changed

projects/igniteui-angular/migrations/common/UpdateChanges.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class UpdateChanges {
1919
protected themePropsChanges: ThemePropertyChanges;
2020
protected importsChanges: ImportsChanges;
2121
protected conditionFunctions: Map<string, Function> = new Map<string, Function>();
22+
protected valueTransforms: Map<string, Function> = new Map<string, Function>();
2223

2324
private _templateFiles: string[] = [];
2425
public get templateFiles(): string[] {
@@ -130,6 +131,10 @@ export class UpdateChanges {
130131
this.conditionFunctions.set(conditionName, callback);
131132
}
132133

134+
public addValueTransform(functionName: string, callback: (oldValue: string) => string) {
135+
this.valueTransforms.set(functionName, callback);
136+
}
137+
133138
protected updateSelectors(entryPath: string) {
134139
let fileContent = this.host.read(entryPath).toString();
135140
let overwrite = false;
@@ -202,8 +207,8 @@ export class UpdateChanges {
202207
continue;
203208
}
204209

205-
let base;
206-
let replace;
210+
let base: string;
211+
let replace: string;
207212
let groups = 1;
208213
let searchPattern;
209214

@@ -212,8 +217,8 @@ export class UpdateChanges {
212217
replace = `(${change.replaceWith})=$1`;
213218
} else {
214219
// Match both bound - [name] - and regular - name
215-
base = String.raw`(\s\[?)${change.name}(\s*\]?=)(["'])`;
216-
replace = String.raw`$1${change.replaceWith}$2$3`;
220+
base = String.raw`(\s\[?)${change.name}(\s*\]?=)(["'])(.*?)\3`;
221+
replace = String.raw`$1${change.replaceWith}$2$3$4$3`;
217222
groups = 3;
218223
}
219224

@@ -244,6 +249,14 @@ export class UpdateChanges {
244249
fileContent = this.copyPropertyValueBetweenElementTags(fileContent, match, moveMatch);
245250
}
246251

252+
if (change.valueTransform) {
253+
const oldValue = match.match(reg).groups[3];
254+
const transform = this.valueTransforms.get(change.valueTransform);
255+
const newValue = transform(oldValue);
256+
// Check why the regEx does not return the correct value
257+
replace = replace.replace('$4', newValue);
258+
}
259+
247260
fileContent = fileContent.replace(
248261
match,
249262
match.replace(reg, replace)

projects/igniteui-angular/migrations/common/schema/binding.schema.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
"description": "Component that emits the output or accepts the input"
2424
},
2525
"remove": {
26-
"description": "Remove directive/component",
26+
"description": "Remove directive/component/property",
2727
"type": "boolean"
2828
},
2929
"replaceWith": {
30-
"description": "Replace original selector with new one",
30+
"description": "Replace original selector/property with new one",
31+
"type": "string"
32+
},
33+
"valueTransform": {
34+
"description": "A function that transforms the value of an Input",
3135
"type": "string"
3236
}
3337
},

projects/igniteui-angular/migrations/common/schema/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface BindingChange extends ChangeAction {
3131
moveBetweenElementTags?: boolean;
3232
/** An array of function names that will be executed as conditions. */
3333
conditions?: string[];
34+
/** A function that transforms the value of an Input */
35+
valueTransform?: string;
3436
}
3537

3638
export interface ClassChanges {

projects/igniteui-angular/migrations/update-9_1_0/changes/inputs.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
"selector": "igx-toast",
1717
"type": "component"
1818
}
19+
},
20+
{
21+
"name": "rowSelectable",
22+
"replaceWith": "rowSelection",
23+
"valueTransform": "rowSelectable_is_deprecated",
24+
"owner": {
25+
"selector": "igx-grid",
26+
"type": "component"
27+
}
1928
}
2029
]
2130
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,19 @@ describe('Update 9.1.0', () => {
5555

5656
done();
5757
});
58+
59+
// Except for testing for true and false (' and ") check for binded scenarios like "'prop'"
60+
fit('should update rowSelectable to rowSelection', done => {
61+
appTree.create(
62+
`/testSrc/appPrefix/component/input.component.html`,
63+
`<igx-grid [rowSelectable]="true"></igx-grid>`
64+
);
65+
66+
const tree = schematicRunner.runSchematic('migration-15', {}, appTree);
67+
68+
expect(tree.readContent('/testSrc/appPrefix/component/input.component.html'))
69+
.toEqual(`<igx-grid [rowSelection]="'multiple'"></igx-grid>`);
70+
71+
done();
72+
});
5873
});

projects/igniteui-angular/migrations/update-9_1_0/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export default function(): Rule {
1212
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
1313

1414
const update = new UpdateChanges(__dirname, host, context);
15+
update.addValueTransform('rowSelectable_is_deprecated', function(oldValue: string): string {
16+
17+
switch (oldValue) {
18+
case 'true':
19+
return '\'multiple\'';
20+
case 'false':
21+
return '\'none\'';
22+
default:
23+
return `${oldValue} ? 'multiple' : 'none' `;
24+
}
25+
});
1526
update.applyChanges();
1627
};
1728
}

0 commit comments

Comments
 (0)