From aed373399a6dbc29c22f74a939fdd5ea226333bb Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Thu, 25 Sep 2025 10:04:10 +0530 Subject: [PATCH] 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 --- .../datatable/table/table.component.html | 20 +++++++++---------- .../datatable/table/table.component.spec.ts | 1 + .../shared/datatable/table/table.component.ts | 16 ++++++++++----- .../src/app/shared/enum/cell-template.enum.ts | 2 ++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html index 75a47529b8c..849f02be658 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.html @@ -410,26 +410,26 @@ let-value="data.value" let-row="data.row" let-column="data.column"> - @if (isCellEditing(row?.id, column?.prop)) { + @if (isCellEditing(row?.[identifier], column?.prop)) {
- + [id]="row?.[identifier] + '-' + column?.prop" + [formControlName]="row?.[identifier] + '-' + column?.prop" + (input)="valueChange(row?.[identifier], column?.prop, $event.target.value)" + [invalid]="formGroup.controls[row?.[identifier] + '-' + column?.prop]?.invalid && formGroup.controls[row?.[identifier] + '-' + column?.prop]?.dirty"> - + This field is required. - + The field format is invalid. @@ -441,7 +441,7 @@ size="sm" id="cell-inline-save-btn" type="button" - (click)="saveCellItem(row?.id, column?.prop)"> + (click)="saveCellItem(row, column?.prop)">
@@ -459,7 +459,7 @@
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts index 4eb46549512..35afd964ae3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts @@ -608,6 +608,7 @@ describe('TableComponent', () => { component.editCellItem('id-0', component.localColumns[0], '0'); } + component.identifier = 'id'; component.ngOnInit(); component.ngAfterViewInit(); fixture.detectChanges(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts index 3058a3bc2d3..081918b9235 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts @@ -253,7 +253,10 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr @Output() columnFiltersChanged = new EventEmitter(); @Output() - editSubmitAction = new EventEmitter<{ [field: string]: string }>(); + editSubmitAction = new EventEmitter<{ + state: { [field: string]: string }; + row: any; + }>(); /** * Use this variable to access the selected row(s). @@ -1396,14 +1399,17 @@ export class TableComponent implements AfterViewInit, OnInit, OnChanges, OnDestr this.editStates[rowId][column.prop] = value; } - saveCellItem(rowId: string, colProp: string) { + saveCellItem(row: any, colProp: string) { if (this.formGroup?.invalid) { this.formGroup.setErrors({ cdSubmitButton: true }); return; } - this.editSubmitAction.emit(this.editStates[rowId]); - this.editingCells.delete(`${rowId}-${colProp}`); - delete this.editStates[rowId][colProp]; + this.editSubmitAction.emit({ + state: this.editStates[row[this.identifier]], + row: row + }); + this.editingCells.delete(`${row[this.identifier]}-${colProp}`); + delete this.editStates[row[this.identifier]][colProp]; } isCellEditing(rowId: string, colProp: string): boolean { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts index 97cd9f84d98..fc0846b3576 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/enum/cell-template.enum.ts @@ -91,6 +91,8 @@ export enum CellTemplate { // } // ... // } + Also need to pass forceIdentifer=true and also a unique identifier prop like + identifier="uid" to the table in some cases to avoid issues. */ editing = 'editing' } -- 2.39.5