]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Update selected items on table refresh 21099/head
authorRicardo Marques <rimarques@suse.com>
Wed, 28 Mar 2018 15:53:59 +0000 (16:53 +0100)
committerRicardo Marques <rimarques@suse.com>
Wed, 11 Apr 2018 11:10:43 +0000 (12:10 +0100)
Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.ts

index ebf795c3c98e305707d7b39ddd85192f78407799..86db34300a437b5fab024aca4c9e992a980ccb0f 100644 (file)
@@ -8,7 +8,8 @@
           (fetchData)="getOsdList()"
           [columns]="columns"
           selectionType="single"
-          (updateSelection)="updateSelection($event)">
+          (updateSelection)="updateSelection($event)"
+          [updateSelectionOnRefresh]="false">
   <cd-osd-details cdTableDetail
                   [selection]="selection">
   </cd-osd-details>
index 1a120d6ec477389f1a92dc21d77f21eb828b6bfc..8d1470d3fa2a276cca573e9767f60593cbc51035 100644 (file)
@@ -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() {