11import React , { CSSProperties , memo } from "react" ;
22import { Handle , Node , NodeProps , Position } from "@xyflow/react" ;
3- import { Badge , Card , Flex , Text , useService , useStore as usePictorStore } from "@code0-tech/pictor" ;
3+ import { Badge , Card , Flex , Text , useService , useStore , useStore as usePictorStore } from "@code0-tech/pictor" ;
44import { FunctionNodeComponentProps } from "@edition/function/components/nodes/FunctionNodeComponent" ;
55import { FlowTypeService } from "@edition/flowtype/services/FlowType.service" ;
66import { FlowService } from "@edition/flow/services/Flow.service" ;
77import { IconVariable } from "@tabler/icons-react" ;
8- import { NodeFunction } from "@code0-tech/sagittarius-graphql-types" ;
8+ import { Namespace , NamespaceProject , NodeFunction } from "@code0-tech/sagittarius-graphql-types" ;
99import { icon , IconString } from "@core/util/icons" ;
1010import { FALLBACK_FLOW_TYPE_DISPLAY_MESSAGE , FALLBACK_FLOW_TYPE_NAME } from "@core/util/fallback-translations" ;
1111import { useFlowValidation } from "@edition/flow/hooks/Flow.validation.hook" ;
@@ -14,21 +14,73 @@ import {useSelectedFunctionNode} from "@edition/function/hooks/FunctionNode.sele
1414import { LiteralBadgeComponent } from "@edition/datatype/components/badges/LiteralBadgeComponent" ;
1515import { ReferenceBadgeComponent } from "@edition/datatype/components/badges/ReferenceBadgeComponent" ;
1616import { NodeBadgeComponent } from "@edition/datatype/components/badges/NodeBadgeComponent" ;
17+ import { useParams } from "next/navigation" ;
18+ import { ProjectService } from "@edition/project/services/Project.service" ;
19+ import { ModuleService } from "@edition/module/services/Module.service" ;
1720
1821
1922export type FunctionNodeTriggerComponentProps = NodeProps < Node < FunctionNodeComponentProps > >
2023
2124export const FunctionNodeTriggerComponent : React . FC < FunctionNodeTriggerComponentProps > = memo ( ( props ) => {
2225
2326 const { data, id, selected} = props
27+
28+ const params = useParams ( )
2429 const flowTypeService = useService ( FlowTypeService )
2530 const flowTypeStore = usePictorStore ( FlowTypeService )
2631 const flowService = useService ( FlowService )
2732 const flowStore = usePictorStore ( FlowService )
33+ const projectService = useService ( ProjectService )
34+ const projectStore = useStore ( ProjectService )
35+ const moduleService = useService ( ModuleService )
36+ const moduleStore = useStore ( ModuleService )
37+
38+ const namespaceIndex = params . namespaceId as any as number
39+ const projectIndex = params . projectId as any as number
40+ const namespaceId : Namespace [ 'id' ] = `gid://sagittarius/Namespace/${ namespaceIndex } `
41+ const projectId : NamespaceProject [ 'id' ] = `gid://sagittarius/NamespaceProject/${ projectIndex } `
42+
43+ const flow = React . useMemo (
44+ ( ) => flowService . getById ( data . flowId , {
45+ namespaceId,
46+ projectId
47+ } ) ,
48+ [ data . flowId , namespaceId , projectId , flowStore ]
49+ )
50+
51+ const project = React . useMemo (
52+ ( ) => projectService . getById ( projectId , {
53+ namespaceId
54+ } ) ,
55+ [ projectId , namespaceId , projectStore ]
56+ )
57+
58+ const flowType = React . useMemo (
59+ ( ) => flowTypeService . getById ( flow ?. type ?. id , {
60+ namespaceId,
61+ projectId,
62+ runtimeId : project ?. primaryRuntime ?. id
63+ } ) ,
64+ [ flow ?. type ?. id , namespaceId , projectId , project ?. primaryRuntime ?. id , flowTypeStore ]
65+ )
2866
29- const flow = React . useMemo ( ( ) => flowService . getById ( data . flowId ) , [ flowStore , data ] )
30- const definition = React . useMemo ( ( ) => flow ? flowTypeService . getById ( flow . type ?. id ) : undefined , [ flowTypeStore , flow ] )
31- const DisplayIcon = icon ( definition ?. displayIcon as IconString )
67+ const module = React . useMemo (
68+ ( ) => moduleService . getById ( flowType ?. runtimeModule ?. id , {
69+ namespaceId : namespaceId ,
70+ projectId : projectId ,
71+ runtimeId : project ?. primaryRuntime ?. id
72+ } ) ,
73+ [ flowType ?. runtimeModule ?. id , namespaceId , projectId , project ?. primaryRuntime ?. id , moduleStore ]
74+ )
75+
76+ let endpoint = `http://${ module ?. definitions ?. nodes ?. [ 0 ] ?. host } :${ module ?. definitions ?. nodes ?. [ 0 ] ?. port } ${ module ?. definitions ?. nodes ?. [ 0 ] ?. endpoint } `
77+ . replace ( "${{project_slug}}" , project ?. slug ?? "${{project_slug}}" )
78+
79+ flow ?. settings ?. nodes ?. forEach ( setting => {
80+ endpoint = endpoint . replace ( `\${{${ setting ?. flowSettingIdentifier } }}` , setting ?. value )
81+ } )
82+
83+ const DisplayIcon = icon ( flowType ?. displayIcon as IconString )
3284 const validation = useFlowValidation ( data . flowId )
3385
3486 const triggerValidations = React . useMemo (
@@ -55,15 +107,15 @@ export const FunctionNodeTriggerComponent: React.FC<FunctionNodeTriggerComponent
55107 . flatMap ( p => p . trim ( ) === "," ? [ "," ] : p . trim ( ) ? [ p . trim ( ) ] : [ ] )
56108 )
57109
58- const displayMessage = React . useMemo ( ( ) => splitTemplate ( definition ?. displayMessages ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_DISPLAY_MESSAGE ) . map ( item => {
110+ const displayMessage = React . useMemo ( ( ) => splitTemplate ( flowType ?. displayMessages ?. [ 0 ] ?. content ?? FALLBACK_FLOW_TYPE_DISPLAY_MESSAGE ) . map ( item => {
59111
60112 const nodeParameter = flow ?. settings ?. nodes ?. find ( ( _ , index ) => {
61- const parameterDefinition = definition ?. flowTypeSettings ?. [ index ]
113+ const parameterDefinition = flowType ?. flowTypeSettings ?. [ index ]
62114 return parameterDefinition ?. identifier == item
63115 } )
64116
65- const parameterDefinition = definition ?. flowTypeSettings ?. find ( pd => pd ?. identifier == item )
66- const parameterIndex = parameterDefinition ? definition ?. flowTypeSettings ?. findIndex ( p => p ?. id === parameterDefinition . id ) : undefined
117+ const parameterDefinition = flowType ?. flowTypeSettings ?. find ( pd => pd ?. identifier == item )
118+ const parameterIndex = parameterDefinition ? flowType ?. flowTypeSettings ?. findIndex ( p => p ?. id === parameterDefinition . id ) : undefined
67119 const parameterValidation = validation ?. filter ( v => v . parameterIndex === parameterIndex && ! v . nodeId )
68120 const decorationStyle : CSSProperties =
69121 parameterValidation ?. length
@@ -94,7 +146,7 @@ export const FunctionNodeTriggerComponent: React.FC<FunctionNodeTriggerComponent
94146 </ div >
95147 }
96148 return " " + String ( item ) + " "
97- } ) , [ flowStore , data , definition , validation ] )
149+ } ) , [ flowStore , data , flowType , validation ] )
98150
99151 const isReferenced = React . useMemo ( ( ) => {
100152
@@ -121,17 +173,24 @@ export const FunctionNodeTriggerComponent: React.FC<FunctionNodeTriggerComponent
121173 className = { `d-flow-node ${ selected ? "d-flow-node--active" : undefined } ` }
122174 style = { { ...( isReferenced === true ? { boxShadow : `0 0 5rem 0 rgba(112, 255, 178, 0.25)` } : { } ) , } } >
123175
124- < Badge color = { "info" }
125- pos = { "absolute" }
126- top = { "-0.35rem" }
127- left = { "50%" }
128- style = { { transform : "translate(-50%, -100%)" } } >
129- Starting node
130- </ Badge >
176+ < Flex pos = { "absolute" }
177+ top = { "-0.35rem" }
178+ left = { "50%" }
179+ align = { "center" }
180+ style = { { transform : "translate(-50%, -100%)" , flexDirection : "column" , gap : "0.35rem" } } >
181+ < Badge color = { "info" } >
182+ Flow trigger
183+ </ Badge >
184+ { module ?. definitions ?. nodes ?. [ 0 ] && (
185+ < Badge color = { "secondary" } >
186+ < Text size = { "xs" } > { endpoint } </ Text >
187+ </ Badge >
188+ ) }
189+ </ Flex >
131190
132191 < Flex style = { { gap : "0.7rem" , ...triggerValidationStyle } } align = { "center" } >
133192 < DisplayIcon color = { data . color } size = { 16 } />
134- < Text size = { "md" } > { flow ? displayMessage : definition ?. names ?. [ 0 ] . content ?? FALLBACK_FLOW_TYPE_NAME } </ Text >
193+ < Text size = { "md" } > { flow ? displayMessage : flowType ?. names ?. [ 0 ] . content ?? FALLBACK_FLOW_TYPE_NAME } </ Text >
135194 </ Flex >
136195
137196 {
0 commit comments