Skip to content

Commit

Permalink
refactor(module:notification): remove deprecated APIs for v10
Browse files Browse the repository at this point in the history
BREAKING CHANGES:

- `NzNotificationDataFilled` has been removed, use `NzNotificationRef` instead.
- `NzNotificationDataOptions.nzPosition` has been removed, use `NzNotificationDataOptions.nzPlacement` instead.
  • Loading branch information
hsuanxyz committed Sep 15, 2020
1 parent e50d530 commit 9a212a1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 21 deletions.
9 changes: 1 addition & 8 deletions components/notification/notification-container.component.ts
Expand Up @@ -5,7 +5,6 @@

import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ViewEncapsulation } from '@angular/core';
import { NotificationConfig, NzConfigKey, NzConfigService } from 'ng-zorro-antd/core/config';
import { warnDeprecation } from 'ng-zorro-antd/core/logger';
import { toCssPixel } from 'ng-zorro-antd/core/util';

import { NzMNContainerComponent } from 'ng-zorro-antd/message';
Expand Down Expand Up @@ -146,13 +145,7 @@ export class NzNotificationContainerComponent extends NzMNContainerComponent {
}

protected mergeOptions(options?: NzNotificationDataOptions): NzNotificationDataOptions {
const { nzPosition } = options ?? {};

if (nzPosition) {
warnDeprecation('`nzPosition` of NzNotificationDataOptions is deprecated and would be removed in 10.0.0. Use `nzPlacement` instead.');
}

const { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement } = this.config;
return { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement: nzPlacement || nzPosition, ...options };
return { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement: nzPlacement, ...options };
}
}
11 changes: 0 additions & 11 deletions components/notification/typings.ts
Expand Up @@ -20,11 +20,6 @@ export interface NzNotificationDataOptions<T = {}> {
nzDuration?: number;
nzAnimate?: boolean;
nzPauseOnHover?: boolean;

/**
* @deprecated use nzPlacement instead, this would be removed in 10.0.0
*/
nzPosition?: NzNotificationPlacement;
}

export interface NzNotificationData {
Expand All @@ -43,9 +38,3 @@ export interface NzNotificationData {
}

export type NzNotificationRef = Pick<Required<NzNotificationData>, 'onClose' | 'onClick' | 'messageId'>;

/**
* @deprecated use `NzNotificationRef` instead
* @breaking-change 10.0.0
*/
export type NzNotificationDataFilled = NzNotificationRef;
6 changes: 6 additions & 0 deletions schematics/ng-update/data/class-names.ts
Expand Up @@ -14,6 +14,12 @@ export const classNames: VersionChanges<ClassNameUpgradeData> = {
{replace: 'UploadXHRArgs', replaceWith: 'NzUploadXHRArgs'}
]
},
{
pr: 'https://github.com/NG-ZORRO/ng-zorro-antd/pull/5779',
changes: [
{replace: 'NzNotificationDataFilled', replaceWith: 'NzNotificationRef'}
]
},
{
pr: 'https://github.com/NG-ZORRO/ng-zorro-antd/pull/5778',
changes: [
Expand Down
16 changes: 14 additions & 2 deletions schematics/ng-update/data/property-names.ts
@@ -1,4 +1,16 @@

import { PropertyNameUpgradeData, VersionChanges } from '@angular/cdk/schematics';
import { PropertyNameUpgradeData, TargetVersion, VersionChanges } from '@angular/cdk/schematics';

export const propertyNames: VersionChanges<PropertyNameUpgradeData> = {};
export const propertyNames: VersionChanges<PropertyNameUpgradeData> = {
[TargetVersion.V10]: [{
pr: '',
changes: [
{
replace: 'nzPosition',
replaceWith: 'nzPlacement',
whitelist: {classes: ['NzNotificationDataOptions']}
}
]
}
]
};
@@ -0,0 +1,67 @@
import { getSystemPath, normalize, virtualFs } from '@angular-devkit/core';
import { TempScopedNodeJsSyncHost } from '@angular-devkit/core/node/testing';
import { HostTree } from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import * as shx from 'shelljs';
import { SchematicsTestNGConfig, SchematicsTestTsConfig } from '../config';

describe('upload migration', () => {
let runner: SchematicTestRunner;
let host: TempScopedNodeJsSyncHost;
let tree: UnitTestTree;
let tmpDirPath: string;
let previousWorkingDir: string;

beforeEach(() => {
runner = new SchematicTestRunner('test', require.resolve('../../../migration.json'));
host = new TempScopedNodeJsSyncHost();
tree = new UnitTestTree(new HostTree(host));

writeFile('/tsconfig.json', JSON.stringify(SchematicsTestTsConfig));
writeFile('/angular.json', JSON.stringify(SchematicsTestNGConfig));

previousWorkingDir = shx.pwd();
tmpDirPath = getSystemPath(host.root);

shx.cd(tmpDirPath);

writeFakeAngular();
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
});

function writeFakeAngular(): void { writeFile('/node_modules/@angular/core/index.d.ts', ``); }

function writeFile(filePath: string, contents: string): void {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
}

// tslint:disable-next-line:no-any
async function runMigration(): Promise<any> {
await runner.runSchematicAsync('migration-v10', {}, tree).toPromise();
}

describe('Property names', () => {

it('should replace deprecated property names', async() => {
writeFile('/index.ts', `
export interface NzNotificationDataOptions {
nzPlacement?: any;
nzPosition?: any;
}
const option: NzNotificationDataOptions = {};
console.log(option.nzPosition);`);

await runMigration();
const content = tree.readContent('/index.ts');

expect(content).toContain(`console.log(option.nzPlacement)`);
expect(content).not.toContain(`console.log(option.nzPosition)`);
});

});

});

0 comments on commit 9a212a1

Please sign in to comment.