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
c64d629a
authored
Dec 09, 2024
by
heheer
Committed by
GitHub
Dec 09, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: loop node snapshot & infinite reload (#3349)
parent
1a294c1f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
81 deletions
+84
-81
packages/web/hooks/useI18n.ts
+1
-1
projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/hooks/useWorkflow.tsx
+69
-59
projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/Loop/NodeLoop.tsx
+8
-4
projects/app/src/pages/app/detail/components/WorkflowComponents/context/index.tsx
+4
-5
projects/app/src/web/core/workflow/utils.ts
+2
-12
No files found.
packages/web/hooks/useI18n.ts
View file @
c64d629a
...
...
@@ -34,7 +34,7 @@ export const useI18nLng = () => {
const
currentLng
=
i18n
?.
language
;
await
i18n
?.
changeLanguage
?.(
lang
);
if
(
currentLng
!==
lang
)
{
if
(
currentLng
!==
lang
&&
currentLng
)
{
window
?.
location
?.
reload
?.();
}
};
...
...
projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/hooks/useWorkflow.tsx
View file @
c64d629a
...
...
@@ -292,63 +292,7 @@ export const useWorkflow = () => {
const
{
getIntersectingNodes
}
=
useReactFlow
();
const
{
isDowningCtrl
}
=
useKeyboard
();
// Loop node size and position
const
resetParentNodeSizeAndPosition
=
useMemoizedFn
((
parentId
:
string
)
=>
{
const
{
childNodes
,
loopNode
}
=
nodes
.
reduce
(
(
acc
,
node
)
=>
{
if
(
node
.
data
.
parentNodeId
===
parentId
)
{
acc
.
childNodes
.
push
(
node
);
}
if
(
node
.
id
===
parentId
)
{
acc
.
loopNode
=
node
;
}
return
acc
;
},
{
childNodes
:
[]
as
Node
[],
loopNode
:
undefined
as
Node
<
FlowNodeItemType
>
|
undefined
}
);
if
(
!
loopNode
)
return
;
const
rect
=
getNodesBounds
(
childNodes
);
// Calculate parent node size with minimum width/height constraints
const
width
=
Math
.
max
(
rect
.
width
+
80
,
840
);
const
height
=
Math
.
max
(
rect
.
height
+
80
,
600
);
const
offsetHeight
=
loopNode
.
data
.
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
loopNodeInputHeight
)
?.
value
??
83
;
// Update parentNode size and position
onChangeNode
({
nodeId
:
parentId
,
type
:
'updateInput'
,
key
:
NodeInputKeyEnum
.
nodeWidth
,
value
:
{
...
Input_Template_Node_Width
,
value
:
width
}
});
onChangeNode
({
nodeId
:
parentId
,
type
:
'updateInput'
,
key
:
NodeInputKeyEnum
.
nodeHeight
,
value
:
{
...
Input_Template_Node_Height
,
value
:
height
}
});
// Update parentNode position
onNodesChange
([
{
id
:
parentId
,
type
:
'position'
,
position
:
{
x
:
rect
.
x
-
70
,
y
:
rect
.
y
-
offsetHeight
-
240
}
}
]);
});
const
{
resetParentNodeSizeAndPosition
}
=
useLoopNode
();
/* helper line */
const
[
helperLineHorizontal
,
setHelperLineHorizontal
]
=
useState
<
THelperLine
>
();
...
...
@@ -704,7 +648,7 @@ export const useWorkflow = () => {
chatConfig
:
appDetail
.
chatConfig
});
},
[
nodes
,
edges
,
appDetail
.
chatConfig
,
pushPastSnapshot
],
[
nodes
,
edges
,
appDetail
.
chatConfig
],
{
wait
:
500
}
);
...
...
@@ -721,7 +665,73 @@ export const useWorkflow = () => {
helperLineVertical
,
onNodeDragStop
,
onPaneContextMenu
,
onPaneClick
,
onPaneClick
};
};
export
const
useLoopNode
=
()
=>
{
const
nodes
=
useContextSelector
(
WorkflowInitContext
,
(
state
)
=>
state
.
nodes
);
const
onNodesChange
=
useContextSelector
(
WorkflowNodeEdgeContext
,
(
state
)
=>
state
.
onNodesChange
);
const
{
onChangeNode
}
=
useContextSelector
(
WorkflowContext
,
(
v
)
=>
v
);
const
resetParentNodeSizeAndPosition
=
useMemoizedFn
((
parentId
:
string
)
=>
{
const
{
childNodes
,
loopNode
}
=
nodes
.
reduce
(
(
acc
,
node
)
=>
{
if
(
node
.
data
.
parentNodeId
===
parentId
)
{
acc
.
childNodes
.
push
(
node
);
}
if
(
node
.
id
===
parentId
)
{
acc
.
loopNode
=
node
;
}
return
acc
;
},
{
childNodes
:
[]
as
Node
[],
loopNode
:
undefined
as
Node
<
FlowNodeItemType
>
|
undefined
}
);
if
(
!
loopNode
)
return
;
const
rect
=
getNodesBounds
(
childNodes
);
// Calculate parent node size with minimum width/height constraints
const
width
=
Math
.
max
(
rect
.
width
+
80
,
840
);
const
height
=
Math
.
max
(
rect
.
height
+
80
,
600
);
const
offsetHeight
=
loopNode
.
data
.
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
loopNodeInputHeight
)
?.
value
??
83
;
// Update parentNode size and position
onChangeNode
({
nodeId
:
parentId
,
type
:
'updateInput'
,
key
:
NodeInputKeyEnum
.
nodeWidth
,
value
:
{
...
Input_Template_Node_Width
,
value
:
width
}
});
onChangeNode
({
nodeId
:
parentId
,
type
:
'updateInput'
,
key
:
NodeInputKeyEnum
.
nodeHeight
,
value
:
{
...
Input_Template_Node_Height
,
value
:
height
}
});
// Update parentNode position
onNodesChange
([
{
id
:
parentId
,
type
:
'position'
,
position
:
{
x
:
rect
.
x
-
70
,
y
:
rect
.
y
-
offsetHeight
-
240
}
}
]);
});
return
{
resetParentNodeSizeAndPosition
};
};
...
...
projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/Loop/NodeLoop.tsx
View file @
c64d629a
...
...
@@ -31,7 +31,7 @@ import { getWorkflowGlobalVariables } from '@/web/core/workflow/utils';
import
{
AppContext
}
from
'../../../../context'
;
import
{
isValidArrayReferenceValue
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
ReferenceArrayValueType
}
from
'@fastgpt/global/core/workflow/type/io'
;
import
{
use
Workflow
}
from
'../../hooks/useWorkflow'
;
import
{
use
LoopNode
}
from
'../../hooks/useWorkflow'
;
import
{
useSize
}
from
'ahooks'
;
const
NodeLoop
=
({
data
,
selected
}:
NodeProps
<
FlowNodeItemType
>
)
=>
{
...
...
@@ -41,7 +41,7 @@ const NodeLoop = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
const
onChangeNode
=
useContextSelector
(
WorkflowContext
,
(
v
)
=>
v
.
onChangeNode
);
const
appDetail
=
useContextSelector
(
AppContext
,
(
v
)
=>
v
.
appDetail
);
const
{
resetParentNodeSizeAndPosition
}
=
use
Workflow
();
const
{
resetParentNodeSizeAndPosition
}
=
use
LoopNode
();
const
{
nodeWidth
,
...
...
@@ -50,8 +50,12 @@ const NodeLoop = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
loopNodeInputHeight
=
Input_Template_LOOP_NODE_OFFSET
}
=
useMemo
(()
=>
{
return
{
nodeWidth
:
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
nodeWidth
)?.
value
,
nodeHeight
:
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
nodeHeight
)?.
value
,
nodeWidth
:
Number
(
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
nodeWidth
)?.
value
?.
toFixed
(
0
)
),
nodeHeight
:
Number
(
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
nodeHeight
)?.
value
?.
toFixed
(
0
)
),
loopInputArray
:
inputs
.
find
((
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
loopInputArray
),
loopNodeInputHeight
:
inputs
.
find
(
(
input
)
=>
input
.
key
===
NodeInputKeyEnum
.
loopNodeInputHeight
...
...
projects/app/src/pages/app/detail/components/WorkflowComponents/context/index.tsx
View file @
c64d629a
...
...
@@ -2,7 +2,6 @@ import { postWorkflowDebug } from '@/web/core/workflow/api';
import
{
checkWorkflowNodeAndConnection
,
compareSnapshot
,
simplifyWorkflowNodes
,
storeEdgesRenderEdge
,
storeNode2FlowNode
}
from
'@/web/core/workflow/utils'
;
...
...
@@ -833,10 +832,10 @@ const WorkflowContextProvider = ({
if
(
past
.
length
>
1
)
{
forbiddenSaveSnapshot
.
current
=
true
;
const
firstPast
=
past
[
0
];
const
firstPast
=
past
[
1
];
resetSnapshot
(
firstPast
);
setFuture
((
future
)
=>
[
firstPast
,
...
future
]);
setFuture
((
future
)
=>
[
past
[
0
]
,
...
future
]);
setPast
((
past
)
=>
past
.
slice
(
1
));
}
});
...
...
@@ -937,10 +936,10 @@ const WorkflowContextProvider = ({
if
(
isInit
&&
past
.
length
===
0
)
{
setPast
([
{
nodes
:
nodes
,
edges
:
edges
,
title
:
t
(
`app:app.version_initial`
),
isSaved
:
true
,
nodes
:
simplifyWorkflowNodes
(
nodes
),
edges
,
chatConfig
:
e
.
chatConfig
||
appDetail
.
chatConfig
}
]);
...
...
projects/app/src/web/core/workflow/utils.ts
View file @
c64d629a
...
...
@@ -619,7 +619,6 @@ export const compareSnapshot = (
return
nodes
.
filter
((
node
)
=>
{
if
(
!
node
)
return
;
if
(
FlowNodeTypeEnum
.
systemConfig
===
node
.
type
)
return
;
return
true
;
})
...
...
@@ -634,7 +633,8 @@ export const compareSnapshot = (
key
:
input
.
key
,
selectedTypeIndex
:
input
.
selectedTypeIndex
??
0
,
renderTypeLis
:
input
.
renderTypeList
,
valueType
:
input
.
valueType
,
// set to arrayAny for loopInputArray to skip valueType comparison
valueType
:
input
.
key
===
NodeInputKeyEnum
.
loopInputArray
?
'arrayAny'
:
input
.
valueType
,
value
:
input
.
value
??
undefined
})),
outputs
:
node
.
data
.
outputs
.
map
((
item
:
FlowNodeOutputItemType
)
=>
({
...
...
@@ -661,13 +661,3 @@ export const compareSnapshot = (
return
isEqual
(
node1
,
node2
);
};
// remove node size
export
const
simplifyWorkflowNodes
=
(
nodes
:
Node
[])
=>
{
return
nodes
.
map
((
node
)
=>
({
id
:
node
.
id
,
type
:
node
.
type
,
position
:
node
.
position
,
data
:
node
.
data
}));
};
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