refactor(api): migrate console.app.workflow to BaseModel (#36216)

Co-authored-by: WH-2099 <wh2099@pm.me>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
chariri
2026-05-18 07:31:37 +00:00
committed by GitHub
co-authored by WH-2099 autofix-ci[bot]
parent 7e8147295b
commit 2eb37caf2e
19 changed files with 1241 additions and 341 deletions
@@ -175,7 +175,7 @@ describe('usePipelineConfig', () => {
expect(mockSetPublishedAt).toHaveBeenCalledWith('2024-01-01T00:00:00Z')
})
it('should handle undefined workflow response', () => {
it('should reset published at when workflow response is empty', () => {
let capturedCallback: ((data: unknown) => void) | undefined
mockUseWorkflowConfig.mockImplementation((url: string, callback: (data: unknown) => void) => {
if (url.includes('/publish')) {
@@ -187,7 +187,7 @@ describe('usePipelineConfig', () => {
capturedCallback?.(undefined)
expect(mockSetPublishedAt).toHaveBeenCalledWith(undefined)
expect(mockSetPublishedAt).toHaveBeenCalledWith(0)
})
})
@@ -33,10 +33,10 @@ export const usePipelineConfig = () => {
handleUpdateNodesDefaultConfigs,
)
const handleUpdatePublishedAt = useCallback((publishedWorkflow: FetchWorkflowDraftResponse) => {
const handleUpdatePublishedAt = useCallback((publishedWorkflow: FetchWorkflowDraftResponse | null) => {
const { setPublishedAt } = workflowStore.getState()
setPublishedAt(publishedWorkflow?.created_at)
setPublishedAt(publishedWorkflow?.created_at ?? 0)
}, [workflowStore])
useWorkflowConfig(
pipelineId ? `/rag/pipelines/${pipelineId}/workflows/publish` : '',
@@ -124,7 +124,7 @@ export const useWorkflowInit = () => {
return acc
}, {} as Record<string, any>),
})
workflowStore.getState().setPublishedAt(publishedWorkflow?.created_at)
workflowStore.getState().setPublishedAt(publishedWorkflow?.created_at ?? 0)
const graph = publishedWorkflow?.graph
workflowStore.getState().setLastPublishedHasUserInput(
hasConnectedUserInput(graph?.nodes, graph?.edges),
+2 -2
View File
@@ -195,10 +195,10 @@ export const useInvalidDataSourceList = () => {
export const publishedPipelineInfoQueryKeyPrefix = [NAME_SPACE, 'published-pipeline']
export const usePublishedPipelineInfo = (pipelineId: string) => {
return useQuery<PublishedPipelineInfoResponse>({
return useQuery<PublishedPipelineInfoResponse | null>({
queryKey: [...publishedPipelineInfoQueryKeyPrefix, pipelineId],
queryFn: () => {
return get<PublishedPipelineInfoResponse>(`/rag/pipelines/${pipelineId}/workflows/publish`)
return get<PublishedPipelineInfoResponse | null>(`/rag/pipelines/${pipelineId}/workflows/publish`)
},
enabled: !!pipelineId,
})
+2 -2
View File
@@ -19,10 +19,10 @@ import { getFlowPrefix } from './utils'
const NAME_SPACE = 'workflow'
export const useAppWorkflow = (appID: string) => {
return useQuery<FetchWorkflowDraftResponse>({
return useQuery<FetchWorkflowDraftResponse | null>({
enabled: !!appID,
queryKey: [NAME_SPACE, 'publish', appID],
queryFn: () => get<FetchWorkflowDraftResponse>(`/apps/${appID}/workflows/publish`),
queryFn: () => get<FetchWorkflowDraftResponse | null>(`/apps/${appID}/workflows/publish`),
})
}
+1 -1
View File
@@ -43,7 +43,7 @@ export const getLoopSingleNodeRunUrl = (flowType: FlowType, isChatFlow: boolean,
}
export const fetchPublishedWorkflow = (url: string) => {
return get<FetchWorkflowDraftResponse>(url)
return get<FetchWorkflowDraftResponse | null>(url)
}
export const stopWorkflowRun = (url: string) => {