From 9fe18a62529037c0586edd032411f863f81b8f27 Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Thu, 5 May 2022 23:13:38 +0530 Subject: [PATCH] mgr/dashboard: devices with same UID causes multiselection In the Physical Disks page, the uids for multiple devices are coming in as same and that causes the selection to go berserk and select multiple rows with same UID. The uid is generated in the frontend service call itself. I just added some more parameters to it inorder to make it more unique. The second issue is the number of selected number getting multiplied exponentially. Its because each time the table is updated or refreshed, we push the row with the number of selected items we had before and that causes the number of selection to multiply. Fixes: https://tracker.ceph.com/issues/55523 Signed-off-by: Nizamudeen A --- .../frontend/src/app/shared/api/host.service.ts | 4 +++- .../src/app/shared/datatable/table/table.component.ts | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts index 1250247aefffa..d13f415275aa3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts @@ -141,7 +141,9 @@ export class HostService extends ApiClient { const devices = _.flatMap(hosts, (host) => { return host.devices.map((device) => { device.hostname = host.name; - device.uid = device.device_id ? device.device_id : `${device.hostname}-${device.path}`; + device.uid = device.device_id + ? `${device.device_id}-${device.hostname}-${device.path}` + : `${device.hostname}-${device.path}`; return device; }); }); 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 a2b7f7ec3dec5..427569ce5e0eb 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 @@ -668,21 +668,22 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O if (this.updateSelectionOnRefresh === 'never') { return; } - const newSelected: any[] = []; + const newSelected = new Set(); this.selection.selected.forEach((selectedItem) => { for (const row of this.data) { if (selectedItem[this.identifier] === row[this.identifier]) { - newSelected.push(row); + newSelected.add(row); } } }); + const newSelectedArray = Array.from(newSelected.values()); if ( this.updateSelectionOnRefresh === 'onChange' && - _.isEqual(this.selection.selected, newSelected) + _.isEqual(this.selection.selected, newSelectedArray) ) { return; } - this.selection.selected = newSelected; + this.selection.selected = newSelectedArray; this.onSelect(this.selection); } -- 2.39.5