From 38aa28813305b7b868b4f070978870cf6628ec3b Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 16 Sep 2024 10:48:18 -0700 Subject: [PATCH] Feature: clone workflows --- src-ui/messages.xlf | 27 ++++++++++++------- .../manage/workflows/workflows.component.html | 3 +++ .../workflows/workflows.component.spec.ts | 16 ++++++++++- .../manage/workflows/workflows.component.ts | 26 +++++++++++++++--- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 18ba85ce4..e51cb5e7b 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -1549,7 +1549,7 @@ src/app/components/manage/workflows/workflows.component.html - 38 + 41 @@ -2215,7 +2215,7 @@ src/app/components/manage/workflows/workflows.component.ts - 97 + 115 @@ -2554,7 +2554,7 @@ src/app/components/manage/workflows/workflows.component.ts - 99 + 117 @@ -7817,53 +7817,60 @@ 30 + + Clone + + src/app/components/manage/workflows/workflows.component.html + 38 + + No workflows defined. src/app/components/manage/workflows/workflows.component.html - 46 + 49 Saved workflow "". src/app/components/manage/workflows/workflows.component.ts - 79 + 78 Error saving workflow. src/app/components/manage/workflows/workflows.component.ts - 87 + 86 Confirm delete workflow src/app/components/manage/workflows/workflows.component.ts - 95 + 113 This operation will permanently delete this workflow. src/app/components/manage/workflows/workflows.component.ts - 96 + 114 Deleted workflow src/app/components/manage/workflows/workflows.component.ts - 105 + 123 Error deleting workflow. src/app/components/manage/workflows/workflows.component.ts - 110 + 128 diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.html b/src-ui/src/app/components/manage/workflows/workflows.component.html index d398b95b1..c16ffc861 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.html +++ b/src-ui/src/app/components/manage/workflows/workflows.component.html @@ -34,6 +34,9 @@ + diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts b/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts index 5a73b07b0..5fdf691d7 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts +++ b/src-ui/src/app/components/manage/workflows/workflows.component.spec.ts @@ -26,6 +26,7 @@ import { import { WorkflowActionType } from 'src/app/data/workflow-action' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' +import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component' const workflows: Workflow[] = [ { @@ -173,6 +174,19 @@ describe('WorkflowsComponent', () => { expect(reloadSpy).toHaveBeenCalled() }) + it('should support clone', () => { + let modal: NgbModalRef + modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1])) + + const cloneButton = fixture.debugElement.queryAll(By.css('button'))[4] + cloneButton.triggerEventHandler('click') + + expect(modal).not.toBeUndefined() + const editDialog = modal.componentInstance as WorkflowEditDialogComponent + expect(editDialog.object.name).toEqual(workflows[0].name + ' (copy)') + expect(editDialog.dialogMode).toEqual(EditDialogMode.CREATE) + }) + it('should support delete, show notification on error / success', () => { let modal: NgbModalRef modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1])) @@ -180,7 +194,7 @@ describe('WorkflowsComponent', () => { const deleteSpy = jest.spyOn(workflowService, 'delete') const reloadSpy = jest.spyOn(component, 'reload') - const deleteButton = fixture.debugElement.queryAll(By.css('button'))[4] + const deleteButton = fixture.debugElement.queryAll(By.css('button'))[5] deleteButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() diff --git a/src-ui/src/app/components/manage/workflows/workflows.component.ts b/src-ui/src/app/components/manage/workflows/workflows.component.ts index a80f03577..757d3c75f 100644 --- a/src-ui/src/app/components/manage/workflows/workflows.component.ts +++ b/src-ui/src/app/components/manage/workflows/workflows.component.ts @@ -57,14 +57,13 @@ export class WorkflowsComponent .join(', ') } - editWorkflow(workflow: Workflow) { + editWorkflow(workflow: Workflow, clone: boolean = false) { const modal = this.modalService.open(WorkflowEditDialogComponent, { backdrop: 'static', size: 'xl', }) - modal.componentInstance.dialogMode = workflow - ? EditDialogMode.EDIT - : EditDialogMode.CREATE + modal.componentInstance.dialogMode = + workflow && !clone ? EditDialogMode.EDIT : EditDialogMode.CREATE if (workflow) { // quick "deep" clone so original doesn't get modified const clone = Object.assign({}, workflow) @@ -88,6 +87,25 @@ export class WorkflowsComponent }) } + cloneWorkflow(workflow: Workflow) { + const clone = Object.assign({}, workflow) + clone.id = null + clone.name = `${workflow.name} (copy)` + clone.actions = [ + ...workflow.actions.map((a) => { + a.id = null + return a + }), + ] + clone.triggers = [ + ...workflow.triggers.map((t) => { + t.id = null + return t + }), + ] + this.editWorkflow(clone, true) + } + deleteWorkflow(workflow: Workflow) { const modal = this.modalService.open(ConfirmDialogComponent, { backdrop: 'static',