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 { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import { useInvalidateAllWorkflowTools } from '@/service/use-tools'
type Props = { type Props = {
collection: Collection collection: Collection
@ -65,7 +66,7 @@ const ProviderDetail = ({
const isBuiltIn = collection.type === CollectionType.builtIn const isBuiltIn = collection.type === CollectionType.builtIn
const isModel = collection.type === CollectionType.model const isModel = collection.type === CollectionType.model
const { isCurrentWorkspaceManager } = useAppContext() const { isCurrentWorkspaceManager } = useAppContext()
const invalidateAllWorkflowTools = useInvalidateAllWorkflowTools()
const [isDetailLoading, setIsDetailLoading] = useState(false) const [isDetailLoading, setIsDetailLoading] = useState(false)
// built in provider // built in provider
@ -164,6 +165,7 @@ const ProviderDetail = ({
workflow_tool_id: string workflow_tool_id: string
}>) => { }>) => {
await saveWorkflowToolProvider(data) await saveWorkflowToolProvider(data)
invalidateAllWorkflowTools()
onRefreshData() onRefreshData()
getWorkflowToolProvider() getWorkflowToolProvider()
Toast.notify({ 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 { Emoji, WorkflowToolProviderParameter, WorkflowToolProviderRequest, WorkflowToolProviderResponse } from '@/app/components/tools/types'
import type { InputVar } from '@/app/components/workflow/types' import type { InputVar } from '@/app/components/workflow/types'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import { useInvalidateAllWorkflowTools } from '@/service/use-tools'
type Props = { type Props = {
disabled: boolean disabled: boolean
@ -46,6 +47,7 @@ const WorkflowToolConfigureButton = ({
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [detail, setDetail] = useState<WorkflowToolProviderResponse>() const [detail, setDetail] = useState<WorkflowToolProviderResponse>()
const { isCurrentWorkspaceManager } = useAppContext() const { isCurrentWorkspaceManager } = useAppContext()
const invalidateAllWorkflowTools = useInvalidateAllWorkflowTools()
const outdated = useMemo(() => { const outdated = useMemo(() => {
if (!detail) if (!detail)
@ -135,6 +137,7 @@ const WorkflowToolConfigureButton = ({
const createHandle = async (data: WorkflowToolProviderRequest & { workflow_app_id: string }) => { const createHandle = async (data: WorkflowToolProviderRequest & { workflow_app_id: string }) => {
try { try {
await createWorkflowToolProvider(data) await createWorkflowToolProvider(data)
invalidateAllWorkflowTools()
onRefreshData?.() onRefreshData?.()
getDetail(workflowAppId) getDetail(workflowAppId)
Toast.notify({ Toast.notify({
@ -156,6 +159,7 @@ const WorkflowToolConfigureButton = ({
await handlePublish() await handlePublish()
await saveWorkflowToolProvider(data) await saveWorkflowToolProvider(data)
onRefreshData?.() onRefreshData?.()
invalidateAllWorkflowTools()
getDetail(workflowAppId) getDetail(workflowAppId)
Toast.notify({ Toast.notify({
type: 'success', type: 'success',

View File

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

View File

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