mirror of https://github.com/langgenius/dify.git
feat: var picker get vars
This commit is contained in:
parent
a031507443
commit
14d71fb598
|
|
@ -7,12 +7,14 @@ import VarReferencePicker from './var-reference-picker'
|
|||
import type { ValueSelector, Variable } from '@/app/components/workflow/types'
|
||||
|
||||
type Props = {
|
||||
nodeId: string
|
||||
readonly: boolean
|
||||
list: Variable[]
|
||||
onChange: (list: Variable[]) => void
|
||||
}
|
||||
|
||||
const VarList: FC<Props> = ({
|
||||
nodeId,
|
||||
readonly,
|
||||
list,
|
||||
onChange,
|
||||
|
|
@ -57,6 +59,7 @@ const VarList: FC<Props> = ({
|
|||
className='w-[120px] h-8 leading-8 px-2.5 rounded-lg border-0 bg-gray-100 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200'
|
||||
type='text' />
|
||||
<VarReferencePicker
|
||||
nodeId={nodeId}
|
||||
readonly={readonly}
|
||||
isShowNodeName
|
||||
className='grow'
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ import {
|
|||
PortalToFollowElemContent,
|
||||
PortalToFollowElemTrigger,
|
||||
} from '@/app/components/base/portal-to-follow-elem'
|
||||
import { useWorkflow } from '@/app/components/workflow/hooks'
|
||||
|
||||
type Props = {
|
||||
className?: string
|
||||
nodeId: string
|
||||
isShowNodeName: boolean
|
||||
readonly: boolean
|
||||
value: ValueSelector
|
||||
|
|
@ -35,12 +37,15 @@ export const getNodeInfoById = (id: string) => {
|
|||
}
|
||||
|
||||
const VarReferencePicker: FC<Props> = ({
|
||||
nodeId,
|
||||
readonly,
|
||||
className,
|
||||
isShowNodeName,
|
||||
value,
|
||||
onChange,
|
||||
}) => {
|
||||
const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow()
|
||||
// console.log(getBeforeNodesInSameBranch(nodeId), getTreeLeafNodes())
|
||||
const [open, setOpen] = useState(false)
|
||||
const hasValue = value.length > 0
|
||||
const node = hasValue ? getNodeInfoById(value[0]) : null
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
|
|||
>
|
||||
<VarList
|
||||
readonly={readOnly}
|
||||
nodeId={id}
|
||||
list={inputs.variables}
|
||||
onChange={handleVarListChange}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ const Panel: FC<NodePanelProps<EndNodeType>> = ({
|
|||
=== EndVarType.structured
|
||||
? (
|
||||
<VarList
|
||||
nodeId={id}
|
||||
readonly={readOnly}
|
||||
list={outputs.structured_variables!}
|
||||
onChange={handleVarListChange}
|
||||
|
|
@ -88,6 +89,7 @@ const Panel: FC<NodePanelProps<EndNodeType>> = ({
|
|||
: (
|
||||
<VarReferencePicker
|
||||
isShowNodeName
|
||||
nodeId={id}
|
||||
readonly={readOnly}
|
||||
value={outputs.plain_text_selector!}
|
||||
onChange={handelPlainTextSelectorChange}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ const getOperators = (type: string) => {
|
|||
|
||||
type ItemProps = {
|
||||
readonly: boolean
|
||||
nodeId: string
|
||||
payload: Condition
|
||||
onChange: (newItem: Condition) => void
|
||||
canRemove: boolean
|
||||
|
|
@ -76,6 +77,7 @@ type ItemProps = {
|
|||
|
||||
const Item: FC<ItemProps> = ({
|
||||
readonly,
|
||||
nodeId,
|
||||
payload,
|
||||
onChange,
|
||||
canRemove,
|
||||
|
|
@ -132,6 +134,7 @@ const Item: FC<ItemProps> = ({
|
|||
|
||||
<div className='flex items-center space-x-1'>
|
||||
<VarReferencePicker
|
||||
nodeId={nodeId}
|
||||
readonly={readonly}
|
||||
isShowNodeName
|
||||
className='grow'
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import Item from './condition-item'
|
|||
import type { Condition, LogicalOperator } from '@/app/components/workflow/nodes/if-else/types'
|
||||
|
||||
type Props = {
|
||||
nodeId: string
|
||||
className?: string
|
||||
readonly: boolean
|
||||
list: Condition[]
|
||||
|
|
@ -18,6 +19,7 @@ type Props = {
|
|||
const ConditionList: FC<Props> = ({
|
||||
className,
|
||||
readonly,
|
||||
nodeId,
|
||||
list,
|
||||
onChange,
|
||||
logicalOperator,
|
||||
|
|
@ -50,6 +52,7 @@ const ConditionList: FC<Props> = ({
|
|||
<div className={cn(className, 'space-y-2')}>
|
||||
<Item
|
||||
readonly={readonly}
|
||||
nodeId={nodeId}
|
||||
payload={list[0]}
|
||||
onChange={handleItemChange(0)}
|
||||
canRemove={canRemove}
|
||||
|
|
@ -63,6 +66,7 @@ const ConditionList: FC<Props> = ({
|
|||
<Item
|
||||
key={item.id}
|
||||
readonly={readonly}
|
||||
nodeId={nodeId}
|
||||
payload={item}
|
||||
onChange={handleItemChange(i + 1)}
|
||||
canRemove={canRemove}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ const Panel: FC<NodePanelProps<IfElseNodeType>> = ({
|
|||
<ConditionList
|
||||
className='mt-2'
|
||||
readonly={readOnly}
|
||||
nodeId={id}
|
||||
list={inputs.conditions}
|
||||
onChange={handleConditionsChange}
|
||||
logicalOperator={inputs.logical_operator}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
|
|||
title={t(`${i18nPrefix}.queryVariable`)}
|
||||
>
|
||||
<VarReferencePicker
|
||||
nodeId={id}
|
||||
readonly={readOnly}
|
||||
isShowNodeName
|
||||
value={inputs.query_variable_selector}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
>
|
||||
<VarList
|
||||
readonly={readOnly}
|
||||
nodeId={id}
|
||||
list={inputs.variables}
|
||||
onChange={handleVarListChange}
|
||||
/>
|
||||
|
|
@ -146,6 +147,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
|
|||
>
|
||||
<VarReferencePicker
|
||||
readonly={readOnly}
|
||||
nodeId={id}
|
||||
isShowNodeName
|
||||
value={inputs.context?.variable_selector || []}
|
||||
onChange={handleContextVarChange}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||
<VarReferencePicker
|
||||
readonly={readOnly}
|
||||
isShowNodeName
|
||||
nodeId={id}
|
||||
value={inputs.query_variable_selector}
|
||||
onChange={handleQueryVarChange}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import VarReferencePicker from '@/app/components/workflow/nodes/_base/components
|
|||
|
||||
type Props = {
|
||||
readOnly: boolean
|
||||
nodeId: string
|
||||
schema: CredentialFormSchema[]
|
||||
value: ToolVarInput[]
|
||||
onChange: (value: ToolVarInput[]) => void
|
||||
|
|
@ -18,6 +19,7 @@ type Props = {
|
|||
|
||||
const InputVarList: FC<Props> = ({
|
||||
readOnly,
|
||||
nodeId,
|
||||
schema,
|
||||
value,
|
||||
onChange,
|
||||
|
|
@ -72,6 +74,7 @@ const InputVarList: FC<Props> = ({
|
|||
<VarReferencePicker
|
||||
readonly={readOnly}
|
||||
isShowNodeName
|
||||
nodeId={nodeId}
|
||||
value={varInput?.value_selector || []} // TODO: support constant value
|
||||
onChange={handleChange(variable)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
|
|||
>
|
||||
<InputVarList
|
||||
readOnly={readOnly}
|
||||
nodeId={id}
|
||||
schema={toolInputVarSchema as any}
|
||||
value={inputs.tool_inputs}
|
||||
onChange={setInputVar}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ import type { ValueSelector } from '@/app/components/workflow/types'
|
|||
|
||||
type Props = {
|
||||
readonly: boolean
|
||||
nodeId: string
|
||||
list: ValueSelector[]
|
||||
onChange: (list: ValueSelector[]) => void
|
||||
}
|
||||
|
||||
const VarList: FC<Props> = ({
|
||||
readonly,
|
||||
nodeId,
|
||||
list,
|
||||
onChange,
|
||||
}) => {
|
||||
|
|
@ -51,6 +53,7 @@ const VarList: FC<Props> = ({
|
|||
<div className='flex items-center space-x-1' key={index}>
|
||||
<VarReferencePicker
|
||||
readonly={readonly}
|
||||
nodeId={nodeId}
|
||||
isShowNodeName
|
||||
className='grow'
|
||||
value={item}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ const Panel: FC<NodePanelProps<VariableAssignerNodeType>> = ({
|
|||
>
|
||||
<VarList
|
||||
readonly={readOnly}
|
||||
nodeId={id}
|
||||
list={inputs.variables}
|
||||
onChange={handleVarListChange}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue