@@ -8,6 +8,8 @@ export interface UseChildDeploymentReturn {
88 activeVersion : number | null
99 /** Whether the child workflow has an active deployment */
1010 isDeployed : boolean | null
11+ /** Whether the child workflow needs redeployment due to changes */
12+ needsRedeploy : boolean
1113 /** Whether the deployment information is currently being fetched */
1214 isLoading : boolean
1315 /** Function to manually refetch deployment status */
@@ -23,6 +25,7 @@ export interface UseChildDeploymentReturn {
2325export function useChildDeployment ( childWorkflowId : string | undefined ) : UseChildDeploymentReturn {
2426 const [ activeVersion , setActiveVersion ] = useState < number | null > ( null )
2527 const [ isDeployed , setIsDeployed ] = useState < boolean | null > ( null )
28+ const [ needsRedeploy , setNeedsRedeploy ] = useState ( false )
2629 const [ isLoading , setIsLoading ] = useState ( false )
2730 const [ refetchTrigger , setRefetchTrigger ] = useState ( 0 )
2831
@@ -31,37 +34,60 @@ export function useChildDeployment(childWorkflowId: string | undefined): UseChil
3134
3235 try {
3336 setIsLoading ( true )
34- const res = await fetch ( `/api/workflows/${ wfId } /deployments` , {
35- cache : 'no-store' ,
36- headers : { 'Cache-Control' : 'no-cache' } ,
37- } )
3837
39- if ( ! res . ok ) {
38+ // Fetch both deployment versions and workflow metadata in parallel
39+ const [ deploymentsRes , workflowRes ] = await Promise . all ( [
40+ fetch ( `/api/workflows/${ wfId } /deployments` , {
41+ cache : 'no-store' ,
42+ headers : { 'Cache-Control' : 'no-cache' } ,
43+ } ) ,
44+ fetch ( `/api/workflows/${ wfId } ` , {
45+ cache : 'no-store' ,
46+ headers : { 'Cache-Control' : 'no-cache' } ,
47+ } ) ,
48+ ] )
49+
50+ if ( ! deploymentsRes . ok || ! workflowRes . ok ) {
4051 if ( ! cancelled ) {
4152 setActiveVersion ( null )
4253 setIsDeployed ( null )
54+ setNeedsRedeploy ( false )
4355 }
4456 return
4557 }
4658
47- const json = await res . json ( )
48- const versions = Array . isArray ( json ?. data ?. versions )
49- ? json . data . versions
50- : Array . isArray ( json ?. versions )
51- ? json . versions
59+ const deploymentsJson = await deploymentsRes . json ( )
60+ const workflowJson = await workflowRes . json ( )
61+
62+ const versions = Array . isArray ( deploymentsJson ?. data ?. versions )
63+ ? deploymentsJson . data . versions
64+ : Array . isArray ( deploymentsJson ?. versions )
65+ ? deploymentsJson . versions
5266 : [ ]
5367
5468 const active = versions . find ( ( v : any ) => v . isActive )
69+ const workflowUpdatedAt = workflowJson ?. data ?. updatedAt || workflowJson ?. updatedAt
5570
5671 if ( ! cancelled ) {
5772 const v = active ? Number ( active . version ) : null
73+ const deployed = v != null
5874 setActiveVersion ( v )
59- setIsDeployed ( v != null ) // true if deployed, false if undeployed
75+ setIsDeployed ( deployed )
76+
77+ // Check if workflow has been updated since deployment
78+ if ( deployed && active ?. createdAt && workflowUpdatedAt ) {
79+ const deploymentTime = new Date ( active . createdAt ) . getTime ( )
80+ const updateTime = new Date ( workflowUpdatedAt ) . getTime ( )
81+ setNeedsRedeploy ( updateTime > deploymentTime )
82+ } else {
83+ setNeedsRedeploy ( false )
84+ }
6085 }
6186 } catch {
6287 if ( ! cancelled ) {
6388 setActiveVersion ( null )
6489 setIsDeployed ( null )
90+ setNeedsRedeploy ( false )
6591 }
6692 } finally {
6793 if ( ! cancelled ) setIsLoading ( false )
@@ -78,6 +104,7 @@ export function useChildDeployment(childWorkflowId: string | undefined): UseChil
78104 } else {
79105 setActiveVersion ( null )
80106 setIsDeployed ( null )
107+ setNeedsRedeploy ( false )
81108 }
82109 } , [ childWorkflowId , refetchTrigger , fetchActiveVersion ] )
83110
@@ -88,6 +115,7 @@ export function useChildDeployment(childWorkflowId: string | undefined): UseChil
88115 return {
89116 activeVersion,
90117 isDeployed,
118+ needsRedeploy,
91119 isLoading,
92120 refetch,
93121 }
0 commit comments