Skip to content

Commit aed3733

Browse files
committed
mgr/dashboard: fix duplicated editing of cell
form control is applied with unique identifier. In the table where the issue is present, let's support adding the `unique_identifier`. Fixes: https://tracker.ceph.com/issues/73250 Signed-off-by: Nizamudeen A <[email protected]>
1 parent 53e4f74 commit aed3733

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,26 +410,26 @@
410410
let-value="data.value"
411411
let-row="data.row"
412412
let-column="data.column">
413-
@if (isCellEditing(row?.id, column?.prop)) {
413+
@if (isCellEditing(row?.[identifier], column?.prop)) {
414414
<form [formGroup]="formGroup"
415415
#formDir="ngForm">
416416
<div cdsRow>
417417
<div cdsCol>
418-
<cds-text-label [invalid]="formGroup.controls[row?.id + '-' + column?.prop]?.invalid && formGroup.controls[row?.id + '-' + column?.prop]?.dirty"
418+
<cds-text-label [invalid]="formGroup.controls[row?.[identifier] + '-' + column?.prop]?.invalid && formGroup.controls[row?.[identifier] + '-' + column?.prop]?.dirty"
419419
[invalidText]="errorTpl">
420420
<input type="text"
421421
cdsText
422422
size="sm"
423-
[id]="row?.id + '-' + column?.prop"
424-
[formControlName]="row?.id + '-' + column?.prop"
425-
(input)="valueChange(row?.id, column?.prop, $event.target.value)"
426-
[invalid]="formGroup.controls[row?.id + '-' + column?.prop]?.invalid && formGroup.controls[row?.id + '-' + column?.prop]?.dirty">
423+
[id]="row?.[identifier] + '-' + column?.prop"
424+
[formControlName]="row?.[identifier] + '-' + column?.prop"
425+
(input)="valueChange(row?.[identifier], column?.prop, $event.target.value)"
426+
[invalid]="formGroup.controls[row?.[identifier] + '-' + column?.prop]?.invalid && formGroup.controls[row?.[identifier] + '-' + column?.prop]?.dirty">
427427
</cds-text-label>
428428
<ng-template #errorTpl>
429-
<span *ngIf="formGroup?.showError(row?.id + '-' + column?.prop, formDir, 'required')">
429+
<span *ngIf="formGroup?.showError(row?.[identifier] + '-' + column?.prop, formDir, 'required')">
430430
<ng-container i18n>This field is required.</ng-container>
431431
</span>
432-
<span *ngIf="column?.customTemplateConfig?.formGroup?.showError(row?.id + '-' + column?.prop, formDir, 'pattern')">
432+
<span *ngIf="column?.customTemplateConfig?.formGroup?.showError(row?.[identifier] + '-' + column?.prop, formDir, 'pattern')">
433433
<ng-container i18n>The field format is invalid.</ng-container>
434434
</span>
435435
</ng-template>
@@ -441,7 +441,7 @@
441441
size="sm"
442442
id="cell-inline-save-btn"
443443
type="button"
444-
(click)="saveCellItem(row?.id, column?.prop)">
444+
(click)="saveCellItem(row, column?.prop)">
445445
<cd-icon type="check"></cd-icon>
446446
</button>
447447
</div>
@@ -459,7 +459,7 @@
459459
<button cdsButton="ghost"
460460
size="sm"
461461
id="cell-inline-edit-btn"
462-
(click)="editCellItem(row?.id, column, value)">
462+
(click)="editCellItem(row[identifier], column, value)">
463463
<cd-icon type="edit"></cd-icon>
464464
</button>
465465
</div>

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ describe('TableComponent', () => {
608608
component.editCellItem('id-0', component.localColumns[0], '0');
609609
}
610610

611+
component.identifier = 'id';
611612
component.ngOnInit();
612613
component.ngAfterViewInit();
613614
fixture.detectChanges();

src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
253253
@Output() columnFiltersChanged = new EventEmitter<CdTableColumnFiltersChange>();
254254

255255
@Output()
256-
editSubmitAction = new EventEmitter<{ [field: string]: string }>();
256+
editSubmitAction = new EventEmitter<{
257+
state: { [field: string]: string };
258+
row: any;
259+
}>();
257260

258261
/**
259262
* Use this variable to access the selected row(s).
@@ -1396,14 +1399,17 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr
13961399
this.editStates[rowId][column.prop] = value;
13971400
}
13981401

1399-
saveCellItem(rowId: string, colProp: string) {
1402+
saveCellItem(row: any, colProp: string) {
14001403
if (this.formGroup?.invalid) {
14011404
this.formGroup.setErrors({ cdSubmitButton: true });
14021405
return;
14031406
}
1404-
this.editSubmitAction.emit(this.editStates[rowId]);
1405-
this.editingCells.delete(`${rowId}-${colProp}`);
1406-
delete this.editStates[rowId][colProp];
1407+
this.editSubmitAction.emit({
1408+
state: this.editStates[row[this.identifier]],
1409+
row: row
1410+
});
1411+
this.editingCells.delete(`${row[this.identifier]}-${colProp}`);
1412+
delete this.editStates[row[this.identifier]][colProp];
14071413
}
14081414

14091415
isCellEditing(rowId: string, colProp: string): boolean {

src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export enum CellTemplate {
9191
// }
9292
// ...
9393
// }
94+
Also need to pass forceIdentifer=true and also a unique identifier prop like
95+
identifier="uid" to the table in some cases to avoid issues.
9496
*/
9597
editing = 'editing'
9698
}

0 commit comments

Comments
 (0)