}
});
});
+
+ const getActionDisable = (name: string) =>
+ component.tableActions.find((o) => o.name === name).disable;
+
+ const testActions = (selection: any, expected: string | boolean) => {
+ expect(getActionDisable('Edit')(selection)).toBe(expected);
+ expect(getActionDisable('Delete')(selection)).toBe(expected);
+ expect(getActionDisable('Copy')(selection)).toBe(expected);
+ expect(getActionDisable('Flatten')(selection)).toBeTruthy();
+ expect(getActionDisable('Move to Trash')(selection)).toBe(expected);
+ };
+
+ it('should test TableActions with valid/invalid image name', () => {
+ component.selection.selected = [
+ {
+ name: 'foobar',
+ pool_name: 'rbd',
+ snapshots: []
+ }
+ ];
+ testActions(component.selection, false);
+
+ component.selection.selected = [
+ {
+ name: 'foo/bar',
+ pool_name: 'rbd',
+ snapshots: []
+ }
+ ];
+ testActions(
+ component.selection,
+ `This RBD image has an invalid name and can't be managed by ceph.`
+ );
+ });
});
permission: 'update',
icon: Icons.edit,
routerLink: () => this.urlBuilder.getEdit(getImageUri()),
- name: this.actionLabels.EDIT
+ name: this.actionLabels.EDIT,
+ disable: this.getInvalidNameDisable
};
const deleteAction: CdTableAction = {
permission: 'delete',
permission: 'create',
canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
disable: (selection: CdTableSelection) =>
- !selection.hasSingleSelection || selection.first().cdExecuting,
+ this.getInvalidNameDisable(selection) || !!selection.first().cdExecuting,
icon: Icons.copy,
routerLink: () => `/block/rbd/copy/${getImageUri()}`,
name: this.actionLabels.COPY
const flattenAction: CdTableAction = {
permission: 'update',
disable: (selection: CdTableSelection) =>
- !selection.hasSingleSelection || selection.first().cdExecuting || !selection.first().parent,
+ this.getInvalidNameDisable(selection) ||
+ selection.first().cdExecuting ||
+ !selection.first().parent,
icon: Icons.flatten,
click: () => this.flattenRbdModal(),
name: this.actionLabels.FLATTEN
click: () => this.trashRbdModal(),
name: this.actionLabels.TRASH,
disable: (selection: CdTableSelection) =>
- !selection.first() ||
- !selection.hasSingleSelection ||
+ this.getInvalidNameDisable(selection) ||
selection.first().image_format === RBDImageFormat.V1
};
this.tableActions = [
return $localize`This RBD has cloned snapshots. Please delete related RBDs before deleting this RBD.`;
}
- return (
- !selection.first() ||
- !selection.hasSingleSelection ||
- this.hasClonedSnapshots(selection.first())
- );
+ return this.getInvalidNameDisable(selection) || this.hasClonedSnapshots(selection.first());
+ }
+
+ getInvalidNameDisable(selection: CdTableSelection): string | boolean {
+ const first = selection.first();
+
+ if (first?.name?.match(/[@/]/)) {
+ return $localize`This RBD image has an invalid name and can't be managed by ceph.`;
+ }
+
+ return !selection.first() || !selection.hasSingleSelection;
}
}