temp fix: tab change caused empty the nodes

This commit is contained in:
Joel
2026-01-14 17:20:22 +08:00
parent d17a92f713
commit be5a4cf5e3
3 changed files with 32 additions and 8 deletions

View File

@ -56,6 +56,7 @@ export const useWorkflowInit = () => {
} = useWorkflowConfig('/files/upload', handleUpdateWorkflowFileUploadConfig)
const handleGetInitialWorkflowData = useCallback(async () => {
setIsLoading(true)
try {
const res = await fetchWorkflowDraft(`/apps/${appDetail.id}/workflows/draft`)
setData(res)
@ -116,6 +117,7 @@ export const useWorkflowInit = () => {
useEffect(() => {
handleGetInitialWorkflowData()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const handleFetchPreloadData = useCallback(async () => {
@ -156,5 +158,6 @@ export const useWorkflowInit = () => {
data,
isLoading: isLoading || isFileUploadConfigLoading,
fileUploadConfigResponse,
reload: handleGetInitialWorkflowData,
}
}

View File

@ -40,16 +40,23 @@ import {
import { createWorkflowSlice } from './store/workflow/workflow-slice'
const WorkflowAppWithAdditionalContext = () => {
const [viewType, setViewType] = useState(ViewType.graph)
const {
data,
isLoading,
fileUploadConfigResponse,
reload,
} = useWorkflowInit()
const workflowStore = useWorkflowStore()
const { isLoadingCurrentWorkspace, currentWorkspace } = useAppContext()
const [viewType, doSetViewType] = useState(ViewType.graph)
const setViewType = (type: ViewType) => {
doSetViewType(type)
if (type === ViewType.graph) {
reload()
}
}
// Initialize trigger status at application level
const { setTriggerStatuses } = useTriggerStatusStore()
const appDetail = useAppStore(s => s.appDetail)
@ -164,7 +171,21 @@ const WorkflowAppWithAdditionalContext = () => {
})
}, [replayRunId, workflowStore, getWorkflowRunAndTraceUrl])
if (!data || isLoading || isLoadingCurrentWorkspace || !currentWorkspace.id) {
const isDataReady = !(!data || isLoading || isLoadingCurrentWorkspace || !currentWorkspace.id)
const GraphMain = useMemo(() => {
if (!isDataReady)
return null
return (
<WorkflowAppMain
nodes={nodesData}
edges={edgesData}
viewport={data.graph.viewport}
/>
)
}, [isDataReady, nodesData, edgesData, data])
if (!isDataReady) {
return (
<div className="relative flex h-full w-full items-center justify-center">
<Loading />
@ -213,11 +234,7 @@ const WorkflowAppWithAdditionalContext = () => {
{viewType === ViewType.graph
? (
<FeaturesProvider features={initialFeatures}>
<WorkflowAppMain
nodes={nodesData}
edges={edgesData}
viewport={data.graph.viewport}
/>
{GraphMain}
</FeaturesProvider>
)
: (

View File

@ -19,6 +19,10 @@ export const syncWorkflowDraft = ({ url, params }: {
url: string
params: Pick<FetchWorkflowDraftResponse, 'graph' | 'features' | 'environment_variables' | 'conversation_variables'>
}) => {
// when graph adn skill type changed, it would pass empty nodes array...Temp prevent sync in this case
if (params.graph.nodes.length === 0) {
throw new Error('Cannot sync workflow draft with zero nodes.')
}
const sanitized = sanitizeWorkflowDraftPayload(params)
return post<CommonResponse & { updated_at: number, hash: string }>(url, { body: sanitized }, { silent: true })
}