mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-05 15:10:40 +08:00
feat: single run set datas
This commit is contained in:
parent
33258f1acf
commit
e848c0c1d8
@ -152,7 +152,19 @@ const useOneStepRun = <T>({
|
||||
}, [])
|
||||
const iterationTimes = iteratorInputKey ? runInputData[iteratorInputKey].length : 0
|
||||
const loopTimes = loopInputKey ? runInputData[loopInputKey].length : 0
|
||||
const [runResult, setRunResult] = useState<NodeRunResult | null>(null)
|
||||
|
||||
const workflowStore = useWorkflowStore()
|
||||
const {
|
||||
setLastRunNodeInfo,
|
||||
setCurrentNodeVars,
|
||||
setShowSingleRunPanel,
|
||||
} = workflowStore.getState()
|
||||
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
|
||||
const setRunResult = useCallback((data: NodeRunResult | null) => {
|
||||
doSetRunResult(data)
|
||||
setLastRunNodeInfo(id, data as any)
|
||||
setCurrentNodeVars(id, data as any)
|
||||
}, [id, setLastRunNodeInfo, setCurrentNodeVars])
|
||||
|
||||
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate()
|
||||
const [canShowSingleRun, setCanShowSingleRun] = useState(false)
|
||||
@ -186,10 +198,9 @@ const useOneStepRun = <T>({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [data._isSingleRun])
|
||||
|
||||
const workflowStore = useWorkflowStore()
|
||||
useEffect(() => {
|
||||
workflowStore.getState().setShowSingleRunPanel(!!isShowSingleRun)
|
||||
}, [isShowSingleRun, workflowStore])
|
||||
setShowSingleRunPanel(!!isShowSingleRun)
|
||||
}, [isShowSingleRun, setShowSingleRunPanel])
|
||||
|
||||
const hideSingleRun = () => {
|
||||
handleNodeDataUpdate({
|
||||
|
@ -33,9 +33,8 @@ const Panel = forwardRef<PanelExposedType, NodePanelProps<LLMNodeType>>(({
|
||||
const { t } = useTranslation()
|
||||
const {
|
||||
currentVars,
|
||||
getLastRunInfos,
|
||||
} = useCurrentVars()
|
||||
// console.log(currentVars, getLastRunInfos())
|
||||
console.log(currentVars)
|
||||
const {
|
||||
readOnly,
|
||||
inputs,
|
||||
|
@ -41,14 +41,15 @@ export const createCurrentVarsSlice: StateCreator<CurrentVarsSliceShape> = (set,
|
||||
},
|
||||
setCurrentNodeVars: (nodeId, payload) => {
|
||||
set((state) => {
|
||||
const nodes = state.currentNodes.map((node) => {
|
||||
// eslint-disable-next-line curly
|
||||
if (node.node_id === nodeId) {
|
||||
return payload
|
||||
}
|
||||
|
||||
return node
|
||||
const prevNodes = state.currentNodes
|
||||
const nodes = produce(prevNodes, (draft) => {
|
||||
const index = prevNodes.findIndex(node => node.id === nodeId)
|
||||
if (index === -1)
|
||||
draft.push(payload)
|
||||
else
|
||||
draft[index] = payload
|
||||
})
|
||||
|
||||
return {
|
||||
currentNodes: nodes,
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import type { NodeTracing } from '@/types/workflow'
|
||||
import produce from 'immer'
|
||||
import type { StateCreator } from 'zustand'
|
||||
|
||||
type NodeInfo = NodeTracing
|
||||
@ -10,6 +11,7 @@ type LastRunState = {
|
||||
type LastRunActions = {
|
||||
setLastRunInfos: (vars: NodeInfo[]) => void
|
||||
getLastRunInfos: () => NodeInfo[]
|
||||
setLastRunNodeInfo: (nodeId: string, payload: NodeInfo) => void
|
||||
getLastRunNodeInfo: (nodeId: string) => NodeInfo | undefined
|
||||
getLastRunVar: (nodeId: string, key: string) => any
|
||||
}
|
||||
@ -32,6 +34,22 @@ export const createLastRunSlice: StateCreator<LastRunSliceShape> = (set, get) =>
|
||||
nodes: [],
|
||||
}))
|
||||
},
|
||||
setLastRunNodeInfo: (nodeId, payload) => {
|
||||
set((state) => {
|
||||
const prevNodes = state.nodes
|
||||
const nodes = produce(prevNodes, (draft) => {
|
||||
const index = prevNodes.findIndex(node => node.id === nodeId)
|
||||
if (index === -1)
|
||||
draft.push(payload)
|
||||
else
|
||||
draft[index] = payload
|
||||
})
|
||||
|
||||
return {
|
||||
nodes,
|
||||
}
|
||||
})
|
||||
},
|
||||
getLastRunNodeInfo: (nodeId) => {
|
||||
const nodes = get().nodes
|
||||
return nodes.find(node => node.node_id === nodeId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user