]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Improve and simplify OsdListComponent 30493/head
authorPatrick Seidensal <pseidensal@suse.com>
Fri, 20 Sep 2019 13:55:18 +0000 (15:55 +0200)
committerPatrick Seidensal <pseidensal@suse.com>
Mon, 23 Sep 2019 10:53:26 +0000 (12:53 +0200)
Signed-off-by: Patrick Seidensal <pseidensal@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/ceph/cluster/osd/osd-list/osd-list.component.ts

index 7b2dcd69b31bdb68a1174d002f6097fc23246f3d..5e5d008718de820bed3c4fc7c4d40694ba140113 100644 (file)
@@ -59,7 +59,7 @@
 
 <ng-template #markOsdConfirmationTpl
              let-markActionDescription="markActionDescription">
-  <ng-container i18n><strong>OSD(s) {{  getSelectedIds() | list }}</strong> will be marked
+  <ng-container i18n><strong>OSD(s) {{  getSelectedOsdIds() | list }}</strong> will be marked
 <strong>{{ markActionDescription }}</strong> if you proceed.</ng-container>
 </ng-template>
 
@@ -70,6 +70,6 @@
        class="danger">
   <cd-warning-panel i18n>The {selection.hasSingleSelection, select, 1 {OSD is} 0 {OSDs are}} not safe to destroy!</cd-warning-panel>
   </div>
-  <ng-container i18n><strong>OSD {{ getSelectedIds() | list }}</strong> will be
+  <ng-container i18n><strong>OSD {{ getSelectedOsdIds() | list }}</strong> will be
 <strong>{{ actionDescription }}</strong> if you proceed.</ng-container>
 </ng-template>
index abf6f2992f61897b5eed105729309159b20542be..f230c42e4e21a45dd2b75e013b520239a7e163f7 100644 (file)
@@ -213,19 +213,23 @@ export class OsdListComponent implements OnInit {
     ];
   }
 
-  getSelectedIds() {
-    return this.selection.selected.map((row) => row.id);
+  /**
+   * Only returns valid IDs, e.g. if an OSD is falsely still selected after being deleted, it won't
+   * get returned.
+   */
+  getSelectedOsdIds(): number[] {
+    const osdIds = this.osds.map((osd) => osd.id);
+    return this.selection.selected.map((row) => row.id).filter((id) => osdIds.includes(id));
   }
 
-  get hasOsdSelected() {
-    const validOsds = [];
-    if (this.selection.hasSelection) {
-      for (const osdId of this.getSelectedIds()) {
-        validOsds.push(this.osds.filter((o) => o.id === osdId).pop());
-      }
-      return validOsds.length > 0;
-    }
-    return false;
+  getSelectedOsds(): any[] {
+    return this.osds.filter(
+      (osd) => !_.isUndefined(osd) && this.getSelectedOsdIds().includes(osd.id)
+    );
+  }
+
+  get hasOsdSelected(): boolean {
+    return this.getSelectedOsdIds().length > 0;
   }
 
   updateSelection(selection: CdTableSelection) {
@@ -233,36 +237,23 @@ export class OsdListComponent implements OnInit {
   }
 
   /**
-   * Returns true if no row is selected or if the selected row is in the given
+   * Returns true if no rows are selected or if *any* of the selected rows are in the given
    * state. Useful for deactivating the corresponding menu entry.
    */
   isNotSelectedOrInState(state: 'in' | 'up' | 'down' | 'out'): boolean {
-    if (!this.hasOsdSelected) {
+    const selectedOsds = this.getSelectedOsds();
+    if (selectedOsds.length === 0) {
       return true;
     }
-
-    let validOsds = [];
-    if (this.selection.hasSelection) {
-      for (const osdId of this.getSelectedIds()) {
-        validOsds.push(this.osds.filter((o) => o.id === osdId).pop());
-      }
-    }
-
-    validOsds = validOsds.filter((osd) => !_.isUndefined(osd));
-    if (validOsds.length === 0) {
-      // `osd` is undefined if the selected OSD has been removed.
-      return true;
-    }
-
     switch (state) {
       case 'in':
-        return validOsds.some((osd) => osd.in === 1);
+        return selectedOsds.some((osd) => osd.in === 1);
       case 'out':
-        return validOsds.some((osd) => osd.in !== 1);
+        return selectedOsds.some((osd) => osd.in !== 1);
       case 'down':
-        return validOsds.some((osd) => osd.up !== 1);
+        return selectedOsds.some((osd) => osd.up !== 1);
       case 'up':
-        return validOsds.some((osd) => osd.up === 1);
+        return selectedOsds.some((osd) => osd.up === 1);
     }
   }
 
@@ -285,7 +276,7 @@ export class OsdListComponent implements OnInit {
     }
 
     const initialState = {
-      selected: this.getSelectedIds(),
+      selected: this.getSelectedOsdIds(),
       deep: deep
     };
 
@@ -307,7 +298,7 @@ export class OsdListComponent implements OnInit {
         },
         onSubmit: () => {
           observableForkJoin(
-            this.getSelectedIds().map((osd: any) => onSubmit.call(this.osdService, osd))
+            this.getSelectedOsdIds().map((osd: any) => onSubmit.call(this.osdService, osd))
           ).subscribe(() => this.bsModalRef.hide());
         }
       }
@@ -330,7 +321,7 @@ export class OsdListComponent implements OnInit {
     templateItemDescription: string,
     action: (id: number) => Observable<any>
   ): void {
-    this.osdService.safeToDestroy(JSON.stringify(this.getSelectedIds())).subscribe((result) => {
+    this.osdService.safeToDestroy(JSON.stringify(this.getSelectedOsdIds())).subscribe((result) => {
       const modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
         initialState: {
           actionDescription: actionDescription,
@@ -342,7 +333,7 @@ export class OsdListComponent implements OnInit {
           },
           submitAction: () => {
             observableForkJoin(
-              this.getSelectedIds().map((osd: any) => action.call(this.osdService, osd))
+              this.getSelectedOsdIds().map((osd: any) => action.call(this.osdService, osd))
             ).subscribe(
               () => {
                 this.getOsdList();