diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.ts b/src/app/workflow-spec-list/workflow-spec-list.component.ts index 23ea5c7..45cf082 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.ts @@ -221,7 +221,7 @@ export class WorkflowSpecListComponent implements OnInit { editCategoryDisplayOrder(catId: number, direction: string) { this.api.reorderWorkflowCategory(catId, direction).subscribe(cat_change => { this.workflowSpecsByCategory = this.workflowSpecsByCategory.map(cat => { - let new_cat = cat_change.find(i2 => i2.id === cat.id); + let new_cat = this.ensure(cat_change.find(i2 => i2.id === cat.id)); cat.display_order = new_cat.display_order; return cat; }); @@ -229,6 +229,15 @@ export class WorkflowSpecListComponent implements OnInit { }); } + // ensure that in array.find, we find what we are expecting. (Ensures TS type safety) + ensure(argument: T | undefined | null, message: string = 'Spec not found!'): T { + if (argument === undefined || argument === null) { + throw new TypeError(message); + } + return argument; + } + + editSpecDisplayOrder(cat: WorkflowSpecCategoryGroup, specId: string, direction: string) { this.api.reorderWorkflowSpecification(specId, direction).subscribe(wfs => { cat.workflow_specs= wfs;