From dc2928522c153d800c97a39dbe0015633e3bb963 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:47:26 +0100 Subject: [PATCH] Fix renaming workflow steps losing the initial step or overwriting other steps (#1378) Co-authored-by: claude[bot] --- .../app/shared/state/workflows.state.spec.ts | 49 ++++++++++++++++++- .../src/app/shared/state/workflows.state.ts | 13 ++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/shared/state/workflows.state.spec.ts b/frontend/src/app/shared/state/workflows.state.spec.ts index ba1f46c95..d4ed91721 100644 --- a/frontend/src/app/shared/state/workflows.state.spec.ts +++ b/frontend/src/app/shared/state/workflows.state.spec.ts @@ -252,7 +252,7 @@ describe('WorkflowView', () => { .renameStep('1', 'a'); expect(workflow.toUpdate().toJSON()).toEqual({ - initial: '1', + initial: 'a', steps: { a: { transitions: { @@ -272,6 +272,53 @@ describe('WorkflowView', () => { }); }); + it('should not change initial step if other step renamed', () => { + const workflow = new WorkflowView(dto) + .setStep('1') + .setStep('2') + .renameStep('2', 'b'); + + expect(workflow.dto.initial).toEqual('1'); + }); + + it('should return same workflow if step renamed to existing step', () => { + const workflow = new WorkflowView(dto) + .setStep('1', { color: '#00ff00' }) + .setStep('2', { color: '#ff0000' }); + + const updated = workflow.renameStep('1', '2'); + + expect(updated).toBe(workflow); + }); + + it('should return same workflow if step renamed to locked step', () => { + const workflow = new WorkflowView(dto) + .setStep('1'); + + const updated = workflow.renameStep('1', 'Published'); + + expect(updated).toBe(workflow); + }); + + it('should return same workflow if locked step renamed', () => { + const workflow = new WorkflowView(dto) + .setStep('1') + .setStep('Published'); + + const updated = workflow.renameStep('Published', '2'); + + expect(updated).toBe(workflow); + }); + + it('should return same workflow if step renamed to empty name', () => { + const workflow = new WorkflowView(dto) + .setStep('1'); + + const updated = workflow.renameStep('1', ''); + + expect(updated).toBe(workflow); + }); + it('should add transitions to workflow', () => { const workflow = new WorkflowView(dto) .setStep('1') diff --git a/frontend/src/app/shared/state/workflows.state.ts b/frontend/src/app/shared/state/workflows.state.ts index 0fe7935e8..323b1687c 100644 --- a/frontend/src/app/shared/state/workflows.state.ts +++ b/frontend/src/app/shared/state/workflows.state.ts @@ -303,7 +303,12 @@ export class WorkflowView { } public renameStep(name: string, newName: string) { - if (!this.dto.steps[name] || name === newName) { + if (!this.dto.steps[name] || name === newName || !newName) { + return this; + } + + // Renaming to an existing step would silently overwrite it. + if (this.dto.steps[newName] || isLocked(name) || isLocked(newName)) { return this; } @@ -314,6 +319,10 @@ export class WorkflowView { renameInObj(step.transitions, name, newName); } + if (clone.initial === name) { + clone.initial = newName; + } + return true; }); } @@ -332,7 +341,7 @@ export class WorkflowView { } function renameInObj(target: any, name: string, newName: string) { - const existing = target[name]; + const existing = target?.[name]; if (existing) { target[newName] = existing; delete target[name];