New categories don't got an ID to start with, we will assign it to them

This commit is contained in:
alicia pritchett 2021-10-06 12:54:40 -04:00
parent 392f3d7ef2
commit 95af509383
3 changed files with 18 additions and 17 deletions

View File

@ -33,8 +33,8 @@ export class WorkflowSpecDialogComponent {
label: c.display_name, label: c.display_name,
})); }));
this.api.getWorkflowSpecList().subscribe(wfs => { this.api.getWorkflowSpecList().subscribe(wfs => {
this.specs = wfs.map(w => w.id); this.specs = wfs.map(w => w.id);
this.fields = [ this.fields = [
{ {

View File

@ -283,6 +283,7 @@ describe('WorkflowSpecListComponent', () => {
const _updateWorkflowSpecCategorySpy = spyOn((component as any), '_updateWorkflowSpecCategory').and.stub(); const _updateWorkflowSpecCategorySpy = spyOn((component as any), '_updateWorkflowSpecCategory').and.stub();
component.selectedCat = undefined; component.selectedCat = undefined;
mockWorkflowSpecCategory1.id = null;
(component as any)._upsertWorkflowSpecCategory(mockWorkflowSpecCategory1 as WorkflowSpecCategoryDialogData); (component as any)._upsertWorkflowSpecCategory(mockWorkflowSpecCategory1 as WorkflowSpecCategoryDialogData);
expect(_addWorkflowSpecCategorySpy).toHaveBeenCalled(); expect(_addWorkflowSpecCategorySpy).toHaveBeenCalled();
expect(_updateWorkflowSpecCategorySpy).not.toHaveBeenCalled(); expect(_updateWorkflowSpecCategorySpy).not.toHaveBeenCalled();

View File

@ -32,7 +32,7 @@ import { SettingsService } from '../settings.service';
export interface WorkflowSpecCategoryGroup { export interface WorkflowSpecCategoryGroup {
id: number; id?: number;
display_name: string; display_name: string;
workflow_specs?: WorkflowSpec[]; workflow_specs?: WorkflowSpec[];
display_order: number; display_order: number;
@ -173,7 +173,7 @@ export class WorkflowSpecListComponent implements OnInit {
}, },
}); });
dialogRef.afterClosed().subscribe((data: WorkflowSpecCategoryDialogData) => { dialogRef.afterClosed().subscribe((data: WorkflowSpecCategoryDialogData) => {
if (data && isNumberDefined(data.id) && data.display_name) { if (data && data.display_name) {
this._upsertWorkflowSpecCategory(data); this._upsertWorkflowSpecCategory(data);
} }
}); });
@ -329,21 +329,21 @@ export class WorkflowSpecListComponent implements OnInit {
} }
private _upsertWorkflowSpecCategory(data: WorkflowSpecCategoryDialogData) { private _upsertWorkflowSpecCategory(data: WorkflowSpecCategoryDialogData) {
if (isNumberDefined(data.id) && data.display_name) { if (data.display_name) {
if (isNumberDefined(data.id)) {
// Save old workflow spec id, in case it's changed const newCat: WorkflowSpecCategory = {
const catId = this.selectedCat ? this.selectedCat.id : undefined; id: data.id,
display_name: data.display_name,
const newCat: WorkflowSpecCategory = { display_order: data.display_order,
id: data.id, admin: data.admin,
display_name: data.display_name,
display_order: data.display_order,
admin: data.admin,
}; };
this._updateWorkflowSpecCategory(data.id, newCat);
if (isNumberDefined(catId)) {
this._updateWorkflowSpecCategory(catId, newCat);
} else { } else {
const newCat: WorkflowSpecCategory = {
display_name: data.display_name,
display_order: data.display_order,
admin: data.admin,
};
this._addWorkflowSpecCategory(newCat); this._addWorkflowSpecCategory(newCat);
} }
} }