Files
ai-agent/web/app/dashboard/ai-workflows/_components/variable-selector.tsx
T

45 lines
1.0 KiB
TypeScript
Raw Normal View History

"use client"
import { OptionCombobox } from "@/components/option-combobox"
2026-06-27 21:27:57 +08:00
import {
buildVariableOption,
2026-06-27 21:27:57 +08:00
createRefValue,
refField,
refNodeId,
type WorkflowVariableRef,
type WorkflowVariableSelector,
} from "./workflow-utils"
export function VariableSelector({
value,
variables,
onChange,
2026-06-27 21:27:57 +08:00
placeholder = "选择变量",
triggerClassName,
}: {
value?: WorkflowVariableSelector
variables: WorkflowVariableRef[]
onChange: (value: WorkflowVariableSelector) => void
2026-06-27 21:27:57 +08:00
placeholder?: string
triggerClassName?: string
}) {
2026-06-27 21:27:57 +08:00
const selected = value ? `${refNodeId(value)}.${refField(value)}` : ""
const options = variables.map(buildVariableOption)
return (
<OptionCombobox
2026-06-27 21:27:57 +08:00
value={selected}
options={options}
2026-06-27 21:27:57 +08:00
placeholder={placeholder}
triggerClassName={triggerClassName}
2026-06-27 21:27:57 +08:00
onChange={(next) => {
const variable = variables.find((item) => `${item.nodeId}.${item.field}` === next)
if (variable) {
onChange(createRefValue(variable.nodeId, variable.field))
}
}}
/>
)
}