mirror of
https://github.com/YFGaia/dify-plus.git
synced 2026-06-04 10:14:00 +08:00
refactor(web): migrate workflow run history from useSWR to TanStack Query (#30077)
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
UpdateWorkflowParams,
|
||||
VarInInspect,
|
||||
WorkflowConfigResponse,
|
||||
WorkflowRunHistoryResponse,
|
||||
} from '@/types/workflow'
|
||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
@@ -25,6 +26,14 @@ export const useAppWorkflow = (appID: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useWorkflowRunHistory = (url?: string, enabled = true) => {
|
||||
return useQuery<WorkflowRunHistoryResponse>({
|
||||
queryKey: [NAME_SPACE, 'runHistory', url],
|
||||
queryFn: () => get<WorkflowRunHistoryResponse>(url as string),
|
||||
enabled: !!url && enabled,
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateAppWorkflow = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return (appID: string) => {
|
||||
|
||||
+7
-20
@@ -1,14 +1,11 @@
|
||||
import type { Fetcher } from 'swr'
|
||||
import type { BlockEnum } from '@/app/components/workflow/types'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type { FlowType } from '@/types/common'
|
||||
import type {
|
||||
ChatRunHistoryResponse,
|
||||
ConversationVariableResponse,
|
||||
FetchWorkflowDraftResponse,
|
||||
NodesDefaultConfigsResponse,
|
||||
VarInInspect,
|
||||
WorkflowRunHistoryResponse,
|
||||
} from '@/types/workflow'
|
||||
import { get, post } from './base'
|
||||
import { getFlowPrefix } from './utils'
|
||||
@@ -24,18 +21,10 @@ export const syncWorkflowDraft = ({ url, params }: {
|
||||
return post<CommonResponse & { updated_at: number, hash: string }>(url, { body: params }, { silent: true })
|
||||
}
|
||||
|
||||
export const fetchNodesDefaultConfigs: Fetcher<NodesDefaultConfigsResponse, string> = (url) => {
|
||||
export const fetchNodesDefaultConfigs = (url: string) => {
|
||||
return get<NodesDefaultConfigsResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchWorkflowRunHistory: Fetcher<WorkflowRunHistoryResponse, string> = (url) => {
|
||||
return get<WorkflowRunHistoryResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchChatRunHistory: Fetcher<ChatRunHistoryResponse, string> = (url) => {
|
||||
return get<ChatRunHistoryResponse>(url)
|
||||
}
|
||||
|
||||
export const singleNodeRun = (flowType: FlowType, flowId: string, nodeId: string, params: object) => {
|
||||
return post(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/run`, { body: params })
|
||||
}
|
||||
@@ -48,7 +37,7 @@ export const getLoopSingleNodeRunUrl = (flowType: FlowType, isChatFlow: boolean,
|
||||
return `${getFlowPrefix(flowType)}/${flowId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/loop/nodes/${nodeId}/run`
|
||||
}
|
||||
|
||||
export const fetchPublishedWorkflow: Fetcher<FetchWorkflowDraftResponse, string> = (url) => {
|
||||
export const fetchPublishedWorkflow = (url: string) => {
|
||||
return get<FetchWorkflowDraftResponse>(url)
|
||||
}
|
||||
|
||||
@@ -68,15 +57,13 @@ export const fetchPipelineNodeDefault = (pipelineId: string, blockType: BlockEnu
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: archived
|
||||
export const updateWorkflowDraftFromDSL = (appId: string, data: string) => {
|
||||
return post<FetchWorkflowDraftResponse>(`apps/${appId}/workflows/draft/import`, { body: { data } })
|
||||
}
|
||||
|
||||
export const fetchCurrentValueOfConversationVariable: Fetcher<ConversationVariableResponse, {
|
||||
export const fetchCurrentValueOfConversationVariable = ({
|
||||
url,
|
||||
params,
|
||||
}: {
|
||||
url: string
|
||||
params: { conversation_id: string }
|
||||
}> = ({ url, params }) => {
|
||||
}) => {
|
||||
return get<ConversationVariableResponse>(url, { params })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user