Skip to content

Commit be5438b

Browse files
committed
improvement(stores): remove deployment state from Zustand in favor of React Query (#3923)
1 parent 4d08eed commit be5438b

File tree

28 files changed

+64
-470
lines changed

28 files changed

+64
-470
lines changed

apps/sim/app/api/copilot/checkpoints/revert/route.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
304304
loops: {},
305305
parallels: {},
306306
isDeployed: true,
307-
deploymentStatuses: { production: 'deployed' },
308307
},
309308
}
310309

@@ -349,7 +348,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
349348
loops: {},
350349
parallels: {},
351350
isDeployed: true,
352-
deploymentStatuses: { production: 'deployed' },
353351
lastSaved: 1640995200000,
354352
},
355353
},
@@ -370,7 +368,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
370368
loops: {},
371369
parallels: {},
372370
isDeployed: true,
373-
deploymentStatuses: { production: 'deployed' },
374371
lastSaved: 1640995200000,
375372
}),
376373
}
@@ -473,7 +470,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
473470
edges: undefined,
474471
loops: null,
475472
parallels: undefined,
476-
deploymentStatuses: null,
477473
},
478474
}
479475

@@ -508,7 +504,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
508504
loops: {},
509505
parallels: {},
510506
isDeployed: false,
511-
deploymentStatuses: {},
512507
lastSaved: 1640995200000,
513508
})
514509
})
@@ -768,10 +763,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
768763
parallel1: { branches: ['branch1', 'branch2'] },
769764
},
770765
isDeployed: true,
771-
deploymentStatuses: {
772-
production: 'deployed',
773-
staging: 'pending',
774-
},
775766
deployedAt: '2024-01-01T10:00:00.000Z',
776767
},
777768
}
@@ -816,10 +807,6 @@ describe('Copilot Checkpoints Revert API Route', () => {
816807
parallel1: { branches: ['branch1', 'branch2'] },
817808
},
818809
isDeployed: true,
819-
deploymentStatuses: {
820-
production: 'deployed',
821-
staging: 'pending',
822-
},
823810
deployedAt: '2024-01-01T10:00:00.000Z',
824811
lastSaved: 1640995200000,
825812
})

apps/sim/app/api/copilot/checkpoints/revert/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export async function POST(request: NextRequest) {
8282
loops: checkpointState?.loops || {},
8383
parallels: checkpointState?.parallels || {},
8484
isDeployed: checkpointState?.isDeployed || false,
85-
deploymentStatuses: checkpointState?.deploymentStatuses || {},
8685
lastSaved: Date.now(),
8786
...(checkpointState?.deployedAt &&
8887
checkpointState.deployedAt !== null &&

apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export async function POST(
7979
loops: deployedState.loops || {},
8080
parallels: deployedState.parallels || {},
8181
lastSaved: Date.now(),
82-
deploymentStatuses: deployedState.deploymentStatuses || {},
8382
})
8483

8584
if (!saveResult.success) {

apps/sim/app/api/workflows/[id]/route.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
8989
const finalWorkflowData = {
9090
...workflowData,
9191
state: {
92-
deploymentStatuses: {},
9392
blocks: normalizedData.blocks,
9493
edges: normalizedData.edges,
9594
loops: normalizedData.loops,
@@ -115,7 +114,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
115114
const emptyWorkflowData = {
116115
...workflowData,
117116
state: {
118-
deploymentStatuses: {},
119117
blocks: {},
120118
edges: [],
121119
loops: {},

apps/sim/app/templates/components/template-card.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ function normalizeWorkflowState(input?: any): WorkflowState | null {
108108
lastUpdate: input.lastUpdate,
109109
metadata: input.metadata,
110110
variables: input.variables,
111-
deploymentStatuses: input.deploymentStatuses,
112-
needsRedeployment: input.needsRedeployment,
113111
dragStartPosition: input.dragStartPosition ?? null,
114112
}
115113

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,17 +1407,6 @@ export function useChat(
14071407
const output = tc.result?.output as Record<string, unknown> | undefined
14081408
const deployedWorkflowId = (output?.workflowId as string) ?? undefined
14091409
if (deployedWorkflowId && typeof output?.isDeployed === 'boolean') {
1410-
const isDeployed = output.isDeployed as boolean
1411-
const serverDeployedAt = output.deployedAt
1412-
? new Date(output.deployedAt as string)
1413-
: undefined
1414-
useWorkflowRegistry
1415-
.getState()
1416-
.setDeploymentStatus(
1417-
deployedWorkflowId,
1418-
isDeployed,
1419-
isDeployed ? (serverDeployedAt ?? new Date()) : undefined
1420-
)
14211410
queryClient.invalidateQueries({
14221411
queryKey: deploymentKeys.info(deployedWorkflowId),
14231412
})

apps/sim/app/workspace/[workspaceId]/templates/components/template-card.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ function normalizeWorkflowState(input?: any): WorkflowState | null {
111111
lastUpdate: input.lastUpdate,
112112
metadata: input.metadata,
113113
variables: input.variables,
114-
deploymentStatuses: input.deploymentStatuses,
115-
needsRedeployment: input.needsRedeployment,
116114
dragStartPosition: input.dragStartPosition ?? null,
117115
}
118116

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import { useWorkflowMap } from '@/hooks/queries/workflows'
4040
import { useWorkspaceSettings } from '@/hooks/queries/workspace'
4141
import { usePermissionConfig } from '@/hooks/use-permission-config'
4242
import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
43-
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
4443
import { mergeSubblockState } from '@/stores/workflows/utils'
4544
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
4645
import type { WorkflowState } from '@/stores/workflows/workflow/types'
@@ -90,10 +89,7 @@ export function DeployModal({
9089
const params = useParams()
9190
const workspaceId = params?.workspaceId as string
9291
const { navigateToSettings } = useSettingsNavigation()
93-
const deploymentStatus = useWorkflowRegistry((state) =>
94-
state.getWorkflowDeploymentStatus(workflowId)
95-
)
96-
const isDeployed = deploymentStatus?.isDeployed ?? isDeployedProp
92+
const isDeployed = isDeployedProp
9793
const { data: workflowMap = {} } = useWorkflowMap(workspaceId)
9894
const workflowMetadata = workflowId ? workflowMap[workflowId] : undefined
9995
const workflowWorkspaceId = workflowMetadata?.workspaceId ?? null
@@ -381,8 +377,6 @@ export function DeployModal({
381377

382378
invalidateDeploymentQueries(queryClient, workflowId)
383379

384-
useWorkflowRegistry.getState().setWorkflowNeedsRedeployment(workflowId, false)
385-
386380
if (chatSuccessTimeoutRef.current) {
387381
clearTimeout(chatSuccessTimeoutRef.current)
388382
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useDeployment,
1010
} from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks'
1111
import { useCurrentWorkflow } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-current-workflow'
12-
import { useDeployedWorkflowState } from '@/hooks/queries/deployments'
12+
import { useDeployedWorkflowState, useDeploymentInfo } from '@/hooks/queries/deployments'
1313
import type { WorkspaceUserPermissions } from '@/hooks/use-user-permissions'
1414
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1515

@@ -25,10 +25,10 @@ export function Deploy({ activeWorkflowId, userPermissions, className }: DeployP
2525
const isRegistryLoading = hydrationPhase === 'idle' || hydrationPhase === 'state-loading'
2626
const { hasBlocks } = useCurrentWorkflow()
2727

28-
const deploymentStatus = useWorkflowRegistry((state) =>
29-
state.getWorkflowDeploymentStatus(activeWorkflowId)
30-
)
31-
const isDeployed = deploymentStatus?.isDeployed || false
28+
const { data: deploymentInfo } = useDeploymentInfo(activeWorkflowId, {
29+
enabled: !isRegistryLoading,
30+
})
31+
const isDeployed = deploymentInfo?.isDeployed ?? false
3232

3333
const isDeployedStateEnabled = Boolean(activeWorkflowId) && isDeployed && !isRegistryLoading
3434
const {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useMemo } from 'react'
22
import type { Edge } from 'reactflow'
33
import { useShallow } from 'zustand/react/shallow'
44
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
5-
import type { DeploymentStatus } from '@/stores/workflows/registry/types'
65
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
76
import type { BlockState, Loop, Parallel, WorkflowState } from '@/stores/workflows/workflow/types'
87

@@ -16,8 +15,6 @@ export interface CurrentWorkflow {
1615
loops: Record<string, Loop>
1716
parallels: Record<string, Parallel>
1817
lastSaved?: number
19-
deploymentStatuses?: Record<string, DeploymentStatus>
20-
needsRedeployment?: boolean
2118

2219
// Mode information
2320
isDiffMode: boolean
@@ -48,8 +45,6 @@ export function useCurrentWorkflow(): CurrentWorkflow {
4845
loops: state.loops,
4946
parallels: state.parallels,
5047
lastSaved: state.lastSaved,
51-
deploymentStatuses: state.deploymentStatuses,
52-
needsRedeployment: state.needsRedeployment,
5348
}))
5449
)
5550

@@ -78,8 +73,6 @@ export function useCurrentWorkflow(): CurrentWorkflow {
7873
loops: activeWorkflow.loops || {},
7974
parallels: activeWorkflow.parallels || {},
8075
lastSaved: activeWorkflow.lastSaved,
81-
deploymentStatuses: activeWorkflow.deploymentStatuses,
82-
needsRedeployment: activeWorkflow.needsRedeployment,
8376

8477
// Mode information - update to reflect ready state
8578
isDiffMode: hasActiveDiff && isShowingDiff,

0 commit comments

Comments
 (0)