Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
2a99e463
authored
May 07, 2024
by
heheer
Committed by
GitHub
May 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: if else node (#1383)
* fix: if else node * fix * fix
parent
8f9203c0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
38 deletions
+81
-38
packages/global/core/workflow/template/system/ifElse/constant.ts
+5
-0
packages/global/core/workflow/utils.ts
+5
-0
packages/service/core/workflow/dispatch/tools/runIfElse.ts
+8
-5
projects/app/src/components/core/workflow/Flow/nodes/NodeIfElse/ListItem.tsx
+34
-30
projects/app/src/components/core/workflow/Flow/nodes/NodeIfElse/index.tsx
+4
-3
projects/app/src/web/core/workflow/utils.ts
+25
-0
No files found.
packages/global/core/workflow/template/system/ifElse/constant.ts
View file @
2a99e463
...
@@ -20,6 +20,11 @@ export enum VariableConditionEnum {
...
@@ -20,6 +20,11 @@ export enum VariableConditionEnum {
lengthLessThan
=
'lengthLessThan'
,
lengthLessThan
=
'lengthLessThan'
,
lengthLessThanOrEqualTo
=
'lengthLessThanOrEqualTo'
lengthLessThanOrEqualTo
=
'lengthLessThanOrEqualTo'
}
}
export
enum
IfElseResultEnum
{
IF
=
'IF'
,
ELSE
=
'ELSE'
,
ELSE_IF
=
'ELSE IF'
}
export
const
stringConditionList
=
[
export
const
stringConditionList
=
[
{
label
:
'为空'
,
value
:
VariableConditionEnum
.
isEmpty
},
{
label
:
'为空'
,
value
:
VariableConditionEnum
.
isEmpty
},
...
...
packages/global/core/workflow/utils.ts
View file @
2a99e463
...
@@ -15,6 +15,7 @@ import type {
...
@@ -15,6 +15,7 @@ import type {
}
from
'../app/type'
;
}
from
'../app/type'
;
import
{
EditorVariablePickerType
}
from
'../../../web/components/common/Textarea/PromptEditor/type'
;
import
{
EditorVariablePickerType
}
from
'../../../web/components/common/Textarea/PromptEditor/type'
;
import
{
defaultWhisperConfig
}
from
'../app/constants'
;
import
{
defaultWhisperConfig
}
from
'../app/constants'
;
import
{
IfElseResultEnum
}
from
'./template/system/ifElse/constant'
;
export
const
getHandleId
=
(
nodeId
:
string
,
type
:
'source'
|
'target'
,
key
:
string
)
=>
{
export
const
getHandleId
=
(
nodeId
:
string
,
type
:
'source'
|
'target'
,
key
:
string
)
=>
{
return
`
${
nodeId
}
-
${
type
}
-
${
key
}
`
;
return
`
${
nodeId
}
-
${
type
}
-
${
key
}
`
;
...
@@ -136,3 +137,7 @@ export const formatEditorVariablePickerIcon = (
...
@@ -136,3 +137,7 @@ export const formatEditorVariablePickerIcon = (
export
const
isReferenceValue
=
(
value
:
any
):
boolean
=>
{
export
const
isReferenceValue
=
(
value
:
any
):
boolean
=>
{
return
Array
.
isArray
(
value
)
&&
value
.
length
===
2
&&
typeof
value
[
0
]
===
'string'
;
return
Array
.
isArray
(
value
)
&&
value
.
length
===
2
&&
typeof
value
[
0
]
===
'string'
;
};
};
export
const
getElseIFLabel
=
(
i
:
number
)
=>
{
return
i
===
0
?
IfElseResultEnum
.
IF
:
`
${
IfElseResultEnum
.
ELSE_IF
}
${
i
}
`
;
};
packages/service/core/workflow/dispatch/tools/runIfElse.ts
View file @
2a99e463
import
{
NodeInputKeyEnum
,
NodeOutputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
import
{
NodeInputKeyEnum
,
NodeOutputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
import
{
DispatchNodeResponseKeyEnum
}
from
'@fastgpt/global/core/workflow/runtime/constants'
;
import
{
DispatchNodeResponseKeyEnum
}
from
'@fastgpt/global/core/workflow/runtime/constants'
;
import
{
DispatchNodeResultType
}
from
'@fastgpt/global/core/workflow/runtime/type'
;
import
{
DispatchNodeResultType
}
from
'@fastgpt/global/core/workflow/runtime/type'
;
import
{
VariableConditionEnum
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/constant'
;
import
{
IfElseResultEnum
,
VariableConditionEnum
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/constant'
;
import
{
import
{
ConditionListItemType
,
ConditionListItemType
,
IfElseConditionType
,
IfElseConditionType
,
IfElseListItemType
IfElseListItemType
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/type'
;
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/type'
;
import
{
ModuleDispatchProps
}
from
'@fastgpt/global/core/workflow/type'
;
import
{
ModuleDispatchProps
}
from
'@fastgpt/global/core/workflow/type'
;
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
get
ElseIFLabel
,
get
HandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
getReferenceVariableValue
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
import
{
getReferenceVariableValue
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
type
Props
=
ModuleDispatchProps
<
{
type
Props
=
ModuleDispatchProps
<
{
...
@@ -75,18 +78,18 @@ export const dispatchIfElse = async (props: Props): Promise<Response> => {
...
@@ -75,18 +78,18 @@ export const dispatchIfElse = async (props: Props): Promise<Response> => {
}
=
props
;
}
=
props
;
const
{
ifElseList
}
=
params
;
const
{
ifElseList
}
=
params
;
let
res
=
'ELSE'
;
let
res
=
IfElseResultEnum
.
ELSE
as
string
;
for
(
let
i
=
0
;
i
<
ifElseList
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
ifElseList
.
length
;
i
++
)
{
const
item
=
ifElseList
[
i
];
const
item
=
ifElseList
[
i
];
const
result
=
getResult
(
item
.
condition
,
item
.
list
,
variables
,
runtimeNodes
);
const
result
=
getResult
(
item
.
condition
,
item
.
list
,
variables
,
runtimeNodes
);
if
(
result
)
{
if
(
result
)
{
res
=
`IF
${
i
}
`
;
res
=
getElseIFLabel
(
i
)
;
break
;
break
;
}
}
}
}
const
resArray
=
Array
.
from
({
length
:
ifElseList
.
length
+
1
},
(
_
,
index
)
=>
{
const
resArray
=
Array
.
from
({
length
:
ifElseList
.
length
+
1
},
(
_
,
index
)
=>
{
const
label
=
index
<
ifElseList
.
length
?
`IF
${
index
}
`
:
'ELSE'
;
const
label
=
index
<
ifElseList
.
length
?
getElseIFLabel
(
index
)
:
IfElseResultEnum
.
ELSE
;
return
getHandleId
(
nodeId
,
'source'
,
label
);
return
getHandleId
(
nodeId
,
'source'
,
label
);
});
});
...
...
projects/app/src/components/core/workflow/Flow/nodes/NodeIfElse/ListItem.tsx
View file @
2a99e463
...
@@ -21,7 +21,7 @@ import React, { useMemo } from 'react';
...
@@ -21,7 +21,7 @@ import React, { useMemo } from 'react';
import
{
WorkflowContext
}
from
'../../../context'
;
import
{
WorkflowContext
}
from
'../../../context'
;
import
MySelect
from
'@fastgpt/web/components/common/MySelect'
;
import
MySelect
from
'@fastgpt/web/components/common/MySelect'
;
import
MyInput
from
'@/components/MyInput'
;
import
MyInput
from
'@/components/MyInput'
;
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
get
ElseIFLabel
,
get
HandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
SourceHandle
}
from
'../render/Handle'
;
import
{
SourceHandle
}
from
'../render/Handle'
;
import
{
Position
,
useReactFlow
}
from
'reactflow'
;
import
{
Position
,
useReactFlow
}
from
'reactflow'
;
import
{
getReferenceDataValueType
}
from
'@/web/core/workflow/utils'
;
import
{
getReferenceDataValueType
}
from
'@/web/core/workflow/utils'
;
...
@@ -63,36 +63,40 @@ const ListItem = ({
...
@@ -63,36 +63,40 @@ const ListItem = ({
>
>
<
Container
w=
{
snapshot
.
isDragging
?
''
:
'full'
}
className=
"nodrag"
>
<
Container
w=
{
snapshot
.
isDragging
?
''
:
'full'
}
className=
"nodrag"
>
<
Flex
mb=
{
4
}
alignItems=
{
'center'
}
>
<
Flex
mb=
{
4
}
alignItems=
{
'center'
}
>
<
Box
{
...
provided
.
dragHandleProps
}
>
{
ifElseList
.
length
>
1
&&
(
<
DragHandleIcon
color=
{
'blackAlpha.600'
}
/>
<
Box
{
...
provided
.
dragHandleProps
}
>
</
Box
>
<
DragHandleIcon
color=
{
'blackAlpha.600'
}
/>
</
Box
>
)
}
<
Box
color=
{
'black'
}
fontSize=
{
'lg'
}
ml=
{
2
}
>
<
Box
color=
{
'black'
}
fontSize=
{
'lg'
}
ml=
{
2
}
>
{
conditionIndex
===
0
?
'IF'
:
'ELSE IF'
}
{
getElseIFLabel
(
conditionIndex
)
}
</
Box
>
</
Box
>
<
Flex
{
conditionItem
.
list
?.
length
>
1
&&
(
px=
{
'2.5'
}
<
Flex
color=
{
'primary.600'
}
px=
{
'2.5'
}
fontWeight=
{
'medium'
}
color=
{
'primary.600'
}
alignItems=
{
'center'
}
fontWeight=
{
'medium'
}
cursor=
{
'pointer'
}
alignItems=
{
'center'
}
rounded=
{
'md'
}
cursor=
{
'pointer'
}
onClick=
{
()
=>
{
rounded=
{
'md'
}
onUpdateIfElseList
(
onClick=
{
()
=>
{
ifElseList
.
map
((
ifElse
,
index
)
=>
{
onUpdateIfElseList
(
if
(
index
===
conditionIndex
)
{
ifElseList
.
map
((
ifElse
,
index
)
=>
{
return
{
if
(
index
===
conditionIndex
)
{
...
ifElse
,
return
{
condition
:
ifElse
.
condition
===
'AND'
?
'OR'
:
'AND'
...
ifElse
,
};
condition
:
ifElse
.
condition
===
'AND'
?
'OR'
:
'AND'
}
};
return
ifElse
;
}
})
return
ifElse
;
);
})
}
}
);
>
}
}
{
conditionItem
.
condition
}
>
<
MyIcon
ml=
{
1
}
boxSize=
{
5
}
name=
"change"
/>
{
conditionItem
.
condition
}
</
Flex
>
<
MyIcon
ml=
{
1
}
boxSize=
{
5
}
name=
"change"
/>
</
Flex
>
)
}
<
Box
flex=
{
1
}
></
Box
>
<
Box
flex=
{
1
}
></
Box
>
{
ifElseList
.
length
>
1
&&
(
{
ifElseList
.
length
>
1
&&
(
<
MyIcon
<
MyIcon
...
@@ -257,7 +261,7 @@ const ListItem = ({
...
@@ -257,7 +261,7 @@ const ListItem = ({
{
!
snapshot
.
isDragging
&&
(
{
!
snapshot
.
isDragging
&&
(
<
SourceHandle
<
SourceHandle
nodeId=
{
nodeId
}
nodeId=
{
nodeId
}
handleId=
{
getHandleId
(
nodeId
,
'source'
,
'IF'
+
conditionIndex
.
toString
(
))
}
handleId=
{
getHandleId
(
nodeId
,
'source'
,
getElseIFLabel
(
conditionIndex
))
}
position=
{
Position
.
Right
}
position=
{
Position
.
Right
}
translate=
{
[
18
,
0
]
}
translate=
{
[
18
,
0
]
}
/>
/>
...
...
projects/app/src/components/core/workflow/Flow/nodes/NodeIfElse/index.tsx
View file @
2a99e463
...
@@ -13,6 +13,7 @@ import { DragDropContext, DragStart, Draggable, DropResult, Droppable } from 're
...
@@ -13,6 +13,7 @@ import { DragDropContext, DragStart, Draggable, DropResult, Droppable } from 're
import
{
SourceHandle
}
from
'../render/Handle'
;
import
{
SourceHandle
}
from
'../render/Handle'
;
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
ListItem
from
'./ListItem'
;
import
ListItem
from
'./ListItem'
;
import
{
IfElseResultEnum
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/constant'
;
const
NodeIfElse
=
({
data
,
selected
}:
NodeProps
<
FlowNodeItemType
>
)
=>
{
const
NodeIfElse
=
({
data
,
selected
}:
NodeProps
<
FlowNodeItemType
>
)
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
...
@@ -108,7 +109,7 @@ const NodeIfElse = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
...
@@ -108,7 +109,7 @@ const NodeIfElse = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
)
}
)
}
</
Draggable
>
</
Draggable
>
))
}
))
}
<
Box
height=
{
draggingItemHeight
}
/>
{
snapshot
.
isDraggingOver
&&
<
Box
height=
{
draggingItemHeight
}
/>
}
</
Box
>
</
Box
>
)
}
)
}
</
Droppable
>
</
Droppable
>
...
@@ -116,11 +117,11 @@ const NodeIfElse = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
...
@@ -116,11 +117,11 @@ const NodeIfElse = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
<
Container
position=
{
'relative'
}
>
<
Container
position=
{
'relative'
}
>
<
Flex
alignItems=
{
'center'
}
>
<
Flex
alignItems=
{
'center'
}
>
<
Box
color=
{
'black'
}
fontSize=
{
'lg'
}
ml=
{
2
}
>
<
Box
color=
{
'black'
}
fontSize=
{
'lg'
}
ml=
{
2
}
>
ELSE
{
IfElseResultEnum
.
ELSE
}
</
Box
>
</
Box
>
<
SourceHandle
<
SourceHandle
nodeId=
{
nodeId
}
nodeId=
{
nodeId
}
handleId=
{
getHandleId
(
nodeId
,
'source'
,
'ELSE'
)
}
handleId=
{
getHandleId
(
nodeId
,
'source'
,
IfElseResultEnum
.
ELSE
)
}
position=
{
Position
.
Right
}
position=
{
Position
.
Right
}
translate=
{
[
26
,
0
]
}
translate=
{
[
26
,
0
]
}
/>
/>
...
...
projects/app/src/web/core/workflow/utils.ts
View file @
2a99e463
...
@@ -25,6 +25,8 @@ import {
...
@@ -25,6 +25,8 @@ import {
import
{
getSystemVariables
}
from
'../app/utils'
;
import
{
getSystemVariables
}
from
'../app/utils'
;
import
{
TFunction
}
from
'next-i18next'
;
import
{
TFunction
}
from
'next-i18next'
;
import
{
ReferenceValueProps
}
from
'@fastgpt/global/core/workflow/type/io'
;
import
{
ReferenceValueProps
}
from
'@fastgpt/global/core/workflow/type/io'
;
import
{
IfElseListItemType
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/type'
;
import
{
VariableConditionEnum
}
from
'@fastgpt/global/core/workflow/template/system/ifElse/constant'
;
export
const
nodeTemplate2FlowNode
=
({
export
const
nodeTemplate2FlowNode
=
({
template
,
template
,
...
@@ -188,6 +190,29 @@ export const checkWorkflowNodeAndConnection = ({
...
@@ -188,6 +190,29 @@ export const checkWorkflowNodeAndConnection = ({
continue
;
continue
;
}
}
if
(
data
.
flowNodeType
===
FlowNodeTypeEnum
.
ifElseNode
)
{
const
ifElseList
:
IfElseListItemType
[]
=
inputs
.
find
(
(
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
ifElseList
)?.
value
;
if
(
ifElseList
.
some
((
item
)
=>
{
return
item
.
list
.
some
((
listItem
)
=>
{
return
(
listItem
.
variable
===
undefined
||
listItem
.
condition
===
undefined
||
(
listItem
.
value
===
undefined
&&
listItem
.
condition
!==
VariableConditionEnum
.
isEmpty
&&
listItem
.
condition
!==
VariableConditionEnum
.
isNotEmpty
)
);
});
})
)
{
return
[
data
.
nodeId
];
}
else
{
continue
;
}
}
// check node input
// check node input
if
(
if
(
inputs
.
some
((
input
)
=>
{
inputs
.
some
((
input
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment