feat: version tag (#14949)
This commit is contained in:
parent
4aaf07d62a
commit
3ca1373274
41 changed files with 1695 additions and 423 deletions
|
|
@ -13,3 +13,14 @@ export const useInvalid = (key: QueryKey) => {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const useReset = (key: QueryKey) => {
|
||||
const queryClient = useQueryClient()
|
||||
return () => {
|
||||
queryClient.resetQueries(
|
||||
{
|
||||
queryKey: key,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import { get } from './base'
|
||||
import { del, get, patch, post } from './base'
|
||||
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query'
|
||||
import type {
|
||||
FetchWorkflowDraftPageParams,
|
||||
FetchWorkflowDraftPageResponse,
|
||||
FetchWorkflowDraftResponse,
|
||||
PublishWorkflowParams,
|
||||
UpdateWorkflowParams,
|
||||
WorkflowConfigResponse,
|
||||
} from '@/types/workflow'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import type { WorkflowConfigResponse } from '@/types/workflow'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import { useReset } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'workflow'
|
||||
|
||||
|
|
@ -21,3 +27,57 @@ export const useWorkflowConfig = (appId: string) => {
|
|||
queryFn: () => get<WorkflowConfigResponse>(`/apps/${appId}/workflows/draft/config`),
|
||||
})
|
||||
}
|
||||
|
||||
const WorkflowVersionHistoryKey = [NAME_SPACE, 'versionHistory']
|
||||
|
||||
export const useWorkflowVersionHistory = (params: FetchWorkflowDraftPageParams) => {
|
||||
const { appId, initialPage, limit, userId, namedOnly } = params
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...WorkflowVersionHistoryKey, appId, initialPage, limit, userId, namedOnly],
|
||||
queryFn: ({ pageParam = 1 }) => get<FetchWorkflowDraftPageResponse>(`/apps/${appId}/workflows`, {
|
||||
params: {
|
||||
page: pageParam,
|
||||
limit,
|
||||
user_id: userId || '',
|
||||
named_only: !!namedOnly,
|
||||
},
|
||||
}),
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : null,
|
||||
initialPageParam: initialPage,
|
||||
})
|
||||
}
|
||||
|
||||
export const useResetWorkflowVersionHistory = (appId: string) => {
|
||||
return useReset([...WorkflowVersionHistoryKey, appId])
|
||||
}
|
||||
|
||||
export const useUpdateWorkflow = (appId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update'],
|
||||
mutationFn: (params: UpdateWorkflowParams) => patch(`/apps/${appId}/workflows/${params.workflowId}`, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteWorkflow = (appId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete'],
|
||||
mutationFn: (workflowId: string) => del(`/apps/${appId}/workflows/${workflowId}`),
|
||||
})
|
||||
}
|
||||
|
||||
export const usePublishWorkflow = (appId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'publish'],
|
||||
mutationFn: (params: PublishWorkflowParams) => post<CommonResponse & { created_at: number }>(`/apps/${appId}/workflows/publish`, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import type { CommonResponse } from '@/models/common'
|
|||
import type {
|
||||
ChatRunHistoryResponse,
|
||||
ConversationVariableResponse,
|
||||
FetchWorkflowDraftPageResponse,
|
||||
FetchWorkflowDraftResponse,
|
||||
NodesDefaultConfigsResponse,
|
||||
WorkflowRunHistoryResponse,
|
||||
|
|
@ -46,18 +45,10 @@ export const getLoopSingleNodeRunUrl = (isChatFlow: boolean, appId: string, node
|
|||
return `apps/${appId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/loop/nodes/${nodeId}/run`
|
||||
}
|
||||
|
||||
export const publishWorkflow = (url: string) => {
|
||||
return post<CommonResponse & { created_at: number }>(url)
|
||||
}
|
||||
|
||||
export const fetchPublishedWorkflow: Fetcher<FetchWorkflowDraftResponse, string> = (url) => {
|
||||
return get<FetchWorkflowDraftResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchPublishedAllWorkflow: Fetcher<FetchWorkflowDraftPageResponse, string> = (url) => {
|
||||
return get<FetchWorkflowDraftPageResponse>(url)
|
||||
}
|
||||
|
||||
export const stopWorkflowRun = (url: string) => {
|
||||
return post<CommonResponse>(url)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue