feat: add update workflow to update use query

This commit is contained in:
Joel 2024-11-13 16:22:09 +08:00
parent 577a948f42
commit 0d607a8c90
4 changed files with 19 additions and 16 deletions

View File

@ -44,6 +44,7 @@ import { useProviderContext } from '@/context/provider-context'
import { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import Loading from '@/app/components/base/loading'
import { useAppContext } from '@/context/app-context'
import { useInvalidateAllWorkflowTools } from '@/service/use-tools'
type Props = {
collection: Collection
@ -65,7 +66,7 @@ const ProviderDetail = ({
const isBuiltIn = collection.type === CollectionType.builtIn
const isModel = collection.type === CollectionType.model
const { isCurrentWorkspaceManager } = useAppContext()
const invalidateAllWorkflowTools = useInvalidateAllWorkflowTools()
const [isDetailLoading, setIsDetailLoading] = useState(false)
// built in provider
@ -164,6 +165,7 @@ const ProviderDetail = ({
workflow_tool_id: string
}>) => {
await saveWorkflowToolProvider(data)
invalidateAllWorkflowTools()
onRefreshData()
getWorkflowToolProvider()
Toast.notify({

View File

@ -14,6 +14,7 @@ import { createWorkflowToolProvider, fetchWorkflowToolDetailByAppID, saveWorkflo
import type { Emoji, WorkflowToolProviderParameter, WorkflowToolProviderRequest, WorkflowToolProviderResponse } from '@/app/components/tools/types'
import type { InputVar } from '@/app/components/workflow/types'
import { useAppContext } from '@/context/app-context'
import { useInvalidateAllWorkflowTools } from '@/service/use-tools'
type Props = {
disabled: boolean
@ -46,6 +47,7 @@ const WorkflowToolConfigureButton = ({
const [isLoading, setIsLoading] = useState(false)
const [detail, setDetail] = useState<WorkflowToolProviderResponse>()
const { isCurrentWorkspaceManager } = useAppContext()
const invalidateAllWorkflowTools = useInvalidateAllWorkflowTools()
const outdated = useMemo(() => {
if (!detail)
@ -135,6 +137,7 @@ const WorkflowToolConfigureButton = ({
const createHandle = async (data: WorkflowToolProviderRequest & { workflow_app_id: string }) => {
try {
await createWorkflowToolProvider(data)
invalidateAllWorkflowTools()
onRefreshData?.()
getDetail(workflowAppId)
Toast.notify({
@ -156,6 +159,7 @@ const WorkflowToolConfigureButton = ({
await handlePublish()
await saveWorkflowToolProvider(data)
onRefreshData?.()
invalidateAllWorkflowTools()
getDetail(workflowAppId)
Toast.notify({
type: 'success',

View File

@ -18,6 +18,7 @@ import {
useQueryClient,
} from '@tanstack/react-query'
import { useStore as usePluginDependencyStore } from '@/app/components/workflow/plugin-dependency/store'
import { useInvalidateAllBuiltInTools } from './use-tools'
const NAME_SPACE = 'plugins'
@ -31,11 +32,13 @@ export const useInstalledPluginList = () => {
export const useInvalidateInstalledPluginList = () => {
const queryClient = useQueryClient()
const invalidateAllBuiltInTools = useInvalidateAllBuiltInTools()
return () => {
queryClient.invalidateQueries(
{
queryKey: useInstalledPluginListKey,
})
invalidateAllBuiltInTools()
}
}

View File

@ -4,6 +4,7 @@ import type {
Tool,
} from '@/app/components/tools/types'
import type { ToolWithProvider } from '@/app/components/workflow/types'
import { useInvalid } from './use-base'
import {
useMutation,
useQuery,
@ -21,13 +22,7 @@ export const useAllBuiltInTools = () => {
}
export const useInvalidateAllBuiltInTools = () => {
const queryClient = useQueryClient()
return () => {
queryClient.invalidateQueries(
{
queryKey: useAllBuiltInToolsKey,
})
}
return useInvalid(useAllBuiltInToolsKey)
}
const useAllCustomToolsKey = [NAME_SPACE, 'customTools']
@ -39,22 +34,21 @@ export const useAllCustomTools = () => {
}
export const useInvalidateAllCustomTools = () => {
const queryClient = useQueryClient()
return () => {
queryClient.invalidateQueries(
{
queryKey: useAllCustomToolsKey,
})
}
return useInvalid(useAllCustomToolsKey)
}
const useAllWorkflowToolsKey = [NAME_SPACE, 'workflowTools']
export const useAllWorkflowTools = () => {
return useQuery<ToolWithProvider[]>({
queryKey: [NAME_SPACE, 'workflowTools'],
queryKey: useAllWorkflowToolsKey,
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/workflow'),
})
}
export const useInvalidateAllWorkflowTools = () => {
return useInvalid(useAllWorkflowToolsKey)
}
export const useBuiltinProviderInfo = (providerName: string) => {
return useQuery({
queryKey: [NAME_SPACE, 'builtin-provider-info', providerName],