@ -12,6 +12,8 @@ import type {
} from '@/types/workflow'
import type { CommonResponse } from '@/models/common'
import { useInvalid , useReset } from './use-base'
import type { FlowType } from '@/types/common'
import { getFlowPrefix } from './utils'
const NAME_SPACE = 'workflow'
@ -102,12 +104,12 @@ export const usePublishWorkflow = () => {
}
const useLastRunKey = [ NAME_SPACE , 'last-run' ]
export const useLastRun = ( appID : string , nodeId : string , enabled : boolean ) = > {
export const useLastRun = ( flowType: FlowType , flowId : string , nodeId : string , enabled : boolean ) = > {
return useQuery < NodeTracing > ( {
enabled ,
queryKey : [ . . . useLastRunKey , appID , nodeId ] ,
queryKey : [ . . . useLastRunKey , flowType, flowId , nodeId ] ,
queryFn : async ( ) = > {
return get ( ` apps/ ${ appID } /workflows/draft/nodes/ ${ nodeId } /last-run ` , { } , {
return get ( ` ${ getFlowPrefix ( flowType ) } / ${ flowId } /workflows/draft/nodes/ ${ nodeId } /last-run ` , { } , {
silent : true ,
} )
} ,
@ -115,13 +117,13 @@ export const useLastRun = (appID: string, nodeId: string, enabled: boolean) => {
} )
}
export const useInvalidLastRun = ( app Id: string , nodeId : string ) = > {
return useInvalid ( [ NAME_SPACE , 'last-run' , app Id, nodeId ] )
export const useInvalidLastRun = ( flowType: FlowType , flow Id: string , nodeId : string ) = > {
return useInvalid ( [ NAME_SPACE , flowType , 'last-run' , flow Id, nodeId ] )
}
// Rerun workflow or change the version of workflow
export const useInvalidAllLastRun = ( appId : string ) = > {
return useInvalid ( [ NAME_SPACE , 'last-run' , app Id] )
export const useInvalidAllLastRun = ( flowType?: FlowType , flowId? : string ) = > {
return useInvalid ( [ NAME_SPACE , flowType , 'last-run' , flow Id] )
}
const useConversationVarValuesKey = [ NAME_SPACE , 'conversation-variable' ]
@ -141,20 +143,20 @@ export const useInvalidateConversationVarValues = (url: string) => {
return useInvalid ( [ . . . useConversationVarValuesKey , url ] )
}
export const useResetConversationVar = ( app Id: string ) = > {
export const useResetConversationVar = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'reset conversation var' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'reset conversation var' , flow Id] ,
mutationFn : async ( varId : string ) = > {
return put ( ` apps/ ${ app Id} /workflows/draft/variables/ ${ varId } /reset ` )
return put ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/variables/ ${ varId } /reset ` )
} ,
} )
}
export const useResetToLastRunValue = ( app Id: string ) = > {
export const useResetToLastRunValue = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'reset to last run value' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'reset to last run value' , flow Id] ,
mutationFn : async ( varId : string ) : Promise < { value : any } > = > {
return put ( ` apps/ ${ app Id} /workflows/draft/variables/ ${ varId } /reset ` )
return put ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/variables/ ${ varId } /reset ` )
} ,
} )
}
@ -175,43 +177,43 @@ export const useInvalidateSysVarValues = (url: string) => {
return useInvalid ( [ . . . useSysVarValuesKey , url ] )
}
export const useDeleteAllInspectorVars = ( app Id: string ) = > {
export const useDeleteAllInspectorVars = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'delete all inspector vars' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'delete all inspector vars' , flow Id] ,
mutationFn : async ( ) = > {
return del ( ` apps/ ${ app Id} /workflows/draft/variables ` )
return del ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/variables ` )
} ,
} )
}
export const useDeleteNodeInspectorVars = ( app Id: string ) = > {
export const useDeleteNodeInspectorVars = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'delete node inspector vars' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'delete node inspector vars' , flow Id] ,
mutationFn : async ( nodeId : string ) = > {
return del ( ` apps/ ${ app Id} /workflows/draft/nodes/ ${ nodeId } /variables ` )
return del ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/nodes/ ${ nodeId } /variables ` )
} ,
} )
}
export const useDeleteInspectVar = ( app Id: string ) = > {
export const useDeleteInspectVar = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'delete inspector var' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'delete inspector var' , flow Id] ,
mutationFn : async ( varId : string ) = > {
return del ( ` apps/ ${ app Id} /workflows/draft/variables/ ${ varId } ` )
return del ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/variables/ ${ varId } ` )
} ,
} )
}
// edit the name or value of the inspector var
export const useEditInspectorVar = ( app Id: string ) = > {
export const useEditInspectorVar = ( flowType: FlowType , flow Id: string ) = > {
return useMutation ( {
mutationKey : [ NAME_SPACE , 'edit inspector var' , app Id] ,
mutationKey : [ NAME_SPACE , flowType , 'edit inspector var' , flow Id] ,
mutationFn : async ( { varId , . . . rest } : {
varId : string
name? : string
value? : any
} ) = > {
return patch ( ` apps/ ${ app Id} /workflows/draft/variables/ ${ varId } ` , {
return patch ( ` ${ getFlowPrefix ( flowType ) } / ${ flow Id} /workflows/draft/variables/ ${ varId } ` , {
body : rest ,
} )
} ,