value of var in node fetching

pull/21369/head
jZonG 1 year ago
parent e6001c259b
commit 8a910a40a4

@ -43,6 +43,8 @@ const useSetWorkflowVarsWithValue = () => {
nodeType: node.data.type, nodeType: node.data.type,
title: node.data.title, title: node.data.title,
vars: varsUnderTheNode, vars: varsUnderTheNode,
isSingRunRunning: false,
isValueFetched: false,
} }
return nodeWithVar return nodeWithVar
}) })

@ -81,12 +81,20 @@ const useInspectVarsCrud = () => {
} }
const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => { const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => {
await doEditInspectorVar({ if (nodeId === VarInInspectType.conversation) {
varId, console.log('edit conversation var value', varId, value)
value, invalidateConversationVarValues()
}) }
if (nodeId !== VarInInspectType.conversation && nodeId !== VarInInspectType.system) else if (nodeId === VarInInspectType.system) {
invalidateSysVarValues()
}
else {
await doEditInspectorVar({
varId,
value,
})
setInspectVarValue(nodeId, varId, value) setInspectVarValue(nodeId, varId, value)
}
}, [doEditInspectorVar, setInspectVarValue]) }, [doEditInspectorVar, setInspectVarValue])
const [currNodeId, setCurrNodeId] = useState<string | null>(null) const [currNodeId, setCurrNodeId] = useState<string | null>(null)

@ -58,8 +58,10 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
const prevNodes = state.nodesWithInspectVars const prevNodes = state.nodesWithInspectVars
const nodes = produce(prevNodes, (draft) => { const nodes = produce(prevNodes, (draft) => {
const index = prevNodes.findIndex(node => node.nodeId === nodeId) const index = prevNodes.findIndex(node => node.nodeId === nodeId)
if (index === -1) if (index !== -1) {
draft[index].vars = payload draft[index].vars = payload
draft[index].isValueFetched = true
}
}) })
return { return {

@ -1,5 +1,5 @@
import type { FC } from 'react' import type { FC } from 'react'
import { useMemo, useState } from 'react' import { useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { import {
RiCloseLine, RiCloseLine,
@ -17,6 +17,7 @@ export type currentVarType = {
nodeId: string nodeId: string
nodeType: string nodeType: string
title: string title: string
isValueFetched?: boolean
var: VarInInspect var: VarInInspect
} }
@ -33,12 +34,28 @@ const Panel: FC = () => {
conversationVars, conversationVars,
systemVars, systemVars,
nodesWithInspectVars, nodesWithInspectVars,
fetchInspectVarValue,
} = useCurrentVars() } = useCurrentVars()
const isEmpty = useMemo(() => { const isEmpty = useMemo(() => {
const allVars = [...environmentVariables, ...conversationVars, ...systemVars, ...nodesWithInspectVars] const allVars = [...environmentVariables, ...conversationVars, ...systemVars, ...nodesWithInspectVars]
return allVars.length === 0 return allVars.length === 0
}, [environmentVariables, conversationVars, systemVars, nodesWithInspectVars]) }, [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) { if (isEmpty) {
return ( return (
<div className={cn('flex h-full flex-col')}> <div className={cn('flex h-full flex-col')}>
@ -71,12 +88,13 @@ const Panel: FC = () => {
> >
<Left <Left
currentNodeVar={currentNodeVar} currentNodeVar={currentNodeVar}
handleVarSelect={setCurrentNodeVar} handleVarSelect={handleNodeVarSelect}
/> />
</div> </div>
{/* right */} {/* right */}
<div className='w-0 grow'> <div className='w-0 grow'>
<Right <Right
isValueFetching={isCurrentNodeVarValueFetching}
currentNodeVar={currentNodeVar} currentNodeVar={currentNodeVar}
handleOpenMenu={() => setShowLeftPanel(true)} handleOpenMenu={() => setShowLeftPanel(true)}
/> />

@ -1,4 +1,3 @@
// import { useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { import {
RiArrowGoBackLine, RiArrowGoBackLine,
@ -17,6 +16,7 @@ import Tooltip from '@/app/components/base/tooltip'
import BlockIcon from '@/app/components/workflow/block-icon' import BlockIcon from '@/app/components/workflow/block-icon'
import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others'
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
import Loading from '@/app/components/base/loading'
import type { currentVarType } from './panel' import type { currentVarType } from './panel'
import { VarInInspectType } from '@/types/workflow' import { VarInInspectType } from '@/types/workflow'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
@ -24,11 +24,13 @@ import cn from '@/utils/classnames'
type Props = { type Props = {
currentNodeVar?: currentVarType currentNodeVar?: currentVarType
handleOpenMenu: () => void handleOpenMenu: () => void
isValueFetching?: boolean
} }
const Right = ({ const Right = ({
currentNodeVar, currentNodeVar,
handleOpenMenu, handleOpenMenu,
isValueFetching,
}: Props) => { }: Props) => {
const { t } = useTranslation() const { t } = useTranslation()
const bottomPanelWidth = useStore(s => s.bottomPanelWidth) const bottomPanelWidth = useStore(s => s.bottomPanelWidth)
@ -115,7 +117,12 @@ const Right = ({
{/* content */} {/* content */}
<div className='grow p-2'> <div className='grow p-2'>
{!currentNodeVar && <Empty />} {!currentNodeVar && <Empty />}
{currentNodeVar && <ValueContent currentVar={currentNodeVar.var} handleValueChange={handleValueChange} />} {isValueFetching && (
<div className='flex h-full items-center justify-center'>
<Loading />
</div>
)}
{currentNodeVar && !isValueFetching && <ValueContent currentVar={currentNodeVar.var} handleValueChange={handleValueChange} />}
</div> </div>
</div> </div>
) )

@ -73,7 +73,7 @@ const ValueContent = ({
? [currentVar.value] ? [currentVar.value]
: []) : [])
} }
}, [currentVar, showTextEditor, showJSONEditor, showFileEditor]) }, [currentVar.id])
const handleTextChange = (value: string) => { const handleTextChange = (value: string) => {
if (currentVar.value_type === 'string') if (currentVar.value_type === 'string')

@ -395,6 +395,6 @@ export type NodeWithVar = {
nodeType: BlockEnum nodeType: BlockEnum
title: string title: string
vars: VarInInspect[] vars: VarInInspect[]
isFetchingValues?: boolean
isSingRunRunning?: boolean isSingRunRunning?: boolean
isValueFetched?: boolean
} }

Loading…
Cancel
Save