feat: add WorkflowEditorStatus component for displaying validation and node counts

This commit is contained in:
mlogclub
2026-06-28 22:32:43 +08:00
parent 4a1595ae73
commit bcaa6225d4
4 changed files with 47 additions and 30 deletions
+1 -1
Submodule docs updated: b6d08c0964...5b69ec7539
@@ -0,0 +1,38 @@
"use client"
import { AlertTriangleIcon, CheckCircle2Icon } from "lucide-react"
import { cn } from "@/lib/utils"
import type { WorkflowDraftValidation } from "./workflow-utils"
export function WorkflowEditorStatus({
validation,
nodeCount,
edgeCount,
}: {
validation: WorkflowDraftValidation
nodeCount: number
edgeCount: number
}) {
return (
<div className="pointer-events-none inline-flex min-h-8 w-fit max-w-full items-center gap-2 rounded-md border border-slate-200/80 bg-white/90 px-2.5 py-1 text-xs text-slate-500 shadow-sm backdrop-blur">
<span
className={cn(
"inline-flex shrink-0 items-center gap-1",
validation.valid ? "text-emerald-600" : "text-amber-700"
)}
>
{validation.valid ? (
<CheckCircle2Icon className="size-3.5" />
) : (
<AlertTriangleIcon className="size-3.5" />
)}
{validation.valid ? "检查通过" : `${validation.errors.length} 个问题`}
</span>
<span className="h-3 w-px shrink-0 bg-slate-200" />
<span className="shrink-0">{nodeCount} </span>
<span className="shrink-0">{edgeCount} 线</span>
</div>
)
}
@@ -2,7 +2,6 @@
import type { ReactNode } from "react"
import {
CheckCircle2Icon,
RotateCcwIcon,
SaveIcon,
SendIcon,
@@ -10,14 +9,8 @@ import {
} from "lucide-react"
import { Button } from "@/components/ui/button"
import { cn } from "@/lib/utils"
import type { WorkflowDraftValidation } from "./workflow-utils"
export function WorkflowEditorToolbar({
validation,
nodeCount,
edgeCount,
toolbarExtra,
onUndo,
undoDisabled = false,
@@ -32,9 +25,6 @@ export function WorkflowEditorToolbar({
onPublish,
publishDisabled = false,
}: {
validation: WorkflowDraftValidation
nodeCount: number
edgeCount: number
toolbarExtra?: ReactNode
onUndo?: () => void
undoDisabled?: boolean
@@ -50,21 +40,7 @@ export function WorkflowEditorToolbar({
publishDisabled?: boolean
}) {
return (
<div className="inline-flex min-h-10 w-fit max-w-full items-center gap-3 rounded-md bg-background/95 px-2 py-1 shadow-sm backdrop-blur">
<div className="flex min-w-0 shrink items-center gap-2">
<span
className={cn(
"inline-flex items-center gap-1 rounded-sm px-2 py-1 text-xs",
validation.valid ? "bg-muted text-muted-foreground" : "bg-amber-50 text-amber-700"
)}
>
<CheckCircle2Icon className="size-3" />
{validation.valid ? "本地检查通过" : `${validation.errors.length} 个本地问题`}
</span>
<span className="truncate text-xs text-muted-foreground">
{nodeCount} / {edgeCount} 线
</span>
</div>
<div className="inline-flex min-h-10 w-fit max-w-full items-center rounded-md bg-background/95 px-2 py-1 shadow-sm backdrop-blur">
<div className="flex min-w-0 items-center gap-1 overflow-x-auto">
{toolbarExtra}
<Button type="button" variant="ghost" size="sm" className="h-7 shrink-0 px-2 text-xs" disabled={undoDisabled} onClick={onUndo}>
@@ -27,6 +27,7 @@ import {
} from "./workflow-branch-selection"
import { WorkflowCanvasControls } from "./workflow-canvas-controls"
import { WorkflowConfigPanel } from "./workflow-config-sidebar"
import { WorkflowEditorStatus } from "./workflow-editor-status"
import { WorkflowEditorToolbar } from "./workflow-editor-toolbar"
import {
WorkflowPortAddProvider,
@@ -329,14 +330,11 @@ function WorkflowEditorInner({
>
<div
className={cn(
"absolute left-3 top-3 z-50 max-w-[calc(100%-1.5rem)]",
"absolute left-3 top-3 z-50 flex max-w-[calc(100%-1.5rem)] flex-col items-start gap-2",
selectedNodeId && "max-w-[calc(100%-25rem)]"
)}
>
<WorkflowEditorToolbar
validation={validation}
nodeCount={definition.nodes.length}
edgeCount={definition.edges.length}
toolbarExtra={toolbarExtra}
onUndo={onUndo}
undoDisabled={undoDisabled}
@@ -351,6 +349,11 @@ function WorkflowEditorInner({
onPublish={onPublish}
publishDisabled={publishDisabled}
/>
<WorkflowEditorStatus
validation={validation}
nodeCount={definition.nodes.length}
edgeCount={definition.edges.length}
/>
</div>
<div className="absolute bottom-3 left-3 z-50">