Browse Source

Fix renaming workflow steps losing the initial step or overwriting other steps (#1378)

Co-authored-by: claude[bot] <claude[bot]@users.noreply.github.com>
pull/1389/head
github-actions[bot] 6 days ago
committed by GitHub
parent
commit
dc2928522c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 49
      frontend/src/app/shared/state/workflows.state.spec.ts
  2. 13
      frontend/src/app/shared/state/workflows.state.ts

49
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')

13
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];

Loading…
Cancel
Save