From: Volker Theile Date: Wed, 24 Jun 2020 10:32:01 +0000 (+0200) Subject: mgr/dashboard: Host delete action should be disabled if not managed by Orchestrator X-Git-Tag: v15.2.9~122^2~107^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=787d625852dda54bdca2fecc0ed9012a19d18f68;p=ceph.git mgr/dashboard: Host delete action should be disabled if not managed by Orchestrator Fixes: https://tracker.ceph.com/issues/46146 Signed-off-by: Volker Theile (cherry picked from commit 4fbe49a793f1bd09a823620414f36a3bbfc426a0) --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts index 05f3d962f0e4..695898c25ae5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts @@ -112,7 +112,7 @@ describe('HostsComponent', () => { }); expect(tableAction.disable(component.selection)).toBeTruthy(); expect(component.getEditDisableDesc(component.selection)).toBe( - 'Host editing is disabled because the host is not managed by Orchestrator.' + 'Host editing is disabled because the selected host is not managed by Orchestrator.' ); }); @@ -132,4 +132,44 @@ describe('HostsComponent', () => { expect(component.getEditDisableDesc(component.selection)).toBeUndefined(); }); }); + + describe('getDeleteDisableDesc', () => { + it('should return message (not managed by Orchestrator)', () => { + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + component.selection.add({ + sources: { + ceph: true, + orchestrator: false + } + }); + expect(component.getDeleteDisableDesc(component.selection)).toBe( + 'Host deletion is disabled because a selected host is not managed by Orchestrator.' + ); + }); + + it('should return undefined (no selection)', () => { + expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined(); + }); + + it('should return undefined (managed by Orchestrator)', () => { + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + component.selection.add({ + sources: { + ceph: false, + orchestrator: true + } + }); + expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined(); + }); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts index 41594c1f55e7..52414bdf3ef0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.ts @@ -107,7 +107,10 @@ export class HostsComponent extends ListWithDetails implements OnInit { () => this.deleteAction() ); }, - disable: () => !this.selection.hasSelection + disable: (selection: CdTableSelection) => + !selection.hasSelection || + !selection.selected.every((selected) => selected.sources.orchestrator), + disableDesc: this.getDeleteDisableDesc.bind(this) } ]; } @@ -191,7 +194,9 @@ export class HostsComponent extends ListWithDetails implements OnInit { 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 this.i18n( + 'Host editing is disabled because the selected host is not managed by Orchestrator.' + ); } return undefined; } @@ -212,6 +217,19 @@ export class HostsComponent extends ListWithDetails implements OnInit { }); } + getDeleteDisableDesc(selection: CdTableSelection): string | undefined { + if ( + selection && + selection.hasSelection && + !selection.selected.every((selected) => selected.sources.orchestrator) + ) { + return this.i18n( + 'Host deletion is disabled because a selected host is not managed by Orchestrator.' + ); + } + return undefined; + } + getHosts(context: CdTableFetchDataContext) { if (this.isLoadingHosts) { return;