From bc45c0904a4ec0983fd188f3d8fa80a9a2bd02cb Mon Sep 17 00:00:00 2001 From: Joel Date: Sun, 27 Apr 2025 14:12:23 +0800 Subject: [PATCH] chore: change init value --- ....ts => use-fetch-workflow-inspect-vars.ts} | 11 +++++++++-- web/app/components/workflow/index.tsx | 8 ++++++-- web/service/use-workflow.ts | 19 ------------------- web/service/workflow.ts | 15 +++++++++++++++ web/types/workflow.ts | 2 +- 5 files changed, 31 insertions(+), 24 deletions(-) rename web/app/components/workflow-app/hooks/{use-set-workflow-vars-with-value.ts => use-fetch-workflow-inspect-vars.ts} (88%) diff --git a/web/app/components/workflow-app/hooks/use-set-workflow-vars-with-value.ts b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts similarity index 88% rename from web/app/components/workflow-app/hooks/use-set-workflow-vars-with-value.ts rename to web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts index a05c62ad4c..feffeaaf78 100644 --- a/web/app/components/workflow-app/hooks/use-set-workflow-vars-with-value.ts +++ b/web/app/components/workflow-app/hooks/use-fetch-workflow-inspect-vars.ts @@ -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 diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx index 72b97c89a4..918eec1b61 100644 --- a/web/app/components/workflow/index.tsx +++ b/web/app/components/workflow/index.tsx @@ -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 = 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') { diff --git a/web/service/use-workflow.ts b/web/service/use-workflow.ts index 067ac778ee..a118e5f3b8 100644 --- a/web/service/use-workflow.ts +++ b/web/service/use-workflow.ts @@ -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 - }, - }) -} diff --git a/web/service/workflow.ts b/web/service/workflow.ts index 7d10394246..ed90e4d435 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -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 @@ -70,3 +73,15 @@ export const fetchCurrentValueOfConversationVariable: Fetcher = ({ url, params }) => { return get(url, { params }) } + +export const fetchAllInspectVars = async (appId: string): Promise => { + // 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 +} diff --git a/web/types/workflow.ts b/web/types/workflow.ts index b5d84e0704..c28f7a02ad 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -395,5 +395,5 @@ export type NodeWithVar = { title: string vars: VarInInspect[] isFetchingValues?: boolean - isSingRunRunning: boolean + isSingRunRunning?: boolean }