Kaynağa Gözat

fix(workflow/if-else): keep conditions in sync on variable rename (#23611)

Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: crazywoola <427733928@qq.com>
tags/1.8.0
Rajhans Jadhao 2 ay önce
ebeveyn
işleme
8d47213529
No account linked to committer's email address

+ 5
- 5
web/app/components/workflow/hooks/use-workflow.ts Dosyayı Görüntüle



const handleOutVarRenameChange = useCallback((nodeId: string, oldValeSelector: ValueSelector, newVarSelector: ValueSelector) => { const handleOutVarRenameChange = useCallback((nodeId: string, oldValeSelector: ValueSelector, newVarSelector: ValueSelector) => {
const { getNodes, setNodes } = store.getState() const { getNodes, setNodes } = store.getState()
const afterNodes = getAfterNodesInSameBranch(nodeId)
const effectNodes = findUsedVarNodes(oldValeSelector, afterNodes)
if (effectNodes.length > 0) {
const newNodes = getNodes().map((node) => {
if (effectNodes.find(n => n.id === node.id))
const allNodes = getNodes()
const affectedNodes = findUsedVarNodes(oldValeSelector, allNodes)
if (affectedNodes.length > 0) {
const newNodes = allNodes.map((node) => {
if (affectedNodes.find(n => n.id === node.id))
return updateNodeVars(node, oldValeSelector, newVarSelector) return updateNodeVars(node, oldValeSelector, newVarSelector)


return node return node

+ 29
- 1
web/app/components/workflow/nodes/_base/components/variable/utils.ts Dosyayı Görüntüle

res = (data as IfElseNodeType).conditions?.map((c) => { res = (data as IfElseNodeType).conditions?.map((c) => {
return c.variable_selector || [] return c.variable_selector || []
}) || [] }) || []
res.push(...((data as IfElseNodeType).cases || []).flatMap(c => (c.conditions || [])).map(c => c.variable_selector || []))
res.push(...((data as IfElseNodeType).cases || []).flatMap(c => (c.conditions || [])).flatMap((c) => {
const selectors: ValueSelector[] = []
if (c.variable_selector)
selectors.push(c.variable_selector)
// Handle sub-variable conditions
if (c.sub_variable_condition && c.sub_variable_condition.conditions)
selectors.push(...c.sub_variable_condition.conditions.map(subC => subC.variable_selector || []).filter(sel => sel.length > 0))
return selectors
}))
break break
} }
case BlockEnum.Code: { case BlockEnum.Code: {
return c return c
}) })
} }
if (payload.cases) {
payload.cases = payload.cases.map((caseItem) => {
if (caseItem.conditions) {
caseItem.conditions = caseItem.conditions.map((c) => {
if (c.variable_selector?.join('.') === oldVarSelector.join('.'))
c.variable_selector = newVarSelector
// Handle sub-variable conditions
if (c.sub_variable_condition && c.sub_variable_condition.conditions) {
c.sub_variable_condition.conditions = c.sub_variable_condition.conditions.map((subC) => {
if (subC.variable_selector?.join('.') === oldVarSelector.join('.'))
subC.variable_selector = newVarSelector
return subC
})
}
return c
})
}
return caseItem
})
}
break break
} }
case BlockEnum.Code: { case BlockEnum.Code: {

Loading…
İptal
Kaydet