From 9bd80e95edc8a4a1de0cc1d3025cc1daad0651e7 Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Tue, 7 Jul 2020 13:39:08 +0100 Subject: [PATCH] mgr/dashboard: Allow to edit iSCSI target with active session Fixes: https://tracker.ceph.com/issues/46383 Signed-off-by: Ricardo Marques (cherry picked from commit df6163e1369703117ac683bcbd5056e1543f4d06) --- .../iscsi-target-list.component.spec.ts | 97 +++++++++++++++++++ .../iscsi-target-list.component.ts | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts index 50d636febe5c..16ff57abd231 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.spec.ts @@ -16,6 +16,7 @@ import { } from '../../../../testing/unit-test-helper'; import { IscsiService } from '../../../shared/api/iscsi.service'; import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component'; +import { CdTableAction } from '../../../shared/models/cd-table-action'; import { ExecutingTask } from '../../../shared/models/executing-task'; import { SummaryService } from '../../../shared/services/summary.service'; import { TaskListService } from '../../../shared/services/task-list.service'; @@ -172,6 +173,102 @@ describe('IscsiTargetListComponent', () => { }); }); + describe('handling of actions', () => { + beforeEach(() => { + fixture.detectChanges(); + }); + + let action: CdTableAction; + + const getAction = (name: string): CdTableAction => { + return component.tableActions.find((tableAction) => tableAction.name === name); + }; + + describe('edit', () => { + beforeEach(() => { + action = getAction('Edit'); + }); + + it('should be disabled if no gateways', () => { + component.selection.selected = [ + { + id: '-1' + } + ]; + expect(action.disable(undefined)).toBeTruthy(); + expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)'); + }); + + it('should be enabled if active sessions', () => { + component.selection.selected = [ + { + id: '-1', + info: { + num_sessions: 1 + } + } + ]; + expect(action.disable(undefined)).toBeFalsy(); + expect(action.disableDesc(undefined)).toBeUndefined(); + }); + + it('should be enabled if no active sessions', () => { + component.selection.selected = [ + { + id: '-1', + info: { + num_sessions: 0 + } + } + ]; + expect(action.disable(undefined)).toBeFalsy(); + expect(action.disableDesc(undefined)).toBeUndefined(); + }); + }); + + describe('delete', () => { + beforeEach(() => { + action = getAction('Delete'); + }); + + it('should be disabled if no gateways', () => { + component.selection.selected = [ + { + id: '-1' + } + ]; + expect(action.disable(undefined)).toBeTruthy(); + expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)'); + }); + + it('should be disabled if active sessions', () => { + component.selection.selected = [ + { + id: '-1', + info: { + num_sessions: 1 + } + } + ]; + expect(action.disable(undefined)).toBeTruthy(); + expect(action.disableDesc(undefined)).toBe('Target has active sessions'); + }); + + it('should be enabled if no active sessions', () => { + component.selection.selected = [ + { + id: '-1', + info: { + num_sessions: 0 + } + } + ]; + expect(action.disable(undefined)).toBeFalsy(); + expect(action.disableDesc(undefined)).toBeUndefined(); + }); + }); + }); + it('should test all TableActions combinations', () => { const permissionHelper: PermissionHelper = new PermissionHelper(component.permission); const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions( diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts index 40265dd6bc0e..07976f2c2195 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts @@ -85,7 +85,7 @@ export class IscsiTargetListComponent extends ListWithDetails implements OnInit, icon: Icons.edit, routerLink: () => `/block/iscsi/targets/edit/${this.selection.first().target_iqn}`, name: this.actionLabels.EDIT, - disable: () => !this.selection.first() || !_.isUndefined(this.getDeleteDisableDesc()), + disable: () => !this.selection.first() || !_.isUndefined(this.getEditDisableDesc()), disableDesc: () => this.getEditDisableDesc() }, { -- 2.47.3