feat: allow workflow step level adjustment
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-04-21 19:48:04 +08:00
parent 396bbf9d9b
commit 1103ff957f

View File

@ -2812,6 +2812,24 @@ export function AgentWorkflowSettingsClient({
});
};
const handlePromoteWorkflowStep = (stepKey: string, parentStepKey: string | null) => {
if (!parentStepKey) {
toast.error("一级模块不能继续升一级");
return;
}
handleMoveWorkflowStep(stepKey, parentStepKey, "after");
};
const handleIndentWorkflowStep = (stepKey: string, previousSiblingStepKey: string | null) => {
if (!previousSiblingStepKey) {
toast.error("当前模块前面没有可作为父级的同级模块");
return;
}
handleMoveWorkflowStep(stepKey, previousSiblingStepKey, "inside");
};
const handleWorkflowStepDragStart = (
event: DragEvent<HTMLElement>,
stepKey: string
@ -4068,7 +4086,9 @@ export function AgentWorkflowSettingsClient({
step: AgentWorkflowStepUiConfig,
depth: number,
indexPath: number[],
siblingCount = 0
siblingCount = 0,
parentStepKey: string | null = null,
previousSiblingStepKey: string | null = null
) => {
const stepLabel = indexPath.join(".");
const levelLabel = getWorkflowLevelLabel(depth, "模块");
@ -4080,6 +4100,10 @@ export function AgentWorkflowSettingsClient({
const isTopLevelStep = depth === 1;
const canMoveTopLevelStepUp = isTopLevelStep && indexPath[0] > 1;
const canMoveTopLevelStepDown = isTopLevelStep && indexPath[0] < siblingCount;
const subtreeDepth = getWorkflowStepSubtreeDepth(step);
const canPromoteStep = Boolean(parentStepKey);
const canIndentStep =
Boolean(previousSiblingStepKey) && depth + subtreeDepth <= AGENT_WORKFLOW_MAX_TREE_DEPTH;
const canAddChildStep = depth < AGENT_WORKFLOW_MAX_TREE_DEPTH;
const canPasteAsChild =
Boolean(copiedWorkflowStep) &&
@ -4185,6 +4209,30 @@ export function AgentWorkflowSettingsClient({
</Button>
</>
) : null}
{canPromoteStep ? (
<Button
type="button"
variant="outline"
size="sm"
className="h-8 px-2 text-xs"
onClick={() => handlePromoteWorkflowStep(step.key, parentStepKey)}
title="提升到父模块同级,例如三级模块变二级模块"
>
升一级
</Button>
) : null}
{canIndentStep ? (
<Button
type="button"
variant="outline"
size="sm"
className="h-8 px-2 text-xs"
onClick={() => handleIndentWorkflowStep(step.key, previousSiblingStepKey)}
title="移入上一个同级模块下面,降低一级"
>
降一级
</Button>
) : null}
{canAddChildStep ? (
<Button
type="button"
@ -4287,7 +4335,8 @@ export function AgentWorkflowSettingsClient({
<div>
<div className="text-sm font-medium">子模块配置</div>
<div className="text-xs text-muted-foreground">
支持把模块拖到任意主模块或子模块下,最多 {AGENT_WORKFLOW_MAX_TREE_DEPTH} 级。
支持拖拽到任意模块下,也可以用“升一级 / 降一级”快速调整层级,最多{" "}
{AGENT_WORKFLOW_MAX_TREE_DEPTH} 级。
</div>
</div>
<div className="flex flex-wrap items-center gap-2">
@ -4322,10 +4371,14 @@ export function AgentWorkflowSettingsClient({
{sortedChildSteps.length > 0 ? (
<div className="space-y-3 border-l border-dashed border-border/80 pl-3 sm:pl-4">
{sortedChildSteps.map((childStep, childIndex) =>
renderWorkflowStepCard(childStep, depth + 1, [
...indexPath,
childIndex + 1,
], sortedChildSteps.length)
renderWorkflowStepCard(
childStep,
depth + 1,
[...indexPath, childIndex + 1],
sortedChildSteps.length,
step.key,
childIndex > 0 ? sortedChildSteps[childIndex - 1].key : null
)
)}
</div>
) : (
@ -6073,7 +6126,14 @@ export function AgentWorkflowSettingsClient({
{sortedSteps.length > 0 ? (
sortedSteps.map((step, stepIndex) =>
renderWorkflowStepCard(step, 1, [stepIndex + 1], sortedSteps.length)
renderWorkflowStepCard(
step,
1,
[stepIndex + 1],
sortedSteps.length,
null,
stepIndex > 0 ? sortedSteps[stepIndex - 1].key : null
)
)
) : (
<motion.div variants={itemVariants}>