Skip to content

Commit 26901f1

Browse files
authored
Merge pull request #9916 from IgniteUI/vslavov/transaction-refactor-migrations
feat(grids): add migrations for deprecated IgxGridTransaction token
2 parents 3d9502f + 1333af6 commit 26901f1

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,73 @@ public onBannerOpened(event: BannerEventArgs) {
700700
}`);
701701
});
702702

703+
// Transaction providers
704+
it('Should add a comment for the deprecated IgxGridTransactionToken', async () => {
705+
appTree.create(
706+
'/testSrc/appPrefix/component/transaction.component.ts', `
707+
import { IgxGridComponent, IgxGridTransaction, IgxTransactionService } from 'igniteui-angular';
708+
@Component({
709+
template: '',
710+
providers: [{ provide: IgxGridTransaction, useClass: IgxTransactionService }]
711+
})
712+
export class TransactionComponent {
713+
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
714+
public IgxGridTransaction!: IgxGridComponent;
715+
}`);
716+
const tree = await schematicRunner.runSchematicAsync(migrationName, {}, appTree)
717+
.toPromise();
718+
719+
expect(tree.readContent('/testSrc/appPrefix/component/transaction.component.ts'))
720+
.toEqual(`
721+
import { IgxGridComponent, IgxGridTransaction, IgxTransactionService } from 'igniteui-angular';
722+
@Component({
723+
template: '',
724+
providers: [/* Injection token 'IgxGridTransaction' has been deprecated. Please refer to the update guide for more details. */
725+
{ provide: IgxGridTransaction, useClass: IgxTransactionService }]
726+
})
727+
export class TransactionComponent {
728+
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
729+
public IgxGridTransaction!: IgxGridComponent;
730+
}`);
731+
});
732+
733+
it('Should add a comment for the deprecated IgxGridTransactionToken, multiple providers', async () => {
734+
appTree.create(
735+
'/testSrc/appPrefix/component/transaction.component.ts', `
736+
import { IgxGridComponent, IgxGridTransaction, IgxTransactionService } from 'igniteui-angular';
737+
@Component({
738+
template: '',
739+
providers: [
740+
{ provider: A, useClass: AService },
741+
{ provide: IgxGridTransaction, useClass: IgxTransactionService },
742+
{ provider: B, useClass: BService}
743+
]
744+
})
745+
export class TransactionComponent {
746+
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
747+
public IgxGridTransaction!: IgxGridComponent;
748+
}`);
749+
const tree = await schematicRunner.runSchematicAsync(migrationName, {}, appTree)
750+
.toPromise();
751+
752+
expect(tree.readContent('/testSrc/appPrefix/component/transaction.component.ts'))
753+
.toEqual(`
754+
import { IgxGridComponent, IgxGridTransaction, IgxTransactionService } from 'igniteui-angular';
755+
@Component({
756+
template: '',
757+
providers: [
758+
{ provider: A, useClass: AService },
759+
/* Injection token 'IgxGridTransaction' has been deprecated. Please refer to the update guide for more details. */
760+
{ provide: IgxGridTransaction, useClass: IgxTransactionService },
761+
{ provider: B, useClass: BService}
762+
]
763+
})
764+
export class TransactionComponent {
765+
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
766+
public IgxGridTransaction!: IgxGridComponent;
767+
}`);
768+
});
769+
703770
it('Should properly rename IComboSelectionChangeEventArgs to IComboSelectionChangingEventArgs', async () => {
704771
appTree.create('/testSrc/appPrefix/component/test.component.ts',
705772
`
@@ -751,4 +818,3 @@ public onBannerOpened(event: BannerEventArgs) {
751818
});
752819
});
753820

754-

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
1414
const prop = ['[paging]', 'paging'];
1515
const changes = new Map<string, FileChange[]>();
1616
const warnMsg = `\n<!-- Auto migrated template content. Please, check your bindings! -->\n`;
17+
const deprecatedToken = 'IgxGridTransaction';
18+
const providerWarnMsg = `/* Injection token 'IgxGridTransaction' has been deprecated. ` +
19+
`Please refer to the update guide for more details. */`;
1720
const templateNames = [];
1821

1922
const applyChanges = () => {
@@ -111,5 +114,17 @@ export default (): Rule => (host: Tree, context: SchematicContext) => {
111114
applyChanges();
112115
changes.clear();
113116

117+
const matchStr = String.raw`({\s*provide:\s*${deprecatedToken}[^}]*},?)`;
118+
const matchExpr = new RegExp(matchStr, 'g');
119+
120+
for (const path of update.tsFiles) {
121+
let content = host.read(path)?.toString();
122+
if (content.indexOf(deprecatedToken) < 0) {
123+
continue;
124+
}
125+
content = content.replace(matchExpr, `${providerWarnMsg}\n$1`);
126+
host.overwrite(path, content);
127+
}
128+
114129
update.applyChanges();
115130
};

0 commit comments

Comments
 (0)