Skip to content

Commit

Permalink
fix: show confirm dialog only if content has been changed for workflo…
Browse files Browse the repository at this point in the history
…w step (#1167)
  • Loading branch information
ivyjeong13 authored Jan 9, 2025
1 parent 0cb644c commit 8d2de63
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions ui/admin/app/components/workflow/steps/StepBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,26 @@ export function StepBase({

const { intercept, dialogProps } = useConfirmationDialog();

const handleDelete = () =>
intercept(() => onDelete(), DeleteStepDialogProps);
const handleDelete = () => {
if (hasContent()) {
intercept(() => onDelete(), DeleteStepDialogProps);
} else {
onDelete();
}
};

const handleUpdateType = (newType: StepType) => {
if (newType !== type) {
if (newType === type) {
return;
}

if (hasContent()) {
intercept(
() => onUpdate(getDefaultStep(newType)),
UpdateStepTypeDialogProps
);
} else {
onUpdate(getDefaultStep(newType));
}
};
return (
Expand Down Expand Up @@ -155,4 +166,22 @@ export function StepBase({
onChange: (value: string) => onUpdate({ ...step, step: value }),
};
}

function hasContent() {
const { workflows, tools } = step;
if (workflows.length || tools.length) {
return true;
}
if (type === "if" && step.if) {
return (
step.if.condition.length ||
step.if.else.length ||
step.if.steps.length
);
} else if (type === "while" && step.while) {
return step.while.condition.length || step.while.steps.length;
}

return step.step?.length;
}
}

0 comments on commit 8d2de63

Please sign in to comment.