Skip to content

Commit 8fe763f

Browse files
committed
DRY
1 parent 7852998 commit 8fe763f

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

apps/sim/hooks/queries/deployments.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
33
import type { WorkflowDeploymentVersionResponse } from '@/lib/workflows/persistence/utils'
44
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
5+
import { fetchDeploymentVersionState } from './workflows'
56

67
const logger = createLogger('DeploymentQueries')
78

@@ -457,21 +458,14 @@ export function useGenerateVersionDescription() {
457458
'@/lib/workflows/comparison/compare'
458459
)
459460

460-
const currentResponse = await fetch(`/api/workflows/${workflowId}/deployments/${version}`)
461-
if (!currentResponse.ok) {
462-
throw new Error('Failed to fetch current version state')
463-
}
464-
const currentData = await currentResponse.json()
465-
const currentState = currentData.deployedState
461+
const currentState = await fetchDeploymentVersionState(workflowId, version)
466462

467463
let previousState = null
468464
if (version > 1) {
469-
const previousResponse = await fetch(
470-
`/api/workflows/${workflowId}/deployments/${version - 1}`
471-
)
472-
if (previousResponse.ok) {
473-
const previousData = await previousResponse.json()
474-
previousState = previousData.deployedState
465+
try {
466+
previousState = await fetchDeploymentVersionState(workflowId, version - 1)
467+
} catch {
468+
// Previous version may not exist, continue without it
475469
}
476470
}
477471

apps/sim/hooks/queries/workflows.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ interface DeploymentVersionStateResponse {
411411
deployedState: WorkflowState
412412
}
413413

414-
async function fetchDeploymentVersionState(
414+
/**
415+
* Fetches the deployed state for a specific deployment version.
416+
* Exported for reuse in other query hooks.
417+
*/
418+
export async function fetchDeploymentVersionState(
415419
workflowId: string,
416420
version: number
417421
): Promise<WorkflowState> {

0 commit comments

Comments
 (0)