ensure() array.find

Makes sure we find an instance of the WFS id we want, when we are looking to add/delete it. (This gets us past karma tests sometimes bailing out)
This commit is contained in:
alicia pritchett 2021-09-29 11:15:00 -04:00
parent 35785caa2e
commit 76c55e0a91
1 changed files with 10 additions and 1 deletions

View File

@ -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<T>(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;