mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-03 18:50:37 +08:00
feat: init vars
This commit is contained in:
parent
ff9c36a244
commit
0ff890d3a0
@ -1,10 +1,10 @@
|
||||
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
||||
import { useWorkflowStore } from '../../workflow/store'
|
||||
import { useWorkflowVars as useDoFetchWorkflowVars } from '@/service/use-workflow'
|
||||
import { useWorkflowVars } from '@/service/use-workflow'
|
||||
import { useStoreApi } from 'reactflow'
|
||||
import type { Node } from '@/app/components/workflow/types'
|
||||
|
||||
const useWorkflowVars = () => {
|
||||
const useSetWorkflowVarsWithValue = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
const { setNodesWithInspectVars, appId } = workflowStore.getState()
|
||||
const store = useStoreApi()
|
||||
@ -13,6 +13,7 @@ const useWorkflowVars = () => {
|
||||
const { getNodes } = store.getState()
|
||||
const nodeArr = getNodes()
|
||||
const nodesKeyValue: Record<string, Node> = {}
|
||||
// TODO: handle conversation, env and system variables
|
||||
nodeArr.forEach((node) => {
|
||||
nodesKeyValue[node.id] = node
|
||||
})
|
||||
@ -44,9 +45,8 @@ const useWorkflowVars = () => {
|
||||
return nodeWithVar
|
||||
})
|
||||
setNodesWithInspectVars(res)
|
||||
console.log(res)
|
||||
}
|
||||
useDoFetchWorkflowVars(appId, 1, addNodeInfo)
|
||||
useWorkflowVars(appId, addNodeInfo)
|
||||
}
|
||||
|
||||
export default useWorkflowVars
|
||||
export default useSetWorkflowVarsWithValue
|
@ -82,7 +82,7 @@ import Confirm from '@/app/components/base/confirm'
|
||||
import DatasetsDetailProvider from './datasets-detail-store/provider'
|
||||
import { HooksStoreContextProvider } from './hooks-store'
|
||||
import type { Shape as HooksStoreShape } from './hooks-store'
|
||||
import useWorkflowVars from '../workflow-app/hooks/use-workflow-vars'
|
||||
import useSetWorkflowVarsWithValue from '../workflow-app/hooks/use-set-workflow-vars-with-value'
|
||||
|
||||
const nodeTypes = {
|
||||
[CUSTOM_NODE]: CustomNode,
|
||||
@ -274,7 +274,7 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
||||
})
|
||||
|
||||
useShortcuts()
|
||||
useWorkflowVars()
|
||||
useSetWorkflowVarsWithValue()
|
||||
|
||||
const store = useStoreApi()
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
|
@ -126,9 +126,9 @@ export const useLastRun = (appID: string, nodeId: string, enabled: boolean) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useWorkflowVars = (appId: string, pageAt: number, onSuccess: (data: VarInInspect[]) => void) => {
|
||||
export const useWorkflowVars = (appId: string, onSuccess: (data: VarInInspect[]) => void) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'variables', appId, pageAt],
|
||||
queryKey: [NAME_SPACE, 'variables', appId],
|
||||
queryFn: async () => {
|
||||
// TODO: mock data. and need to get the rest data if has more data
|
||||
await sleep(1000)
|
||||
|
Loading…
x
Reference in New Issue
Block a user