File tree Expand file tree Collapse file tree
src/packages/ce/src/flow/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use client"
2+
3+ import React from "react"
4+ import { useSubscription } from "@apollo/client/react"
5+ import { ExecutionResult , Subscription } from "@code0-tech/sagittarius-graphql-types"
6+ import { FlowExecution , useFlowExecutionStore } from "@edition/flow/hooks/Flow.execution.hook"
7+ import { useService } from "@code0-tech/pictor"
8+ import { FlowService } from "@edition/flow/services/Flow.service"
9+ import flowExecutionResultSubscription from "@edition/flow/services/subscriptions/Flow.executionResult.subscription.graphql"
10+
11+ export interface FlowExecutionSubscriberComponentProps {
12+ execution : FlowExecution
13+ }
14+
15+ export const FlowExecutionSubscriberComponent : React . FC < FlowExecutionSubscriberComponentProps > = ( { execution} ) => {
16+
17+ const flowService = useService ( FlowService )
18+ const removeExecution = useFlowExecutionStore ( s => s . removeExecution )
19+
20+ useSubscription < Subscription > ( flowExecutionResultSubscription , {
21+ variables : { executionIdentifier : execution . executionIdentifier } ,
22+ onData : ( data ) => {
23+ const executionResult = data . data . data ?. namespacesProjectsFlowsExecutionResult ?. executionResult as ExecutionResult | undefined
24+ if ( executionResult ) {
25+ flowService . addExecutionResult ( execution . flowId , executionResult )
26+ removeExecution ( execution . executionIdentifier )
27+ }
28+ } ,
29+ onComplete : ( ) => removeExecution ( execution . executionIdentifier ) ,
30+ onError : ( ) => removeExecution ( execution . executionIdentifier ) ,
31+ } )
32+
33+ return null
34+ }
Original file line number Diff line number Diff line change 1+ "use client"
2+
3+ import React from "react"
4+ import { useFlowExecutionStore } from "@edition/flow/hooks/Flow.execution.hook"
5+ import { FlowExecutionSubscriberComponent } from "@edition/flow/components/FlowExecutionSubscriberComponent"
6+
7+ /**
8+ * Keeps one subscription alive per pending manual execution. Each subscriber writes
9+ * the incoming execution result into the flow store and drops the pending entry.
10+ */
11+ export const FlowExecutionWatcherComponent : React . FC = ( ) => {
12+
13+ const executions = useFlowExecutionStore ( s => s . executions )
14+
15+ return < >
16+ { executions . map ( execution => (
17+ < FlowExecutionSubscriberComponent
18+ key = { execution . executionIdentifier }
19+ execution = { execution }
20+ />
21+ ) ) }
22+ </ >
23+ }
You can’t perform that action at this time.
0 commit comments