Skip to content

Commit 96e5402

Browse files
authored
[bugfix] Fix frontend error when all monitor metrics are selected in new bulletin form (#3345)
1 parent 0a6e814 commit 96e5402

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

web-app/src/app/routes/bulletin/bulletin.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,14 @@
218218
<nz-form-item>
219219
<nz-form-label [nzSpan]="7" nzFor="dropdown" nzRequired="true">{{ 'bulletin.monitor.metrics' | i18n }}</nz-form-label>
220220
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
221-
<nz-transfer [nzDataSource]="hierarchies" [nzRenderList]="[leftRenderList, null]" (nzChange)="transferChange($event)">
222-
<ng-template #leftRenderList let-items let-onItemSelect="onItemSelect">
221+
<nz-transfer
222+
[nzDataSource]="hierarchies"
223+
[nzRenderList]="[leftRenderList, null]"
224+
(nzChange)="transferChange($event)"
225+
(nzSelectChange)="onSelectChange($event)"
226+
>
227+
<ng-template #leftRenderList let-items let-onItemSelect="onItemSelect" let-stat="stat">
228+
<div *ngIf="updateTransferStat(stat)"></div>
223229
<nz-tree
224230
[nzData]="treeNodes"
225231
nzExpandAll

web-app/src/app/routes/bulletin/bulletin.component.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ALAIN_I18N_TOKEN } from '@delon/theme';
2323
import { NzModalService } from 'ng-zorro-antd/modal';
2424
import { NzNotificationService } from 'ng-zorro-antd/notification';
2525
import { NzTableQueryParams } from 'ng-zorro-antd/table';
26-
import { TransferChange } from 'ng-zorro-antd/transfer';
26+
import { TransferChange, TransferSelectChange, TransferStat } from 'ng-zorro-antd/transfer';
2727
import { NzFormatEmitEvent, NzTreeNode, NzTreeNodeOptions } from 'ng-zorro-antd/tree';
2828
import { Subject } from 'rxjs';
2929
import { finalize, debounceTime, distinctUntilChanged } from 'rxjs/operators';
@@ -76,6 +76,7 @@ export class BulletinComponent implements OnInit, OnDestroy {
7676
filterLabels: Record<string, string> = {};
7777
filteredMonitors: Monitor[] = [];
7878
private filterSubject = new Subject<string>(); //filter logic debouncing
79+
currentStat: TransferStat | null = null; //transfer component status
7980

8081
ngOnInit() {
8182
this.loadTabs();
@@ -368,6 +369,42 @@ export class BulletinComponent implements OnInit, OnDestroy {
368369
return tree;
369370
}
370371

372+
updateTransferStat(stat: TransferStat): boolean {
373+
this.currentStat = stat;
374+
// stat.shownCount = 33;
375+
return true;
376+
}
377+
378+
private collectLeafNodes(nodes: NzTreeNodeOptions[], results: NzTreeNodeOptions[]): void {
379+
nodes.forEach(node => {
380+
if (node.isLeaf && !node.disabled) {
381+
results.push(node);
382+
}
383+
if (node.children) {
384+
this.collectLeafNodes(node.children, results);
385+
}
386+
});
387+
}
388+
389+
onSelectChange(event: TransferSelectChange): void {
390+
if (event.direction === 'left' && event.checked && this.currentStat?.checkAll) {
391+
const allLeafNodes: NzTreeNodeOptions[] = [];
392+
this.collectLeafNodes(this.treeNodes, allLeafNodes);
393+
394+
allLeafNodes.forEach(node => {
395+
const existing = this.checkedNodeList.find(n => n.origin.id === node.id);
396+
if (!existing) {
397+
const treeNode = new NzTreeNode(node);
398+
treeNode.isChecked = true;
399+
this.checkedNodeList.push(treeNode);
400+
}
401+
});
402+
}
403+
if (event.direction === 'left' && !event.checked && this.currentStat?.checkAll === false) {
404+
this.checkedNodeList = [];
405+
}
406+
}
407+
371408
treeCheckBoxChange(event: NzFormatEmitEvent, onItemSelect: (item: NzTreeNodeOptions) => void): void {
372409
this.checkBoxChange(event.node!, onItemSelect);
373410
}

0 commit comments

Comments
 (0)