Skip to content

Commit e240264

Browse files
authored
fix(module:notification): don't create new messageId for update (#8000)
* fix(module:notification): don't create new messageId for update * refactor(module:notification): remove useless code * chore: update gitignore
1 parent 8b6b653 commit e240264

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ report.*.json
5454
# System Files
5555
.DS_Store
5656
Thumbs.db
57+
58+
monospace.json

components/message/base.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,15 @@ export abstract class NzMNContainerComponent implements OnInit, OnDestroy {
101101
}
102102

103103
remove(id: string, userAction: boolean = false): void {
104-
this.instances.some((instance, index) => {
105-
if (instance.messageId === id) {
104+
this.instances
105+
.map((instance, index) => ({ index, instance }))
106+
.filter(({ instance }) => instance.messageId === id)
107+
.forEach(({ index, instance }) => {
106108
this.instances.splice(index, 1);
107109
this.instances = [...this.instances];
108110
this.onRemove(instance, userAction);
109111
this.readyInstances();
110-
return true;
111-
}
112-
return false;
113-
});
112+
});
114113
}
115114

116115
removeAll(): void {

components/notification/notification.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class NzNotificationService extends NzMNService {
7070
...message,
7171
...{
7272
createdAt: new Date(),
73-
messageId: this.generateMessageId(),
73+
messageId: options?.nzKey || this.generateMessageId(),
7474
options
7575
}
7676
});

components/notification/notification.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55

66
import { HomeOutline } from '@ant-design/icons-angular/icons';
77

8-
import { NzConfigService, NZ_CONFIG } from 'ng-zorro-antd/core/config';
8+
import { NZ_CONFIG, NzConfigService } from 'ng-zorro-antd/core/config';
99
import { dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
1010
import { ComponentBed, createComponentBed } from 'ng-zorro-antd/core/testing/component-bed';
1111
import { NZ_ICONS } from 'ng-zorro-antd/icon';
@@ -218,9 +218,12 @@ describe('NzNotification', () => {
218218
});
219219

220220
it('should update an existing notification when keys are matched', () => {
221-
notificationService.create('', '', 'EXISTS', { nzKey: 'exists' });
221+
let messageId: string | null = null;
222+
messageId = notificationService.create('', '', 'EXISTS', { nzKey: 'exists' }).messageId;
222223
expect(overlayContainerElement.textContent).toContain('EXISTS');
223-
notificationService.create('success', 'Title', 'SHOULD NOT CHANGE', { nzKey: 'exists' });
224+
expect(messageId).toEqual('exists');
225+
messageId = notificationService.create('success', 'Title', 'SHOULD NOT CHANGE', { nzKey: 'exists' }).messageId;
226+
expect(messageId).toEqual('exists');
224227
expect(overlayContainerElement.textContent).not.toContain('EXISTS');
225228
expect(overlayContainerElement.textContent).toContain('Title');
226229
expect(overlayContainerElement.textContent).toContain('SHOULD NOT CHANGE');

0 commit comments

Comments
 (0)