From 9d316c34d2b386e5849a638a39da533307899d12 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Wed, 28 Mar 2018 16:53:59 +0100 Subject: [PATCH] mgr/dashboard: Update selected items on table refresh Signed-off-by: Ricardo Marques --- .../osd/osd-list/osd-list.component.html | 3 ++- .../shared/datatable/table/table.component.ts | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html index ebf795c3c98e3..86db34300a437 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html @@ -8,7 +8,8 @@ (fetchData)="getOsdList()" [columns]="columns" selectionType="single" - (updateSelection)="updateSelection($event)"> + (updateSelection)="updateSelection($event)" + [updateSelectionOnRefresh]="false"> 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 1a120d6ec4773..8d1470d3fa2a2 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 @@ -69,6 +69,9 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O // e.g. 'single' or 'multi'. @Input() selectionType: string = undefined; + // If `true` selected item details will be updated on table refresh + @Input() updateSelectionOnRefresh = true; + /** * Should be a function to update the input data if undefined nothing will be triggered * @@ -223,6 +226,27 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O } this.loadingIndicator = false; this.updating = false; + if (this.updateSelectionOnRefresh) { + this.updateSelected(); + } + } + + /** + * After updating the data, we have to update the selected items + * because details may have changed, + * or some selected items may have been removed. + */ + updateSelected() { + const newSelected = []; + this.selection.selected.forEach((selectedItem) => { + for (const row of this.data) { + if (selectedItem[this.identifier] === row[this.identifier]) { + newSelected.push(row); + } + } + }); + this.selection.selected = newSelected; + this.onSelect(); } onSelect() { -- 2.39.5