diff --git a/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts index 334f847bf6..d092ea6cef 100644 --- a/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts @@ -43,6 +43,8 @@ const useSetWorkflowVarsWithValue = () => { nodeType: node.data.type, title: node.data.title, vars: varsUnderTheNode, + isSingRunRunning: false, + isValueFetched: false, } return nodeWithVar }) diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts index 5b79d03683..35543f27f5 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -81,12 +81,20 @@ const useInspectVarsCrud = () => { } const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => { - await doEditInspectorVar({ - varId, - value, - }) - if (nodeId !== VarInInspectType.conversation && nodeId !== VarInInspectType.system) + if (nodeId === VarInInspectType.conversation) { + console.log('edit conversation var value', varId, value) + invalidateConversationVarValues() + } + else if (nodeId === VarInInspectType.system) { + invalidateSysVarValues() + } + else { + await doEditInspectorVar({ + varId, + value, + }) setInspectVarValue(nodeId, varId, value) + } }, [doEditInspectorVar, setInspectVarValue]) const [currNodeId, setCurrNodeId] = useState(null) diff --git a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts index fef174f48b..7e3b98dfc2 100644 --- a/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts +++ b/web/app/components/workflow/store/workflow/debug/inspect-vars-slice.ts @@ -58,8 +58,10 @@ export const createInspectVarsSlice: StateCreator = (set, const prevNodes = state.nodesWithInspectVars const nodes = produce(prevNodes, (draft) => { const index = prevNodes.findIndex(node => node.nodeId === nodeId) - if (index === -1) + if (index !== -1) { draft[index].vars = payload + draft[index].isValueFetched = true + } }) return { diff --git a/web/app/components/workflow/variable-inspect/panel.tsx b/web/app/components/workflow/variable-inspect/panel.tsx index 299e0d2dca..7c582a416f 100644 --- a/web/app/components/workflow/variable-inspect/panel.tsx +++ b/web/app/components/workflow/variable-inspect/panel.tsx @@ -1,5 +1,5 @@ import type { FC } from 'react' -import { useMemo, useState } from 'react' +import { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine, @@ -17,6 +17,7 @@ export type currentVarType = { nodeId: string nodeType: string title: string + isValueFetched?: boolean var: VarInInspect } @@ -33,12 +34,28 @@ const Panel: FC = () => { conversationVars, systemVars, nodesWithInspectVars, + fetchInspectVarValue, } = useCurrentVars() + const isEmpty = useMemo(() => { const allVars = [...environmentVariables, ...conversationVars, ...systemVars, ...nodesWithInspectVars] return allVars.length === 0 }, [environmentVariables, conversationVars, systemVars, nodesWithInspectVars]) + const isCurrentNodeVarValueFetching = useMemo(() => { + if (!currentNodeVar) return false + const targetNode = nodesWithInspectVars.find(node => node.nodeId === currentNodeVar.nodeId) + if (!targetNode) return false + return !targetNode.isValueFetched + }, [currentNodeVar, nodesWithInspectVars]) + + const handleNodeVarSelect = useCallback((node: currentVarType) => { + setCurrentNodeVar(node) + const targetNode = nodesWithInspectVars.find(n => n.nodeId === node.nodeId) + if (targetNode && !targetNode.isValueFetched) + fetchInspectVarValue([node.nodeId]) + }, [fetchInspectVarValue, nodesWithInspectVars]) + if (isEmpty) { return (
@@ -71,12 +88,13 @@ const Panel: FC = () => { >
{/* right */}
setShowLeftPanel(true)} /> diff --git a/web/app/components/workflow/variable-inspect/right.tsx b/web/app/components/workflow/variable-inspect/right.tsx index 761bdd8627..0bee911e0c 100644 --- a/web/app/components/workflow/variable-inspect/right.tsx +++ b/web/app/components/workflow/variable-inspect/right.tsx @@ -1,4 +1,3 @@ -// import { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiArrowGoBackLine, @@ -17,6 +16,7 @@ import Tooltip from '@/app/components/base/tooltip' import BlockIcon from '@/app/components/workflow/block-icon' import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' +import Loading from '@/app/components/base/loading' import type { currentVarType } from './panel' import { VarInInspectType } from '@/types/workflow' import cn from '@/utils/classnames' @@ -24,11 +24,13 @@ import cn from '@/utils/classnames' type Props = { currentNodeVar?: currentVarType handleOpenMenu: () => void + isValueFetching?: boolean } const Right = ({ currentNodeVar, handleOpenMenu, + isValueFetching, }: Props) => { const { t } = useTranslation() const bottomPanelWidth = useStore(s => s.bottomPanelWidth) @@ -115,7 +117,12 @@ const Right = ({ {/* content */}
{!currentNodeVar && } - {currentNodeVar && } + {isValueFetching && ( +
+ +
+ )} + {currentNodeVar && !isValueFetching && }
) diff --git a/web/app/components/workflow/variable-inspect/value-content.tsx b/web/app/components/workflow/variable-inspect/value-content.tsx index 0a738dce1f..3bc71da551 100644 --- a/web/app/components/workflow/variable-inspect/value-content.tsx +++ b/web/app/components/workflow/variable-inspect/value-content.tsx @@ -73,7 +73,7 @@ const ValueContent = ({ ? [currentVar.value] : []) } - }, [currentVar, showTextEditor, showJSONEditor, showFileEditor]) + }, [currentVar.id]) const handleTextChange = (value: string) => { if (currentVar.value_type === 'string') diff --git a/web/types/workflow.ts b/web/types/workflow.ts index dc45b982cc..7be20b2b10 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -395,6 +395,6 @@ export type NodeWithVar = { nodeType: BlockEnum title: string vars: VarInInspect[] - isFetchingValues?: boolean isSingRunRunning?: boolean + isValueFetched?: boolean }