chore: change init value

This commit is contained in:
Joel 2025-04-27 14:12:23 +08:00
parent 135f27b19b
commit bc45c0904a
5 changed files with 31 additions and 24 deletions

View File

@ -1,8 +1,8 @@
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
import { useWorkflowStore } from '../../workflow/store'
import { useWorkflowVars } from '@/service/use-workflow'
import { useStoreApi } from 'reactflow'
import type { Node } from '@/app/components/workflow/types'
import { fetchAllInspectVars } from '@/service/workflow'
const useSetWorkflowVarsWithValue = () => {
const workflowStore = useWorkflowStore()
@ -46,7 +46,14 @@ const useSetWorkflowVarsWithValue = () => {
})
setNodesWithInspectVars(res)
}
useWorkflowVars(appId, addNodeInfo)
const fetchInspectVars = async () => {
const data = await fetchAllInspectVars(appId)
addNodeInfo(data)
}
return {
fetchInspectVars,
}
}
export default useSetWorkflowVarsWithValue

View File

@ -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 useSetWorkflowVarsWithValue from '../workflow-app/hooks/use-set-workflow-vars-with-value'
import useSetWorkflowVarsWithValue from '../workflow-app/hooks/use-fetch-workflow-inspect-vars'
const nodeTypes = {
[CUSTOM_NODE]: CustomNode,
@ -274,7 +274,11 @@ export const Workflow: FC<WorkflowProps> = memo(({
})
useShortcuts()
useSetWorkflowVarsWithValue()
const { fetchInspectVars } = useSetWorkflowVarsWithValue()
useEffect(() => {
fetchInspectVars()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const store = useStoreApi()
if (process.env.NODE_ENV === 'development') {

View File

@ -7,13 +7,11 @@ import type {
NodeTracing,
PublishWorkflowParams,
UpdateWorkflowParams,
VarInInspect,
WorkflowConfigResponse,
} from '@/types/workflow'
import type { CommonResponse } from '@/models/common'
import { useReset } from './use-base'
import { sleep } from '@/utils'
import { vars } from '@/app/components/workflow/store/workflow/debug/mock-data'
const NAME_SPACE = 'workflow'
@ -125,20 +123,3 @@ export const useLastRun = (appID: string, nodeId: string, enabled: boolean) => {
},
})
}
export const useWorkflowVars = (appId: string, onSuccess: (data: VarInInspect[]) => void) => {
return useQuery({
queryKey: [NAME_SPACE, 'variables', appId],
queryFn: async () => {
// TODO: mock data. and need to get the rest data if has more data
await sleep(1000)
const data = await Promise.resolve({
items: vars,
total: 1,
})
onSuccess(data.items)
return data
},
})
}

View File

@ -9,6 +9,9 @@ import type {
WorkflowRunHistoryResponse,
} from '@/types/workflow'
import type { BlockEnum } from '@/app/components/workflow/types'
import { sleep } from '@/utils'
import { vars } from '@/app/components/workflow/store/workflow/debug/mock-data'
import type { VarInInspect } from '@/types/workflow'
export const fetchWorkflowDraft = (url: string) => {
return get(url, {}, { silent: true }) as Promise<FetchWorkflowDraftResponse>
@ -70,3 +73,15 @@ export const fetchCurrentValueOfConversationVariable: Fetcher<ConversationVariab
}> = ({ url, params }) => {
return get<ConversationVariableResponse>(url, { params })
}
export const fetchAllInspectVars = async (appId: string): Promise<VarInInspect[]> => {
// TODO: mock data. and need to get the rest data if has more data
await sleep(1000)
const data = await Promise.resolve({
items: vars,
total: 1,
})
const res = data.items
return res
}

View File

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