feat: support reordering workflow modules
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-02 21:06:22 +08:00
parent 83c31b600c
commit cc53eee037

View File

@ -1860,6 +1860,29 @@ export function AgentWorkflowSettingsClient({
});
};
const handleMoveTopLevelStep = (stepKey: string, direction: "up" | "down") => {
setConfig((prev) => {
const sortedRootSteps = [...prev.steps].sort((left, right) => left.sortOrder - right.sortOrder);
const currentIndex = sortedRootSteps.findIndex((step) => step.key === stepKey);
if (currentIndex < 0) {
return prev;
}
const targetIndex = direction === "up" ? currentIndex - 1 : currentIndex + 1;
if (targetIndex < 0 || targetIndex >= sortedRootSteps.length) {
return prev;
}
return normalizeConfigOrdering({
...prev,
steps: moveArrayItem(sortedRootSteps, currentIndex, targetIndex).map((step, index) => ({
...step,
sortOrder: index,
})),
});
});
};
const handleUploadPreview = async (stepKey: string, optionKey: string, file: File) => {
if (!file.type.startsWith("image/")) {
toast.error("请上传图片文件");
@ -2665,12 +2688,16 @@ export function AgentWorkflowSettingsClient({
const renderWorkflowStepCard = (
step: AgentWorkflowStepUiConfig,
depth: number,
indexPath: number[]
indexPath: number[],
siblingCount = 0
) => {
const stepLabel = indexPath.join(".");
const levelLabel = getWorkflowLevelLabel(depth, "模块");
const rootOptions = [...(step.options || [])].sort((left, right) => left.sortOrder - right.sortOrder);
const optionCardCount = countAgentWorkflowOptionTree(step.options || []);
const isTopLevelStep = depth === 1;
const canMoveTopLevelStepUp = isTopLevelStep && indexPath[0] > 1;
const canMoveTopLevelStepDown = isTopLevelStep && indexPath[0] < siblingCount;
return (
<motion.div
@ -2729,6 +2756,30 @@ export function AgentWorkflowSettingsClient({
<div className="flex flex-wrap items-center gap-2">
<Badge variant="secondary">{optionCardCount} 张卡片</Badge>
<Badge variant="outline">卡片树结构</Badge>
{isTopLevelStep ? (
<>
<Button
type="button"
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => handleMoveTopLevelStep(step.key, "up")}
disabled={!canMoveTopLevelStepUp}
>
<ArrowUp className="h-4 w-4" />
</Button>
<Button
type="button"
variant="outline"
size="icon"
className="h-8 w-8"
onClick={() => handleMoveTopLevelStep(step.key, "down")}
disabled={!canMoveTopLevelStepDown}
>
<ArrowDown className="h-4 w-4" />
</Button>
</>
) : null}
<Switch
checked={step.enabled}
onCheckedChange={(checked) =>
@ -4355,7 +4406,7 @@ export function AgentWorkflowSettingsClient({
{sortedSteps.length > 0 ? (
sortedSteps.map((step, stepIndex) =>
renderWorkflowStepCard(step, 1, [stepIndex + 1])
renderWorkflowStepCard(step, 1, [stepIndex + 1], sortedSteps.length)
)
) : (
<motion.div variants={itemVariants}>