id: '-1'
}
];
- expect(action.disable(undefined)).toBeTruthy();
- expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)');
+ expect(action.disable(undefined)).toBe('Unavailable gateway(s)');
});
it('should be enabled if active sessions', () => {
}
];
expect(action.disable(undefined)).toBeFalsy();
- expect(action.disableDesc(undefined)).toBeUndefined();
});
it('should be enabled if no active sessions', () => {
}
];
expect(action.disable(undefined)).toBeFalsy();
- expect(action.disableDesc(undefined)).toBeUndefined();
});
});
id: '-1'
}
];
- expect(action.disable(undefined)).toBeTruthy();
- expect(action.disableDesc(undefined)).toBe('Unavailable gateway(s)');
+ expect(action.disable(undefined)).toBe('Unavailable gateway(s)');
});
it('should be disabled if active sessions', () => {
}
}
];
- expect(action.disable(undefined)).toBeTruthy();
- expect(action.disableDesc(undefined)).toBe('Target has active sessions');
+ expect(action.disable(undefined)).toBe('Target has active sessions');
});
it('should be enabled if no active sessions', () => {
}
];
expect(action.disable(undefined)).toBeFalsy();
- expect(action.disableDesc(undefined)).toBeUndefined();
});
});
});
icon: Icons.edit,
routerLink: () => `/block/iscsi/targets/edit/${this.selection.first().target_iqn}`,
name: this.actionLabels.EDIT,
- disable: () => !this.selection.first() || !_.isUndefined(this.getEditDisableDesc()),
- disableDesc: () => this.getEditDisableDesc()
+ disable: () => this.getEditDisableDesc()
},
{
permission: 'delete',
icon: Icons.destroy,
click: () => this.deleteIscsiTargetModal(),
name: this.actionLabels.DELETE,
- disable: () => !this.selection.first() || !_.isUndefined(this.getDeleteDisableDesc()),
- disableDesc: () => this.getDeleteDisableDesc()
+ disable: () => this.getDeleteDisableDesc()
}
];
}
}
}
- getEditDisableDesc(): string | undefined {
+ getEditDisableDesc(): string | boolean {
const first = this.selection.first();
- if (first && first.cdExecuting) {
+
+ if (first && first?.cdExecuting) {
return first.cdExecuting;
}
- if (first && _.isUndefined(first['info'])) {
+
+ if (first && _.isUndefined(first?.['info'])) {
return $localize`Unavailable gateway(s)`;
}
- return undefined;
+ return !first;
}
- getDeleteDisableDesc(): string | undefined {
+ getDeleteDisableDesc(): string | boolean {
const first = this.selection.first();
- if (first && first.cdExecuting) {
+
+ if (first?.cdExecuting) {
return first.cdExecuting;
}
- if (first && _.isUndefined(first['info'])) {
+
+ if (first && _.isUndefined(first?.['info'])) {
return $localize`Unavailable gateway(s)`;
}
- if (first && first['info'] && first['info']['num_sessions']) {
+
+ if (first && first?.['info']?.['num_sessions']) {
return $localize`Target has active sessions`;
}
- return undefined;
+ return !first;
}
prepareResponse(resp: any): any[] {
}
]
});
- expect(component.getDeleteDisableDesc()).toBe(
+ expect(component.getDeleteDisableDesc(component.selection)).toBe(
'This RBD has cloned snapshots. Please delete related RBDs before deleting this RBD.'
);
});
icon: Icons.destroy,
click: () => this.deleteRbdModal(),
name: this.actionLabels.DELETE,
- disable: (selection: CdTableSelection) =>
- !this.selection.first() ||
- !this.selection.hasSingleSelection ||
- this.hasClonedSnapshots(selection.first()),
- disableDesc: () => this.getDeleteDisableDesc()
+ disable: (selection: CdTableSelection) => this.getDeleteDisableDesc(selection)
};
const copyAction: CdTableAction = {
permission: 'create',
}, []);
}
- getDeleteDisableDesc(): string {
- const first = this.selection.first();
+ getDeleteDisableDesc(selection: CdTableSelection): string | boolean {
+ const first = selection.first();
+
if (first && this.hasClonedSnapshots(first)) {
return $localize`This RBD has cloned snapshots. Please delete related RBDs before deleting this RBD.`;
}
- return '';
+ return (
+ !selection.first() ||
+ !selection.hasSingleSelection ||
+ this.hasClonedSnapshots(selection.first())
+ );
}
}
icon: Icons.destroy,
click: () => this.deleteModal(),
name: this.actionLabels.DELETE,
- disable: () => !this.selection.first() || !_.isUndefined(this.getDeleteDisableDesc()),
- disableDesc: () => this.getDeleteDisableDesc()
+ disable: () => this.getDeleteDisableDesc()
};
this.tableActions = [createAction, deleteAction];
}
});
}
- getDeleteDisableDesc(): string | undefined {
+ getDeleteDisableDesc(): string | boolean {
const first = this.selection.first();
- if (first) {
- if (first.num_images > 0) {
- return $localize`Namespace contains images`;
- }
+
+ if (first?.num_images > 0) {
+ return $localize`Namespace contains images`;
}
- return undefined;
+ return !this.selection?.first();
}
}
this.clone = {
permission: 'create',
canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
- disable: (selection: CdTableSelection) =>
- !selection.hasSingleSelection ||
- selection.first().cdExecuting ||
- !_.isUndefined(this.getCloneDisableDesc(featuresName)),
- disableDesc: () => this.getCloneDisableDesc(featuresName),
+ disable: (selection: CdTableSelection) => this.getCloneDisableDesc(selection, featuresName),
icon: Icons.clone,
name: actionLabels.CLONE
};
];
}
- getCloneDisableDesc(featuresName: string[]): string | undefined {
- if (!featuresName?.includes('layering')) {
- return $localize`Parent image must support Layering`;
+ getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
+ if (selection.hasSingleSelection && !selection.first().cdExecuting) {
+ if (!featuresName?.includes('layering')) {
+ return $localize`Parent image must support Layering`;
+ }
+
+ return false;
}
- return undefined;
+ return true;
}
}
);
});
- it('should disable button and return undefined (no selection)', () => {
+ it('should disable button and return true (no selection)', () => {
expect(tableAction.disable(component.selection)).toBeTruthy();
- expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+ expect(component.getEditDisableDesc(component.selection)).toBeTruthy();
});
- it('should enable button and return undefined (managed by Orchestrator)', () => {
+ it('should enable button and return false (managed by Orchestrator)', () => {
component.selection.add({
sources: {
ceph: false,
}
});
expect(tableAction.disable(component.selection)).toBeFalsy();
- expect(component.getEditDisableDesc(component.selection)).toBeUndefined();
+ expect(component.getEditDisableDesc(component.selection)).toBeFalsy();
});
});
);
});
- it('should return undefined (no selection)', () => {
- expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined();
+ it('should return true (no selection)', () => {
+ expect(component.getDeleteDisableDesc(component.selection)).toBeTruthy();
});
- it('should return undefined (managed by Orchestrator)', () => {
+ it('should return false (managed by Orchestrator)', () => {
component.selection.add({
sources: {
ceph: false,
orchestrator: true
}
});
- expect(component.getDeleteDisableDesc(component.selection)).toBeUndefined();
+ expect(component.getDeleteDisableDesc(component.selection)).toBeFalsy();
});
});
});
() => this.editAction()
);
},
- disable: (selection: CdTableSelection) =>
- !selection.hasSingleSelection || !selection.first().sources.orchestrator,
- disableDesc: this.getEditDisableDesc.bind(this)
+ disable: this.getEditDisableDesc.bind(this)
},
{
name: this.actionLabels.DELETE,
() => this.deleteAction()
);
},
- disable: (selection: CdTableSelection) =>
- !selection.hasSelection ||
- !selection.selected.every((selected) => selected.sources.orchestrator),
- disableDesc: this.getDeleteDisableDesc.bind(this)
+ disable: this.getDeleteDisableDesc.bind(this)
}
];
}
});
}
- getEditDisableDesc(selection: CdTableSelection): string | undefined {
- if (selection && selection.hasSingleSelection && !selection.first().sources.orchestrator) {
- return $localize`Host editing is disabled because the selected host is not managed by Orchestrator.`;
+ getEditDisableDesc(selection: CdTableSelection): boolean | string {
+ if (selection?.hasSingleSelection) {
+ if (!selection?.first().sources.orchestrator) {
+ return $localize`Host editing is disabled because the selected host is not managed by Orchestrator.`;
+ }
+
+ return false;
}
- return undefined;
+
+ return true;
}
deleteAction() {
});
}
- getDeleteDisableDesc(selection: CdTableSelection): string | undefined {
- if (
- selection &&
- selection.hasSelection &&
- !selection.selected.every((selected) => selected.sources.orchestrator)
- ) {
- return $localize`Host deletion is disabled because a selected host is not managed by Orchestrator.`;
+ getDeleteDisableDesc(selection: CdTableSelection): boolean | string {
+ if (selection?.hasSelection) {
+ if (!selection.selected.every((selected) => selected.sources.orchestrator)) {
+ return $localize`Host deletion is disabled because a selected host is not managed by Orchestrator.`;
+ }
+
+ return false;
}
- return undefined;
+
+ return true;
}
getHosts(context: CdTableFetchDataContext) {
name: $localize`Disable`,
permission: 'update',
click: () => this.updateModuleState(),
- disable: () => this.isTableActionDisabled('disabled'),
- disableDesc: () => this.getTableActionDisabledDesc(),
+ disable: () => () => this.getTableActionDisabledDesc(),
icon: Icons.stop
}
];
}
}
- getTableActionDisabledDesc(): string | undefined {
- if (this.selection.hasSelection) {
- const selected = this.selection.first();
- if (selected.always_on) {
- return $localize`This Manager module is always on.`;
- }
+ getTableActionDisabledDesc(): string | boolean {
+ if (this.selection.first().always_on) {
+ return $localize`This Manager module is always on.`;
}
- return undefined;
+ return this.isTableActionDisabled('disabled');
}
/**
});
describe('getDisableDesc', () => {
+ beforeEach(() => {
+ component.selection.selected = [{ pool_name: 'foo' }];
+ });
+
it('should return message if mon_allow_pool_delete flag is set to false', () => {
component.monAllowPoolDelete = false;
expect(component.getDisableDesc()).toBe(
);
});
- it('should return undefined if mon_allow_pool_delete flag is set to true', () => {
+ it('should return false if mon_allow_pool_delete flag is set to true', () => {
component.monAllowPoolDelete = true;
- expect(component.getDisableDesc()).toBeUndefined();
+ expect(component.getDisableDesc()).toBeFalsy();
});
});
});
icon: Icons.destroy,
click: () => this.deletePoolModal(),
name: this.actionLabels.DELETE,
- disable: () => !this.selection.first() || !this.monAllowPoolDelete,
- disableDesc: () => this.getDisableDesc()
+ disable: this.getDisableDesc.bind(this)
}
];
}
}
- getDisableDesc(): string | undefined {
- if (!this.monAllowPoolDelete) {
- return $localize`Pool deletion is disabled by the mon_allow_pool_delete configuration setting.`;
+ getDisableDesc(): boolean | string {
+ if (this.selection?.hasSelection) {
+ if (!this.monAllowPoolDelete) {
+ return $localize`Pool deletion is disabled by the mon_allow_pool_delete configuration setting.`;
+ }
+
+ return false;
}
- return undefined;
+ return true;
}
setExpandedRow(expandedRow: any) {
});
describe('useDisableDesc', () => {
- it('should return a description if disableDesc is set for action', () => {
+ it('should return a description if disable method returns a string', () => {
const deleteWithDescAction: CdTableAction = {
permission: 'delete',
icon: 'fa-times',
canBePrimary: (selection: CdTableSelection) => selection.hasSelection,
- disableDesc: () => {
+ disable: () => {
return 'Delete action disabled description';
},
name: 'DeleteDesc'
);
});
- it('should return no description if disableDesc is not set for action', () => {
+ it('should return no description if disable does not return string', () => {
expect(component.useDisableDesc(deleteAction)).toBeUndefined();
});
});
}
useDisableDesc(action: CdTableAction) {
- return action.disableDesc && action.disableDesc(this.selection);
+ if (action.disable) {
+ const result = action.disable(this.selection);
+ return _.isString(result) ? result : undefined;
+ }
+
+ return undefined;
}
}
// The font awesome icon that will be used
icon: string;
- // You can define the condition to disable the action.
- // By default all 'update' and 'delete' actions will only be enabled
- // if one selection is made and no task is running on the selected item.
- disable?: (_: CdTableSelection) => boolean;
-
/**
+ * You can define the condition to disable the action.
+ * By default all 'update' and 'delete' actions will only be enabled
+ * if one selection is made and no task is running on the selected item.`
+ *
* In some cases you might want to give the user a hint why a button is
- * disabled. The specified message will be shown to the user as a button
- * tooltip.
- */
- disableDesc?: (_: CdTableSelection) => string | undefined;
+ * disabled. This is achieved by returning a string.
+ * */
+ disable?: (_: CdTableSelection) => boolean | string;
/**
* Defines if the button can become 'primary' (displayed as button and not