|
|
|
@ -24,14 +24,6 @@ import { useConfigsMap } from './use-configs-map'
|
|
|
|
export const useInspectVarsCrud = () => {
|
|
|
|
export const useInspectVarsCrud = () => {
|
|
|
|
const workflowStore = useWorkflowStore()
|
|
|
|
const workflowStore = useWorkflowStore()
|
|
|
|
const appId = useStore(s => s.appId)
|
|
|
|
const appId = useStore(s => s.appId)
|
|
|
|
const setNodeInspectVars = useStore(s => s.setNodeInspectVars)
|
|
|
|
|
|
|
|
const setInspectVarValue = useStore(s => s.setInspectVarValue)
|
|
|
|
|
|
|
|
const renameInspectVarNameInStore = useStore(s => s.renameInspectVarName)
|
|
|
|
|
|
|
|
const deleteAllInspectVarsInStore = useStore(s => s.deleteAllInspectVars)
|
|
|
|
|
|
|
|
const deleteNodeInspectVarsInStore = useStore(s => s.deleteNodeInspectVars)
|
|
|
|
|
|
|
|
const deleteInspectVarInStore = useStore(s => s.deleteInspectVar)
|
|
|
|
|
|
|
|
const setNodesWithInspectVars = useStore(s => s.setNodesWithInspectVars)
|
|
|
|
|
|
|
|
const resetToLastRunVarInStore = useStore(s => s.resetToLastRunVar)
|
|
|
|
|
|
|
|
const { conversationVarsUrl, systemVarsUrl } = useConfigsMap()
|
|
|
|
const { conversationVarsUrl, systemVarsUrl } = useConfigsMap()
|
|
|
|
const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl)
|
|
|
|
const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl)
|
|
|
|
const { mutateAsync: doResetConversationVar } = useResetConversationVar(appId)
|
|
|
|
const { mutateAsync: doResetConversationVar } = useResetConversationVar(appId)
|
|
|
|
@ -90,6 +82,10 @@ export const useInspectVarsCrud = () => {
|
|
|
|
}, [getNodeInspectVars])
|
|
|
|
}, [getNodeInspectVars])
|
|
|
|
|
|
|
|
|
|
|
|
const fetchInspectVarValue = useCallback(async (selector: ValueSelector) => {
|
|
|
|
const fetchInspectVarValue = useCallback(async (selector: ValueSelector) => {
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
appId,
|
|
|
|
|
|
|
|
setNodeInspectVars,
|
|
|
|
|
|
|
|
} = workflowStore.getState()
|
|
|
|
const nodeId = selector[0]
|
|
|
|
const nodeId = selector[0]
|
|
|
|
const isSystemVar = nodeId === 'sys'
|
|
|
|
const isSystemVar = nodeId === 'sys'
|
|
|
|
const isConversationVar = nodeId === 'conversation'
|
|
|
|
const isConversationVar = nodeId === 'conversation'
|
|
|
|
@ -103,11 +99,14 @@ export const useInspectVarsCrud = () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const vars = await fetchNodeInspectVars(appId, nodeId)
|
|
|
|
const vars = await fetchNodeInspectVars(appId, nodeId)
|
|
|
|
setNodeInspectVars(nodeId, vars)
|
|
|
|
setNodeInspectVars(nodeId, vars)
|
|
|
|
}, [appId, invalidateSysVarValues, invalidateConversationVarValues, setNodeInspectVars])
|
|
|
|
}, [workflowStore, invalidateSysVarValues, invalidateConversationVarValues])
|
|
|
|
|
|
|
|
|
|
|
|
// after last run would call this
|
|
|
|
// after last run would call this
|
|
|
|
const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => {
|
|
|
|
const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => {
|
|
|
|
const { nodesWithInspectVars } = workflowStore.getState()
|
|
|
|
const {
|
|
|
|
|
|
|
|
nodesWithInspectVars,
|
|
|
|
|
|
|
|
setNodesWithInspectVars,
|
|
|
|
|
|
|
|
} = workflowStore.getState()
|
|
|
|
const nodes = produce(nodesWithInspectVars, (draft) => {
|
|
|
|
const nodes = produce(nodesWithInspectVars, (draft) => {
|
|
|
|
const nodeInfo = allNodes.find(node => node.id === nodeId)
|
|
|
|
const nodeInfo = allNodes.find(node => node.id === nodeId)
|
|
|
|
if (nodeInfo) {
|
|
|
|
if (nodeInfo) {
|
|
|
|
@ -128,7 +127,7 @@ export const useInspectVarsCrud = () => {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
setNodesWithInspectVars(nodes)
|
|
|
|
setNodesWithInspectVars(nodes)
|
|
|
|
handleCancelNodeSuccessStatus(nodeId)
|
|
|
|
handleCancelNodeSuccessStatus(nodeId)
|
|
|
|
}, [workflowStore, setNodesWithInspectVars, handleCancelNodeSuccessStatus])
|
|
|
|
}, [workflowStore, handleCancelNodeSuccessStatus])
|
|
|
|
|
|
|
|
|
|
|
|
const hasNodeInspectVar = useCallback((nodeId: string, varId: string) => {
|
|
|
|
const hasNodeInspectVar = useCallback((nodeId: string, varId: string) => {
|
|
|
|
const { nodesWithInspectVars } = workflowStore.getState()
|
|
|
|
const { nodesWithInspectVars } = workflowStore.getState()
|
|
|
|
@ -139,11 +138,12 @@ export const useInspectVarsCrud = () => {
|
|
|
|
}, [workflowStore])
|
|
|
|
}, [workflowStore])
|
|
|
|
|
|
|
|
|
|
|
|
const deleteInspectVar = useCallback(async (nodeId: string, varId: string) => {
|
|
|
|
const deleteInspectVar = useCallback(async (nodeId: string, varId: string) => {
|
|
|
|
|
|
|
|
const { deleteInspectVar } = workflowStore.getState()
|
|
|
|
if(hasNodeInspectVar(nodeId, varId)) {
|
|
|
|
if(hasNodeInspectVar(nodeId, varId)) {
|
|
|
|
await doDeleteInspectVar(varId)
|
|
|
|
await doDeleteInspectVar(varId)
|
|
|
|
deleteInspectVarInStore(nodeId, varId)
|
|
|
|
deleteInspectVar(nodeId, varId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [doDeleteInspectVar, deleteInspectVarInStore, hasNodeInspectVar])
|
|
|
|
}, [doDeleteInspectVar, workflowStore, hasNodeInspectVar])
|
|
|
|
|
|
|
|
|
|
|
|
const resetConversationVar = useCallback(async (varId: string) => {
|
|
|
|
const resetConversationVar = useCallback(async (varId: string) => {
|
|
|
|
await doResetConversationVar(varId)
|
|
|
|
await doResetConversationVar(varId)
|
|
|
|
@ -151,21 +151,24 @@ export const useInspectVarsCrud = () => {
|
|
|
|
}, [doResetConversationVar, invalidateConversationVarValues])
|
|
|
|
}, [doResetConversationVar, invalidateConversationVarValues])
|
|
|
|
|
|
|
|
|
|
|
|
const deleteNodeInspectorVars = useCallback(async (nodeId: string) => {
|
|
|
|
const deleteNodeInspectorVars = useCallback(async (nodeId: string) => {
|
|
|
|
|
|
|
|
const { deleteNodeInspectVars } = workflowStore.getState()
|
|
|
|
if (hasNodeInspectVars(nodeId)) {
|
|
|
|
if (hasNodeInspectVars(nodeId)) {
|
|
|
|
await doDeleteNodeInspectorVars(nodeId)
|
|
|
|
await doDeleteNodeInspectorVars(nodeId)
|
|
|
|
deleteNodeInspectVarsInStore(nodeId)
|
|
|
|
deleteNodeInspectVars(nodeId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [doDeleteNodeInspectorVars, deleteNodeInspectVarsInStore, hasNodeInspectVars])
|
|
|
|
}, [doDeleteNodeInspectorVars, workflowStore, hasNodeInspectVars])
|
|
|
|
|
|
|
|
|
|
|
|
const deleteAllInspectorVars = useCallback(async () => {
|
|
|
|
const deleteAllInspectorVars = useCallback(async () => {
|
|
|
|
|
|
|
|
const { deleteAllInspectVars } = workflowStore.getState()
|
|
|
|
await doDeleteAllInspectorVars()
|
|
|
|
await doDeleteAllInspectorVars()
|
|
|
|
await invalidateConversationVarValues()
|
|
|
|
await invalidateConversationVarValues()
|
|
|
|
await invalidateSysVarValues()
|
|
|
|
await invalidateSysVarValues()
|
|
|
|
deleteAllInspectVarsInStore()
|
|
|
|
deleteAllInspectVars()
|
|
|
|
handleEdgeCancelRunningStatus()
|
|
|
|
handleEdgeCancelRunningStatus()
|
|
|
|
}, [doDeleteAllInspectorVars, invalidateConversationVarValues, invalidateSysVarValues, deleteAllInspectVarsInStore, handleEdgeCancelRunningStatus])
|
|
|
|
}, [doDeleteAllInspectorVars, invalidateConversationVarValues, invalidateSysVarValues, workflowStore, handleEdgeCancelRunningStatus])
|
|
|
|
|
|
|
|
|
|
|
|
const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => {
|
|
|
|
const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => {
|
|
|
|
|
|
|
|
const { setInspectVarValue } = workflowStore.getState()
|
|
|
|
await doEditInspectorVar({
|
|
|
|
await doEditInspectorVar({
|
|
|
|
varId,
|
|
|
|
varId,
|
|
|
|
value,
|
|
|
|
value,
|
|
|
|
@ -175,9 +178,10 @@ export const useInspectVarsCrud = () => {
|
|
|
|
invalidateConversationVarValues()
|
|
|
|
invalidateConversationVarValues()
|
|
|
|
if (nodeId === VarInInspectType.system)
|
|
|
|
if (nodeId === VarInInspectType.system)
|
|
|
|
invalidateSysVarValues()
|
|
|
|
invalidateSysVarValues()
|
|
|
|
}, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, setInspectVarValue])
|
|
|
|
}, [doEditInspectorVar, invalidateConversationVarValues, invalidateSysVarValues, workflowStore])
|
|
|
|
|
|
|
|
|
|
|
|
const renameInspectVarName = useCallback(async (nodeId: string, oldName: string, newName: string) => {
|
|
|
|
const renameInspectVarName = useCallback(async (nodeId: string, oldName: string, newName: string) => {
|
|
|
|
|
|
|
|
const { renameInspectVarName } = workflowStore.getState()
|
|
|
|
const varId = getVarId(nodeId, oldName)
|
|
|
|
const varId = getVarId(nodeId, oldName)
|
|
|
|
if (!varId)
|
|
|
|
if (!varId)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
@ -187,8 +191,8 @@ export const useInspectVarsCrud = () => {
|
|
|
|
varId,
|
|
|
|
varId,
|
|
|
|
name: newName,
|
|
|
|
name: newName,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
renameInspectVarNameInStore(nodeId, varId, newSelector)
|
|
|
|
renameInspectVarName(nodeId, varId, newSelector)
|
|
|
|
}, [doEditInspectorVar, getVarId, renameInspectVarNameInStore])
|
|
|
|
}, [doEditInspectorVar, getVarId, workflowStore])
|
|
|
|
|
|
|
|
|
|
|
|
const isInspectVarEdited = useCallback((nodeId: string, name: string) => {
|
|
|
|
const isInspectVarEdited = useCallback((nodeId: string, name: string) => {
|
|
|
|
const inspectVar = getInspectVar(nodeId, name)
|
|
|
|
const inspectVar = getInspectVar(nodeId, name)
|
|
|
|
@ -199,14 +203,15 @@ export const useInspectVarsCrud = () => {
|
|
|
|
}, [getInspectVar])
|
|
|
|
}, [getInspectVar])
|
|
|
|
|
|
|
|
|
|
|
|
const resetToLastRunVar = useCallback(async (nodeId: string, varId: string) => {
|
|
|
|
const resetToLastRunVar = useCallback(async (nodeId: string, varId: string) => {
|
|
|
|
|
|
|
|
const { resetToLastRunVar } = workflowStore.getState()
|
|
|
|
const isSysVar = nodeId === 'sys'
|
|
|
|
const isSysVar = nodeId === 'sys'
|
|
|
|
const data = await doResetToLastRunValue(varId)
|
|
|
|
const data = await doResetToLastRunValue(varId)
|
|
|
|
|
|
|
|
|
|
|
|
if(isSysVar)
|
|
|
|
if(isSysVar)
|
|
|
|
invalidateSysVarValues()
|
|
|
|
invalidateSysVarValues()
|
|
|
|
else
|
|
|
|
else
|
|
|
|
resetToLastRunVarInStore(nodeId, varId, data.value)
|
|
|
|
resetToLastRunVar(nodeId, varId, data.value)
|
|
|
|
}, [doResetToLastRunValue, invalidateSysVarValues, resetToLastRunVarInStore])
|
|
|
|
}, [doResetToLastRunValue, invalidateSysVarValues, workflowStore])
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
hasNodeInspectVars,
|
|
|
|
hasNodeInspectVars,
|
|
|
|
|