From a92baa8523279f663644837304f1e6c71787a63e Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 23 Jun 2020 12:19:54 +0200 Subject: [PATCH] mgr/dashboard: Bypass current selection when calling CdTableAction::disableDesc(). Signed-off-by: Volker Theile --- .../src/app/ceph/cluster/hosts/hosts.component.spec.ts | 4 ++-- .../src/app/ceph/cluster/hosts/hosts.component.ts | 10 +++------- .../datatable/table-actions/table-actions.component.ts | 2 +- .../frontend/src/app/shared/models/cd-table-action.ts | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) 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 9cc62f48b3da4..591b0f189fd5c 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 @@ -103,7 +103,7 @@ describe('HostsComponent', () => { }); it('should return undefined (no selection)', () => { - expect(component.getEditDisableDesc()).toBeUndefined(); + expect(component.getEditDisableDesc(component.selection)).toBeUndefined(); }); it('should return undefined (managed by Orchestrator)', () => { @@ -113,7 +113,7 @@ describe('HostsComponent', () => { orchestrator: true } }); - expect(component.getEditDisableDesc()).toBeUndefined(); + expect(component.getEditDisableDesc(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 50b04947c0d7a..41594c1f55e79 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 @@ -94,7 +94,7 @@ export class HostsComponent extends ListWithDetails implements OnInit { }, disable: (selection: CdTableSelection) => !selection.hasSingleSelection || !selection.first().sources.orchestrator, - disableDesc: () => this.getEditDisableDesc() + disableDesc: this.getEditDisableDesc.bind(this) }, { name: this.actionLabels.DELETE, @@ -189,12 +189,8 @@ export class HostsComponent extends ListWithDetails implements OnInit { }); } - getEditDisableDesc(): string | undefined { - if ( - this.selection && - this.selection.hasSingleSelection && - !this.selection.first().sources.orchestrator - ) { + 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; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts index 4f34fc574be75..f494ae19f555e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table-actions/table-actions.component.ts @@ -146,6 +146,6 @@ export class TableActionsComponent implements OnInit { } useDisableDesc(action: CdTableAction) { - return action.disableDesc && action.disableDesc(); + return action.disableDesc && action.disableDesc(this.selection); } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts index ac8dcb61a98d0..9af10625ae65b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-action.ts @@ -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 -- 2.39.5