fix: can not reset system variables (#21750)
This commit is contained in:
@@ -11,12 +11,11 @@ import {
|
|||||||
useEditInspectorVar,
|
useEditInspectorVar,
|
||||||
useInvalidateConversationVarValues,
|
useInvalidateConversationVarValues,
|
||||||
useInvalidateSysVarValues,
|
useInvalidateSysVarValues,
|
||||||
useLastRun,
|
|
||||||
useResetConversationVar,
|
useResetConversationVar,
|
||||||
useResetToLastRunValue,
|
useResetToLastRunValue,
|
||||||
useSysVarValues,
|
useSysVarValues,
|
||||||
} from '@/service/use-workflow'
|
} from '@/service/use-workflow'
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { isConversationVar, isENV, isSystemVar } from '../nodes/_base/components/variable/utils'
|
import { isConversationVar, isENV, isSystemVar } from '../nodes/_base/components/variable/utils'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { Node } from '@/app/components/workflow/types'
|
import type { Node } from '@/app/components/workflow/types'
|
||||||
@@ -123,6 +122,7 @@ const useInspectVarsCrud = () => {
|
|||||||
nodeType: nodeInfo.data.type,
|
nodeType: nodeInfo.data.type,
|
||||||
title: nodeInfo.data.title,
|
title: nodeInfo.data.title,
|
||||||
vars: payload,
|
vars: payload,
|
||||||
|
nodePayload: nodeInfo.data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -180,16 +180,6 @@ const useInspectVarsCrud = () => {
|
|||||||
invalidateSysVarValues()
|
invalidateSysVarValues()
|
||||||
}, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarValue])
|
}, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarValue])
|
||||||
|
|
||||||
const [currNodeId, setCurrNodeId] = useState<string | null>(null)
|
|
||||||
const [currEditVarId, setCurrEditVarId] = useState<string | null>(null)
|
|
||||||
const { data } = useLastRun(appId, currNodeId || '', !!currNodeId)
|
|
||||||
useEffect(() => {
|
|
||||||
if (data && currNodeId && currEditVarId) {
|
|
||||||
const inspectVar = getNodeInspectVars(currNodeId)?.vars?.find(item => item.id === currEditVarId)
|
|
||||||
resetToLastRunVarInStore(currNodeId, currEditVarId, data.outputs?.[inspectVar?.selector?.[1] || ''])
|
|
||||||
}
|
|
||||||
}, [data, currNodeId, currEditVarId, getNodeInspectVars, editInspectVarValue, resetToLastRunVarInStore])
|
|
||||||
|
|
||||||
const renameInspectVarName = async (nodeId: string, oldName: string, newName: string) => {
|
const renameInspectVarName = async (nodeId: string, oldName: string, newName: string) => {
|
||||||
const varId = getVarId(nodeId, oldName)
|
const varId = getVarId(nodeId, oldName)
|
||||||
if (!varId)
|
if (!varId)
|
||||||
@@ -212,9 +202,13 @@ const useInspectVarsCrud = () => {
|
|||||||
}, [getInspectVar])
|
}, [getInspectVar])
|
||||||
|
|
||||||
const resetToLastRunVar = async (nodeId: string, varId: string) => {
|
const resetToLastRunVar = async (nodeId: string, varId: string) => {
|
||||||
await doResetToLastRunValue(varId)
|
const isSysVar = nodeId === 'sys'
|
||||||
setCurrNodeId(nodeId)
|
const data = await doResetToLastRunValue(varId)
|
||||||
setCurrEditVarId(varId)
|
|
||||||
|
if(isSysVar)
|
||||||
|
invalidateSysVarValues()
|
||||||
|
else
|
||||||
|
resetToLastRunVarInStore(nodeId, varId, data.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@@ -139,7 +139,7 @@ export const useResetConversationVar = (appId: string) => {
|
|||||||
export const useResetToLastRunValue = (appId: string) => {
|
export const useResetToLastRunValue = (appId: string) => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: [NAME_SPACE, 'reset to last run value', appId],
|
mutationKey: [NAME_SPACE, 'reset to last run value', appId],
|
||||||
mutationFn: async (varId: string) => {
|
mutationFn: async (varId: string): Promise<{ value: any }> => {
|
||||||
return put(`apps/${appId}/workflows/draft/variables/${varId}/reset`)
|
return put(`apps/${appId}/workflows/draft/variables/${varId}/reset`)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user