44 FlowSetting ,
55 LiteralValue ,
66 Maybe ,
7- Mutation , Namespace , NamespaceProject ,
7+ Mutation ,
8+ Namespace ,
9+ NamespaceProject ,
810 NamespacesProjectsFlowsCreateInput ,
911 NamespacesProjectsFlowsCreatePayload ,
1012 NamespacesProjectsFlowsDeleteInput ,
@@ -14,7 +16,7 @@ import {
1416 NodeFunction ,
1517 NodeFunctionIdWrapper ,
1618 NodeParameter ,
17- NodeParameterValueInput ,
19+ NodeParameterValueInput , ParameterDefinition ,
1820 Query ,
1921 ReferencePathInput ,
2022 ReferenceValue ,
@@ -177,10 +179,11 @@ export class FlowService extends ReactiveArrayService<FlowView, FlowDependencies
177179
178180 case "ReferenceValue" : {
179181 const v = parameter . value as ReferenceValue
182+ console . log ( v )
180183 value = {
181184 referenceValue : {
182185 ...( v . nodeFunctionId ? { nodeFunctionId : v . nodeFunctionId } : { } ) ,
183- ...( v . parameterIndex && v . inputIndex ?
186+ ...( " parameterIndex" in v && " inputIndex" in v ?
184187 {
185188 parameterIndex : v . parameterIndex ,
186189 inputIndex : v . inputIndex
@@ -304,31 +307,62 @@ export class FlowService extends ReactiveArrayService<FlowView, FlowDependencies
304307 await this . syncFlow ( flowId )
305308 }
306309
307- async setParameterValue ( flowId : FlowView [ 'id' ] , nodeId : NodeFunction [ 'id' ] , parameterId : NodeParameter [ 'id' ] , value ?: LiteralValue | ReferenceValue | NodeFunction ) : Promise < void > {
310+ async setParameterValue ( flowId : FlowView [ 'id' ] , nodeId : NodeFunction [ 'id' ] , parameterIndex : number , value ?: LiteralValue | ReferenceValue | NodeFunction , parameterDefinitionId ?: ParameterDefinition [ 'id' ] ) : Promise < void > {
308311 const flow = this . getById ( flowId )
309312 const index = this . values ( ) . findIndex ( f => f . id === flowId )
310313 if ( ! flow ) return
311314 const node = this . getNodeById ( flowId , nodeId )
312315 if ( ! node ) return
313- const parameter = node . parameters ?. nodes ?. find ( p => p ?. id === parameterId )
314- if ( ! parameter ) return
315- this . removeParameterNode ( flow , parameter )
316- if ( value ?. __typename === "NodeFunction" ) {
317- const nextNodeIndex : number = Math . max ( 0 , ...flow . nodes ?. nodes ?. map ( node => Number ( node ?. id ?. match ( / N o d e F u n c t i o n \/ ( \d + ) $ / ) ?. [ 1 ] ?? 0 ) ) ?? [ 0 ] )
318- const addingIdValue : NodeFunction = {
319- ...value ,
320- id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } `
316+ const parameter = node . parameters ?. nodes ?. [ parameterIndex ]
317+ if ( ! parameter && parameterDefinitionId ) {
318+ //TODO: needs a parameterDefinitionId
319+ const localParameter : NodeParameter = {
320+ __typename : "NodeParameter" ,
321+ parameterDefinition : {
322+ __typename : "ParameterDefinition" ,
323+ id : parameterDefinitionId
324+ } ,
325+ value : null
321326 }
322- flow . nodes ?. nodes ?. push ( addingIdValue )
323- parameter . value = {
324- id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } ` ,
325- __typename : "NodeFunctionIdWrapper"
326- } as NodeFunctionIdWrapper
327- } else {
328- parameter . value = value as LiteralValue | ReferenceValue
327+
328+ if ( value ?. __typename === "NodeFunction" ) {
329+ const nextNodeIndex : number = Math . max ( 0 , ...flow . nodes ?. nodes ?. map ( node => Number ( node ?. id ?. match ( / N o d e F u n c t i o n \/ ( \d + ) $ / ) ?. [ 1 ] ?? 0 ) ) ?? [ 0 ] )
330+ const addingIdValue : NodeFunction = {
331+ ...value ,
332+ id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } `
333+ }
334+ flow . nodes ?. nodes ?. push ( addingIdValue )
335+ localParameter . value = {
336+ id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } ` ,
337+ __typename : "NodeFunctionIdWrapper"
338+ } as NodeFunctionIdWrapper
339+ } else {
340+ localParameter . value = value as LiteralValue | ReferenceValue
341+ }
342+
343+ flow . editedAt = new Date ( ) . toISOString ( )
344+
345+ node . parameters ?. nodes ?. push ( localParameter )
346+ } else if ( parameter ) {
347+ this . removeParameterNode ( flow , parameter )
348+ if ( value ?. __typename === "NodeFunction" ) {
349+ const nextNodeIndex : number = Math . max ( 0 , ...flow . nodes ?. nodes ?. map ( node => Number ( node ?. id ?. match ( / N o d e F u n c t i o n \/ ( \d + ) $ / ) ?. [ 1 ] ?? 0 ) ) ?? [ 0 ] )
350+ const addingIdValue : NodeFunction = {
351+ ...value ,
352+ id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } `
353+ }
354+ flow . nodes ?. nodes ?. push ( addingIdValue )
355+ parameter . value = {
356+ id : `gid://sagittarius/NodeFunction/${ nextNodeIndex + 1 } ` ,
357+ __typename : "NodeFunctionIdWrapper"
358+ } as NodeFunctionIdWrapper
359+ } else {
360+ parameter . value = value as LiteralValue | ReferenceValue
361+ }
362+
363+ flow . editedAt = new Date ( ) . toISOString ( )
329364 }
330365
331- flow . editedAt = new Date ( ) . toISOString ( )
332366
333367 this . set ( index , new View ( flow ) )
334368 await this . syncFlow ( flowId )
0 commit comments