feat: enhance WorkflowEditor with improved node selection and validation display
This commit is contained in:
@@ -530,14 +530,38 @@ export function AIAgentConfigWorkbench({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button variant="outline" disabled={savingAgent || loading} onClick={saveAgentSettings}>
|
{activeSection === "workflow" ? (
|
||||||
<SaveIcon className="size-4" />
|
<>
|
||||||
保存
|
{validation ? (
|
||||||
</Button>
|
<Badge variant={validation.valid ? "default" : "destructive"}>
|
||||||
<Button disabled={savingWorkflow || loading || !currentAgentId} onClick={publishWorkflow}>
|
{validation.valid ? "校验通过" : `${validation.errors.length} 个问题`}
|
||||||
<SendIcon className="size-4" />
|
</Badge>
|
||||||
发布流程
|
) : null}
|
||||||
</Button>
|
<Button variant="outline" disabled={savingWorkflow || loading || !currentAgentId} onClick={validateWorkflowDraft}>
|
||||||
|
<CheckCircle2Icon className="size-4" />
|
||||||
|
校验
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" disabled={savingWorkflow || loading || !currentAgentId} onClick={saveWorkflowDraft}>
|
||||||
|
<SaveIcon className="size-4" />
|
||||||
|
保存草稿
|
||||||
|
</Button>
|
||||||
|
<Button disabled={savingWorkflow || loading || !currentAgentId} onClick={publishWorkflow}>
|
||||||
|
<SendIcon className="size-4" />
|
||||||
|
发布流程
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Button variant="outline" disabled={savingAgent || loading} onClick={saveAgentSettings}>
|
||||||
|
<SaveIcon className="size-4" />
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
<Button disabled={savingWorkflow || loading || !currentAgentId} onClick={publishWorkflow}>
|
||||||
|
<SendIcon className="size-4" />
|
||||||
|
发布流程
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -753,40 +777,12 @@ export function AIAgentConfigWorkbench({
|
|||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{activeSection === "workflow" ? (
|
{activeSection === "workflow" ? (
|
||||||
<div className="flex h-full min-h-0 flex-col">
|
<WorkflowEditor
|
||||||
<div className="flex shrink-0 items-center justify-between border-b px-3 py-2">
|
key={editorKey}
|
||||||
<div className="min-w-0 flex-1">
|
definition={definition}
|
||||||
<div className="truncate text-sm font-medium">主会话流程</div>
|
nodeSpecs={nodeSpecs}
|
||||||
</div>
|
onDefinitionChange={setDefinition}
|
||||||
<div className="ml-3 flex items-center gap-2">
|
/>
|
||||||
{validation ? (
|
|
||||||
<Badge variant={validation.valid ? "default" : "destructive"}>
|
|
||||||
{validation.valid ? "校验通过" : `${validation.errors.length} 个问题`}
|
|
||||||
</Badge>
|
|
||||||
) : null}
|
|
||||||
<Button size="sm" variant="outline" disabled={savingWorkflow || !currentAgentId} onClick={validateWorkflowDraft}>
|
|
||||||
<CheckCircle2Icon className="size-4" />
|
|
||||||
校验
|
|
||||||
</Button>
|
|
||||||
<Button size="sm" variant="outline" disabled={savingWorkflow || !currentAgentId} onClick={saveWorkflowDraft}>
|
|
||||||
<SaveIcon className="size-4" />
|
|
||||||
保存草稿
|
|
||||||
</Button>
|
|
||||||
<Button size="sm" disabled={savingWorkflow || !currentAgentId} onClick={publishWorkflow}>
|
|
||||||
<SendIcon className="size-4" />
|
|
||||||
发布
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="min-h-0 flex-1">
|
|
||||||
<WorkflowEditor
|
|
||||||
key={editorKey}
|
|
||||||
definition={definition}
|
|
||||||
nodeSpecs={nodeSpecs}
|
|
||||||
onDefinitionChange={setDefinition}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{activeSection === "handoff" ? (
|
{activeSection === "handoff" ? (
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import { AlertCircleIcon, CheckCircle2Icon } from "lucide-react"
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
|
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Button } from "@/components/ui/button"
|
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
@@ -188,6 +187,10 @@ export function WorkflowEditor({
|
|||||||
onDefinitionChange(toApiDefinition(draft) as AIWorkflowDefinition)
|
onDefinitionChange(toApiDefinition(draft) as AIWorkflowDefinition)
|
||||||
}, [draft, onDefinitionChange])
|
}, [draft, onDefinitionChange])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onDefinitionChange(toApiDefinition(draft) as AIWorkflowDefinition)
|
||||||
|
}, [draft, onDefinitionChange])
|
||||||
|
|
||||||
const onConnect = useCallback(
|
const onConnect = useCallback(
|
||||||
(connection: Connection) => {
|
(connection: Connection) => {
|
||||||
if (!connection.source || !connection.target) {
|
if (!connection.source || !connection.target) {
|
||||||
@@ -361,7 +364,7 @@ export function WorkflowEditor({
|
|||||||
</aside>
|
</aside>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
<ResizableHandle withHandle />
|
<ResizableHandle withHandle />
|
||||||
<ResizablePanel defaultSize="56%" minSize="30%" className="min-h-0">
|
<ResizablePanel defaultSize={selectedNode ? "56%" : "82%"} minSize="30%" className="min-h-0">
|
||||||
<section
|
<section
|
||||||
data-workflow-canvas
|
data-workflow-canvas
|
||||||
ref={canvasRef}
|
ref={canvasRef}
|
||||||
@@ -382,7 +385,12 @@ export function WorkflowEditor({
|
|||||||
onEdgesChange={onEdgesChange}
|
onEdgesChange={onEdgesChange}
|
||||||
onConnect={onConnect}
|
onConnect={onConnect}
|
||||||
onInit={setFlowInstance}
|
onInit={setFlowInstance}
|
||||||
onNodeClick={(_, node) => setSelectedNodeId(node.id)}
|
onNodeClick={(event, node) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
setSelectedNodeId(node.id)
|
||||||
|
}}
|
||||||
|
onEdgeClick={() => setSelectedNodeId(null)}
|
||||||
|
onPaneClick={() => setSelectedNodeId(null)}
|
||||||
fitView
|
fitView
|
||||||
fitViewOptions={fitViewOptions}
|
fitViewOptions={fitViewOptions}
|
||||||
minZoom={0.45}
|
minZoom={0.45}
|
||||||
@@ -406,36 +414,31 @@ export function WorkflowEditor({
|
|||||||
) : null}
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
<ResizableHandle withHandle />
|
{selectedNode ? (
|
||||||
<ResizablePanel defaultSize="26%" minSize="18%" maxSize="40%" className="min-h-0">
|
<>
|
||||||
<aside className="h-full min-h-0 overflow-y-auto bg-muted/10">
|
<ResizableHandle withHandle />
|
||||||
<NodeConfigPanel
|
<ResizablePanel defaultSize="26%" minSize="18%" maxSize="40%" className="min-h-0">
|
||||||
node={selectedNode}
|
<aside className="h-full min-h-0 overflow-y-auto bg-muted/10">
|
||||||
nodeSpec={selectedNodeSpec}
|
<NodeConfigPanel
|
||||||
availableVariables={availableVariables}
|
node={selectedNode}
|
||||||
onChange={updateNodeData}
|
nodeSpec={selectedNodeSpec}
|
||||||
/>
|
availableVariables={availableVariables}
|
||||||
{!validation.valid ? (
|
onChange={updateNodeData}
|
||||||
<div className="border-t p-4">
|
/>
|
||||||
<div className="mb-2 text-sm font-medium">流程检查</div>
|
{!validation.valid ? (
|
||||||
<ul className="space-y-1 text-xs text-destructive">
|
<div className="border-t p-4">
|
||||||
{validation.errors.map((error) => (
|
<div className="mb-2 text-sm font-medium">流程检查</div>
|
||||||
<li key={error}>{error}</li>
|
<ul className="space-y-1 text-xs text-destructive">
|
||||||
))}
|
{validation.errors.map((error) => (
|
||||||
</ul>
|
<li key={error}>{error}</li>
|
||||||
</div>
|
))}
|
||||||
) : null}
|
</ul>
|
||||||
<div className="border-t p-4">
|
</div>
|
||||||
<Button
|
) : null}
|
||||||
variant="outline"
|
</aside>
|
||||||
className="w-full"
|
</ResizablePanel>
|
||||||
onClick={() => onDefinitionChange(toApiDefinition(toDraft(nodes, edges)) as AIWorkflowDefinition)}
|
</>
|
||||||
>
|
) : null}
|
||||||
同步当前流程
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
</ResizablePanel>
|
|
||||||
</ResizablePanelGroup>
|
</ResizablePanelGroup>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user