From: Nizamudeen A Date: Thu, 5 May 2022 17:43:38 +0000 (+0530) Subject: mgr/dashboard: devices with same UID causes multiselection X-Git-Tag: v18.0.0~933^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F46174%2Fhead;p=ceph.git 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 --- 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 1250247aefff..d13f415275aa 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 a2b7f7ec3dec..427569ce5e0e 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); }