]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Bypass current selection when calling CdTableAction::disableDesc().
authorVolker Theile <vtheile@suse.com>
Tue, 23 Jun 2020 10:19:54 +0000 (12:19 +0200)
committerLaura Paduano <lpaduano@suse.com>
Mon, 6 Jul 2020 14:44:20 +0000 (16:44 +0200)
Signed-off-by: Volker Theile <vtheile@suse.com>
(cherry picked from commit a92baa8523279f663644837304f1e6c71787a63e)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts

index 69ed5df199647f9f8e22ab03668ead469cfdfd7e..5b16f2b41805f2ba6da88017184dc7f08da66011 100644 (file)
@@ -92,4 +92,32 @@ describe('HostsComponent', () => {
       expect(spans[0].textContent).toBe(hostname);
     });
   }));
+
+  describe('getEditDisableDesc', () => {
+    it('should return message (not managed by Orchestrator)', () => {
+      component.selection.add({
+        sources: {
+          ceph: true,
+          orchestrator: false
+        }
+      });
+      expect(component.getEditDisableDesc(component.selection)).toBe(
+        'Host editing is disabled because the host is not managed by Orchestrator.'
+      );
+    });
+
+    it('should return undefined (no selection)', () => {
+      expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+    });
+
+    it('should return undefined (managed by Orchestrator)', () => {
+      component.selection.add({
+        sources: {
+          ceph: false,
+          orchestrator: true
+        }
+      });
+      expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+    });
+  });
 });
index 91e9faa7f2cbe67c45d07d5d6b9a808f9f2686e7..50a742c5af912e9fe2034a84ba5d0b8f706221e0 100644 (file)
@@ -73,6 +73,21 @@ export class HostsComponent extends ListWithDetails implements OnInit {
           );
         }
       },
+      {
+        name: this.actionLabels.EDIT,
+        permission: 'update',
+        icon: Icons.edit,
+        click: () => {
+          this.depCheckerService.checkOrchestratorOrModal(
+            this.actionLabels.EDIT,
+            this.i18n('Host'),
+            () => this.editAction()
+          );
+        },
+        disable: (selection: CdTableSelection) =>
+          !selection.hasSingleSelection || !selection.first().sources.orchestrator,
+        disableDesc: this.getEditDisableDesc.bind(this)
+      },
       {
         name: this.actionLabels.DELETE,
         permission: 'delete',
@@ -121,7 +136,59 @@ export class HostsComponent extends ListWithDetails implements OnInit {
     this.selection = selection;
   }
 
-  deleteHostModal() {
+  editAction() {
+    this.hostService.getLabels().subscribe((resp: string[]) => {
+      const host = this.selection.first();
+      const allLabels = resp.map((label) => {
+        return { enabled: true, name: label };
+      });
+      this.modalService.show(FormModalComponent, {
+        initialState: {
+          titleText: this.i18n('Edit Host: {{hostname}}', host),
+          fields: [
+            {
+              type: 'select-badges',
+              name: 'labels',
+              value: host['labels'],
+              label: this.i18n('Labels'),
+              typeConfig: {
+                customBadges: true,
+                options: allLabels,
+                messages: new SelectMessages(
+                  {
+                    empty: this.i18n('There are no labels.'),
+                    filter: this.i18n('Filter or add labels'),
+                    add: this.i18n('Add label')
+                  },
+                  this.i18n
+                )
+              }
+            }
+          ],
+          submitButtonText: this.i18n('Edit Host'),
+          onSubmit: (values: any) => {
+            this.hostService.update(host['hostname'], values.labels).subscribe(() => {
+              this.notificationService.show(
+                NotificationType.success,
+                this.i18n('Updated Host "{{hostname}}"', host)
+              );
+              // Reload the data table content.
+              this.table.refreshBtn();
+            });
+          }
+        }
+      });
+    });
+  }
+
+  getEditDisableDesc(selection: CdTableSelection): string | undefined {
+    if (selection && selection.hasSingleSelection && !selection.first().sources.orchestrator) {
+      return this.i18n('Host editing is disabled because the host is not managed by Orchestrator.');
+    }
+    return undefined;
+  }
+
+  deleteAction() {
     const hostname = this.selection.first().hostname;
     this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
       initialState: {
index 57714dbae6b14d48eb90cc59084e1592deeb68a9..334f5563eeb5f770e8f5f0fe0e9b895970544f00 100644 (file)
@@ -148,6 +148,6 @@ export class TableActionsComponent implements OnInit {
   }
 
   useDisableDesc(action: CdTableAction) {
-    return action.disableDesc && action.disableDesc();
+    return action.disableDesc && action.disableDesc(this.selection);
   }
 }
index ac8dcb61a98d05712921687d93dd8b85bf93e113..9af10625ae65bd3226dfeec3ff4cf6b5cee5660e 100644 (file)
@@ -29,7 +29,7 @@ export class CdTableAction {
    * disabled. The specified message will be shown to the user as a button
    * tooltip.
    */
-  disableDesc?: Function;
+  disableDesc?: (_: CdTableSelection) => string | undefined;
 
   /**
    * Defines if the button can become 'primary' (displayed as button and not