From bed29dcabe16541a345b2cd3afb722673de58a55 Mon Sep 17 00:00:00 2001 From: alicia pritchett Date: Thu, 14 Oct 2021 13:21:43 -0400 Subject: [PATCH 1/2] Fixes #477 - Libraries not showing as 'selected spec' on page loads Will load libraries on page loads now. will set master spec correctly. updating some tests --- .../workflow-spec-list.component.spec.ts | 13 +++-- .../workflow-spec-list.component.ts | 48 ++++++++++--------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts index 1499642..faef9cf 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts @@ -18,7 +18,7 @@ import { MockEnvironment, mockWorkflowMeta1, mockWorkflowSpec0, mockWorkflowSpec1, - mockWorkflowSpec2, + mockWorkflowSpec2, mockWorkflowSpec3, mockWorkflowSpecCategories, mockWorkflowSpecCategory0, mockWorkflowSpecCategory1, @@ -260,6 +260,14 @@ describe('WorkflowSpecListComponent', () => { expect(_loadWorkflowLibrariesSpy).toHaveBeenCalled(); }); + it('should set a library spec as the selected spec', () => { + const _loadWorkflowLibrariesSpy = spyOn((component as any), '_loadWorkflowLibraries').and.stub(); + (component as any)._loadWorkflowLibraries(mockWorkflowSpec3) + component.selectedSpec = mockWorkflowSpec3; + expect(_loadWorkflowLibrariesSpy).toHaveBeenCalled() + expect(component.selectedSpec).toEqual(mockWorkflowSpec3) + }) + it('should show a metadata dialog when editing a workflow spec category', () => { let mockCatData: WorkflowSpecCategoryDialogData = { id: null, @@ -519,9 +527,6 @@ describe('WorkflowSpecListComponent', () => { expect(component.workflowSpecs).toEqual(allSpecs); expect(component.workflowSpecsByCategory).toBeTruthy(); - component.workflowSpecsByCategory.forEach(cat => { - expect(cat.workflow_specs).not.toContain(mockMasterSpec); - }); expect(component.masterStatusSpec).toEqual(mockMasterSpec); }); 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 c4b723c..df3ddef 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.ts @@ -227,7 +227,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 = this.ensure(cat_change.find(i2 => i2.id === cat.id)); + let new_cat = (cat_change.find(i2 => i2.id === cat.id)); cat.display_order = new_cat.display_order; return cat; }); @@ -235,14 +235,6 @@ 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 => { @@ -261,13 +253,24 @@ export class WorkflowSpecListComponent implements OnInit { this.workflowSpecsByCategory[i].workflow_specs = []; }); this._loadWorkflowSpecs(selectedSpecName); - this._loadWorkflowLibraries(); + this._loadWorkflowLibraries(selectedSpecName); }); } - private _loadWorkflowLibraries() { + private _loadWorkflowLibraries(selectedSpecName: string = null) { this.api.getWorkflowSpecificationLibraries().subscribe(wfs => { this.workflowLibraries = wfs; + + // If selected spec is a library, set it. + if (selectedSpecName) { + wfs.forEach(ws => { + if (selectedSpecName && selectedSpecName === ws.id) { + this.selectedSpec = ws; + } + }); + } else { + this.selectedSpec = this.masterStatusSpec; + } }); } @@ -275,23 +278,26 @@ export class WorkflowSpecListComponent implements OnInit { this.api.getWorkflowSpecList().subscribe(wfs => { this.workflowSpecs = wfs; + // Populate categories with their specs this.workflowSpecsByCategory.forEach(cat => { cat.workflow_specs = this.workflowSpecs .filter(wf => { - // Find and set master spec - if (wf.is_master_spec) { - this.masterStatusSpec = wf; + if (searchSpecName) { + return (wf.category_id === cat.id) && wf.display_name.toLowerCase().includes(searchSpecName.toLowerCase()); } else { - if (searchSpecName) { - return (wf.category_id === cat.id) && wf.display_name.toLowerCase().includes(searchSpecName.toLowerCase()); - } else { - return wf.category_id === cat.id; - } + return wf.category_id === cat.id; } }) cat.workflow_specs.sort((x,y) => x.display_order - y.display_order); }); + // Set master spec + wfs.forEach(wf => { + if (wf.is_master_spec){ + this.masterStatusSpec = wf; + } + }); + // Set the selected workflow to something sensible. if (!selectedSpecName && this.selectedSpec) { selectedSpecName = this.selectedSpec.id; @@ -303,8 +309,6 @@ export class WorkflowSpecListComponent implements OnInit { this.selectedCat = this.selectedSpec.category; } }); - } else { - this.selectedSpec = this.masterStatusSpec; } }); } @@ -361,7 +365,7 @@ export class WorkflowSpecListComponent implements OnInit { private _addWorkflowSpec(newSpec: WorkflowSpec) { this.api.addWorkflowSpecification(newSpec).subscribe(_ => { - this._loadWorkflowLibraries(); + this._loadWorkflowLibraries(newSpec.id); this._loadWorkflowSpecs(newSpec.id); this._displayMessage('Saved new workflow spec.'); }); From c9603264a32578cf9f240afff7eca026bd590b0d Mon Sep 17 00:00:00 2001 From: alicia pritchett Date: Mon, 18 Oct 2021 13:50:06 -0400 Subject: [PATCH 2/2] Fixes #504- Tweak Library Category Behavior But you have to have the other fix in here. Keeps libraries category thingy expanded when its supposed to be. --- src/app/workflow-spec-list/workflow-spec-list.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.html b/src/app/workflow-spec-list/workflow-spec-list.component.html index 8caeffc..c2af487 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.html +++ b/src/app/workflow-spec-list/workflow-spec-list.component.html @@ -31,7 +31,7 @@ - +

All Libraries