Skip to content

Commit fa63af9

Browse files
authored
fix(queries): remove more remaining manual state management and refetching in favor of reactquery (#2852)
1 parent dba5799 commit fa63af9

File tree

8 files changed

+184
-284
lines changed

8 files changed

+184
-284
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/mcp/mcp.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ export function McpDeploy({
9898
const workspaceId = params.workspaceId as string
9999
const openSettingsModal = useSettingsModalStore((state) => state.openModal)
100100

101-
const {
102-
data: servers = [],
103-
isLoading: isLoadingServers,
104-
refetch: refetchServers,
105-
} = useWorkflowMcpServers(workspaceId)
101+
const { data: servers = [], isLoading: isLoadingServers } = useWorkflowMcpServers(workspaceId)
106102
const addToolMutation = useAddWorkflowMcpTool()
107103
const deleteToolMutation = useDeleteWorkflowMcpTool()
108104
const updateToolMutation = useUpdateWorkflowMcpTool()
@@ -346,7 +342,6 @@ export function McpDeploy({
346342
toolDescription: toolDescription.trim() || undefined,
347343
parameterSchema,
348344
})
349-
refetchServers()
350345
onAddedToServer?.()
351346
logger.info(`Added workflow ${workflowId} as tool to server ${serverId}`)
352347
} catch (error) {
@@ -375,7 +370,6 @@ export function McpDeploy({
375370
delete next[serverId]
376371
return next
377372
})
378-
refetchServers()
379373
} catch (error) {
380374
logger.error('Failed to remove tool:', error)
381375
} finally {
@@ -398,7 +392,6 @@ export function McpDeploy({
398392
parameterSchema,
399393
addToolMutation,
400394
deleteToolMutation,
401-
refetchServers,
402395
onAddedToServer,
403396
]
404397
)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ import {
5252
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/custom-tool-modal/custom-tool-modal'
5353
import { ToolCredentialSelector } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/tool-credential-selector'
5454
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
55-
import { useChildDeployment } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-deployment'
5655
import { getAllBlocks } from '@/blocks'
5756
import { useMcpTools } from '@/hooks/mcp/use-mcp-tools'
5857
import {
5958
type CustomTool as CustomToolDefinition,
6059
useCustomTools,
6160
} from '@/hooks/queries/custom-tools'
6261
import { useForceRefreshMcpTools, useMcpServers, useStoredMcpTools } from '@/hooks/queries/mcp'
63-
import { useWorkflowInputFields, useWorkflows } from '@/hooks/queries/workflows'
62+
import {
63+
useChildDeploymentStatus,
64+
useDeployChildWorkflow,
65+
useWorkflowInputFields,
66+
useWorkflows,
67+
} from '@/hooks/queries/workflows'
6468
import { usePermissionConfig } from '@/hooks/use-permission-config'
6569
import { getProviderFromModel, supportsToolUsageControl } from '@/providers/utils'
6670
import { useSettingsModalStore } from '@/stores/modals/settings/store'
@@ -756,37 +760,26 @@ function WorkflowToolDeployBadge({
756760
workflowId: string
757761
onDeploySuccess?: () => void
758762
}) {
759-
const { isDeployed, needsRedeploy, isLoading, refetch } = useChildDeployment(workflowId)
760-
const [isDeploying, setIsDeploying] = useState(false)
763+
const { data, isLoading } = useChildDeploymentStatus(workflowId)
764+
const deployMutation = useDeployChildWorkflow()
761765
const userPermissions = useUserPermissionsContext()
762766

763-
const deployWorkflow = useCallback(async () => {
767+
const isDeployed = data?.isDeployed ?? null
768+
const needsRedeploy = data?.needsRedeploy ?? false
769+
const isDeploying = deployMutation.isPending
770+
771+
const deployWorkflow = useCallback(() => {
764772
if (isDeploying || !workflowId || !userPermissions.canAdmin) return
765773

766-
try {
767-
setIsDeploying(true)
768-
const response = await fetch(`/api/workflows/${workflowId}/deploy`, {
769-
method: 'POST',
770-
headers: {
771-
'Content-Type': 'application/json',
774+
deployMutation.mutate(
775+
{ workflowId },
776+
{
777+
onSuccess: () => {
778+
onDeploySuccess?.()
772779
},
773-
body: JSON.stringify({
774-
deployChatEnabled: false,
775-
}),
776-
})
777-
778-
if (response.ok) {
779-
refetch()
780-
onDeploySuccess?.()
781-
} else {
782-
logger.error('Failed to deploy workflow')
783780
}
784-
} catch (error) {
785-
logger.error('Error deploying workflow:', error)
786-
} finally {
787-
setIsDeploying(false)
788-
}
789-
}, [isDeploying, workflowId, refetch, onDeploySuccess, userPermissions.canAdmin])
781+
)
782+
}, [isDeploying, workflowId, userPermissions.canAdmin, deployMutation, onDeploySuccess])
790783

791784
if (isLoading || (isDeployed && !needsRedeploy)) {
792785
return null
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export { useBlockProperties } from './use-block-properties'
22
export { useBlockState } from './use-block-state'
33
export { useChildWorkflow } from './use-child-workflow'
4-
export { useScheduleInfo } from './use-schedule-info'
54
export { useWebhookInfo } from './use-webhook-info'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-deployment.ts

Lines changed: 0 additions & 113 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-workflow.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
2-
import { useChildDeployment } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-child-deployment'
32
import type { WorkflowBlockProps } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/types'
3+
import { useChildDeploymentStatus } from '@/hooks/queries/workflows'
44

55
/**
66
* Return type for the useChildWorkflow hook
@@ -16,12 +16,12 @@ export interface UseChildWorkflowReturn {
1616
childNeedsRedeploy: boolean
1717
/** Whether the child version information is loading */
1818
isLoadingChildVersion: boolean
19-
/** Function to manually refetch deployment status */
20-
refetchDeployment: () => void
2119
}
2220

2321
/**
24-
* Custom hook for managing child workflow information for workflow selector blocks
22+
* Custom hook for managing child workflow information for workflow selector blocks.
23+
* Cache invalidation is handled automatically by React Query when using
24+
* the useDeployChildWorkflow mutation.
2525
*
2626
* @param blockId - The ID of the block
2727
* @param blockType - The type of the block
@@ -53,20 +53,20 @@ export function useChildWorkflow(
5353
}
5454
}
5555

56-
const {
57-
activeVersion: childActiveVersion,
58-
isDeployed: childIsDeployed,
59-
needsRedeploy: childNeedsRedeploy,
60-
isLoading: isLoadingChildVersion,
61-
refetch: refetchDeployment,
62-
} = useChildDeployment(isWorkflowSelector ? childWorkflowId : undefined)
56+
const { data, isLoading, isPending } = useChildDeploymentStatus(
57+
isWorkflowSelector ? childWorkflowId : undefined
58+
)
59+
60+
const childActiveVersion = data?.activeVersion ?? null
61+
const childIsDeployed = data?.isDeployed ?? null
62+
const childNeedsRedeploy = data?.needsRedeploy ?? false
63+
const isLoadingChildVersion = isLoading || isPending
6364

6465
return {
6566
childWorkflowId,
6667
childActiveVersion,
6768
childIsDeployed,
6869
childNeedsRedeploy,
6970
isLoadingChildVersion,
70-
refetchDeployment,
7171
}
7272
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/hooks/use-schedule-info.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)